Commit 1b2c0a84 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Sphinx documentation for the Automaton class.

parent 10500578
# -*- coding: utf-8 -*-
#
# track_publication api documentation build configuration file, created by
# sphinx-quickstart on Sat Apr 11 11:17:03 2015.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import re
import sys
from datetime import datetime
def get_version():
"""Get the current version identifier.
Returns:
str: the version number
"""
log = open('../../static/CHANGELOG').read()
match = re.search(r"(\d+\.\d+(\.\d+)*)", log)
if match:
return match.group(1)
return ""
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../modules'))
sys.path.insert(0, os.path.abspath('../../../web2py'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode']
# autosummary configuration
autosummary_generate = True
# intersphinx configuration
intersphinx_mapping = {'python': ('http://docs.python.org/2.7', None)}
# napoleon configuration
napoleon_user_rtype = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
now = datetime.now()
project = u'track_publications'
copyright = u'2012-%s, R. Le Gac, licensed under CeCILL' % now.year
author = u'R. Le Gac'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = get_version()
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinxdoc'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_domain_indices = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'track_publications_api_doc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
(master_doc,
'track_publications_api.tex',
u'track\\_publications API',
u'R. Le Gac',
'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# If true, show page references after internal links.
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'track_publications_api', u'API',
[author], 1)
]
# If true, show URL addresses after external links.
# man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'track_publications_api', u'track_publications API',
author, 'track_publications_api', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
# texinfo_appendices = []
# If false, no module index is generated.
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'
harvest_tools.automaton.Automaton.__init__
==========================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.__init__
\ No newline at end of file
harvest_tools.automaton.Automaton.check_record
==============================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.check_record
\ No newline at end of file
harvest_tools.automaton.Automaton.decode_xml
============================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.decode_xml
\ No newline at end of file
harvest_tools.automaton.Automaton.get_create_collaboration
==========================================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.get_create_collaboration
\ No newline at end of file
harvest_tools.automaton.Automaton.get_create_publisher
======================================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.get_create_publisher
\ No newline at end of file
harvest_tools.automaton.Automaton.get_record_by_fields
======================================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.get_record_by_fields
\ No newline at end of file
harvest_tools.automaton.Automaton.insert_record
===============================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.insert_record
\ No newline at end of file
harvest_tools.automaton.Automaton.process_url
=============================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.process_url
\ No newline at end of file
harvest_tools.automaton.Automaton.process_xml
=============================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.process_xml
\ No newline at end of file
harvest_tools.automaton.Automaton.report
========================================
.. currentmodule:: harvest_tools.automaton
.. automethod:: Automaton.report
\ No newline at end of file
harvest_tools.automaton.Automaton
=================================
.. currentmodule:: harvest_tools.automaton
.. autoclass:: Automaton
.. rubric:: Methods
.. autosummary::
:toctree: automaton/
~Automaton.__init__
~Automaton.check_record
~Automaton.decode_xml
~Automaton.get_create_collaboration
~Automaton.get_create_publisher
~Automaton.get_record_by_fields
~Automaton.insert_record
~Automaton.process_url
~Automaton.process_xml
~Automaton.report
Harvesters
----------
.. currentmodule:: harvest_tools.automaton
.. autosummary::
:toctree: generated/
Automaton
.. track_publication_api documentation master file, created by
sphinx-quickstart on Sat Apr 11 11:17:03 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
API Documentation
=================
.. toctree::
:maxdepth: 2
harvester
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`
......@@ -27,45 +27,63 @@ MSG_WELL_FORM_OAI = "Reject OAI is not well formed"
class Automaton(object):
"""Base class to search and process publications.
- Decode the parameter of a selector defining user criteria.
- Search for publications in the store, according to
user criteria or process and XML string.
- Load records in the database.
"""Base class to search and process publications:
The parameters of the search as well as the parameters of the harvester
are defined by the current request.
* Decode the selector defining user criteria.
* Search for publications in the store, according to
user criteria
* Decode the XML string return by the store.
* Insert new records in the database.
The logic implements in the `Automaton` class is the following
Note:
The parameters of the search are defined by the current ``request``.
1. Ask to the store, all the `record_id` satisfying the user request.
2. Reject `record_id` matching the `origin` field of a database entry.
3. Request to the store, the XML description of the publication
The logic implements in the ``Automaton`` class is the following:
#. Ask to the store, all the `record_id` satisfying the user request.
#. Reject `record_id` matching the `origin` field of database entry.
#. Request to the store, the XML description of the publication
and decode it.
4. Check that the *oai* of the publication is defined and well formed.
Recover it if it is not the case. From time to time, the `id`
encoded in the `oai` field is different from the `record` id.
#. Check that the *oai* of the publication is defined and well formed.
Recover it, if it is not the case. From time to time, the `id`
encoded in the `oai` field is different from the `record_id`.
This happens when an old record is redirected to new one
for obscure reasons. The record is ignore if a database entry
is found with the bad OAI.
5. Reject temporarily publication.
6. Check that *authors* are defined.
#. Reject temporarily publication.
#. Check that *authors* are defined.
Reject the publication if it is not the case.
7. Check that *my institute* is in the list of the institutes
#. Check that *my institute* is in the list of the institutes
signing the publication. Reject the publication if it is
not the case. When the affiliation are not defined,
try to recover this case, by finding the author of my institute
signing the publication. This recovery procedure uses
the *author rescue list*. Reject the record when the recovery
procedure failed.
8. Check that the *collaboration*, if defined, is well formed.
#. Check that the *collaboration*, if defined, is well formed.
Reject the publication if it is not the case
10. Several check are applied depending on the publication type.
11. At the end of this process, the publisher, the authors are
formatted and the list of signatories of my institute extracted.
#. Several check are applied depending on the publication type.
#. At the end of this process, the publisher, the authors are
formatted and the list of signatories of my institute extracted.
Args:
db (gluon.DAL): the database connection.
id_team (int): the identifier of the team in the database.
id_project (int): the identifier of the project in the database.
controller (unicode): type of the publication (``article``,
``proceeding``, *etc*).
id_category (int): the identifier of the category of publication
year_start (int): starting year for the scan
year_end (int): ending year of the scan
dry_run (bool): new records are not inserted in the database
when ``True``.
debug (bool): activate the verbose mode when ``True``.
Raises:
ToolException: when the team or the project or the publication category
is not defined.
"""
def __init__(self,
db,
id_team,
......@@ -76,40 +94,7 @@ class Automaton(object):
year_end=None,
dry_run=True,
debug=False):
"""
@note see C{build_harvester_tool} factory function building
C{PublicationsTools}
@type db: gluon.dal.DAL
@param db:
@type id_team: int
@param id_team: Identifier of the team in the db
@type id_project: int
@param id_project: Identifier of the project in the db
@type controller: unicode
@param controller: Type of publication
(i.e. 'article', 'proceedings', ...)
@type id_category: int
@param id_category: Identifier of the category of publication
(i.e. ACL, ACTI, ...)
@type year_start: int
@keyword year_start: Start year of search (i.e. '2014')
@type year_end: int
@keyword year_end: End year of search (i.e. '2015')
@type dry_run: boolean
@keyword dry_run: True if no record is to be written to the db
@type debug: bool
@param debug: activate the debug mode
"""
self.collection_logs = []
self.db = db
self.id_team = id_team
......@@ -145,15 +130,16 @@ class Automaton(object):
def _insert_in_db(self, log_year="", **fields):
"""Insert the record in the database, handling database exception.
@type log_year: unicode
@param log_year: year of the record for the log
Args:
log_year (unicode): year of the record for the log
@type **fields: dict
@param **fields:
Keyword Args:
**fields: keyword arguments defining the record values to be
inserted in the database.
@rtype: int
@return: one when the record is inserted / updated in the database
zero otherwise.
Returns:
int: one when the record is inserted / updated in the database,
zero otherwise.
"""
db = self.db
......@@ -182,18 +168,18 @@ class Automaton(object):
return 0
def _is_record_in_db(self, rec_id, title):
"""Return C{True} if the record is already in the database.
"""Return ``True`` when the record is already in the database.
The search is based on the origin field.
A new log entry is created
Note:
A new log entry is created when a record is found.
@type rec_id: int
@param rec_id: record identifier
Args:
rec_id (int): record identifier
title (unicode): title of the collection
@type title: str
@param title: title of the collection
@rtype: bool
Returns:
bool: ``True`` when a record if found, ``False`` otherwise.
"""
db = self.db
......@@ -229,14 +215,16 @@ class Automaton(object):
The main parameter is the collection and the date range defined
in the selector.
@type collection: unicode
@param collection: statement defining the collection in the
store, I{i.e.} C{"find cn d0 and tc p and not tc c"} or
C{"LHCb Papers"}. The syntax depends on the invenio store.
Args:
collection (unicode): string defining the collection in the
store. The syntax depends on the invenio store:
* ``"find cn d0 and tc p and not tc c"``
* ``"LHCb Papers"``.
@rtype: dict
@return: the key are a sub-set of those defined in
L{invenio_tools.InvenioStore.get_ids}.
Returns:
dict: the key are a sub-set of those defined in
:py:meth:invenio_tools.InvenioStore.get_ids.
"""
......@@ -284,23 +272,25 @@ class Automaton(object):
return dic
def check_record(self, record):
"""Check the content of the record in order to fix non conformities.
Return False when a non conformities has been found and can not be
"""Check the content of the record in order to fix non-conformities.
Return ``False`` when non-conformities are found and can not be
corrected.
@note: Some checks depend on the type of publications and have to be
implemented in inherited class.
Note: