Internal API

candyshop package

candyshop is just pure art.

Candyshop is a package that serves as a processor of the information contained in Odoo Modules. It’s primarily aimed at making reports of missing dependencies in an Odoo Environment.

It has abstractions that represent Odoo Modules and virtual Odoo Enviroments, as well as functions to resolve dependency trees.

candyshop.bundle submodule

candyshop.bundle is a module for representing Odoo Modules.

This module contains abstraction classes to represent a Module or a Bundle (a group of modules). These classes are read-only. For now, you cannot create or modify Bundles or Modules through these abstractions.

class candyshop.bundle.Bundle(path=None, exclude_tests=True)[source]

This class represents a group of modules or Bundle.

Also referred as Addons, a group of modules is simply a folder where you can put modules. Optionally, it can have a oca_dependencies.txt file (located at the root folder), where you can specify other git repositories needed for the correct operation of some of the modules included in the Bundle.

_Bundle__get_modules()

Private method to find and instance all valid modules inside a bundle.

New in version 0.1.0.

_Bundle__get_oca_dependencies_file()

Private method to find (if any) the oca_dependencies.txt file.

New in version 0.1.0.

_Bundle__parse_oca_dependencies()

Private method to parse (if any) the oca_dependencies.txt file.

New in version 0.1.0.

__init__(path=None, exclude_tests=True)[source]

Initialize a Bundle instance.

Parameters:
  • path – (string) a path pointing to the root directory containing Odoo Modules.
  • exclude_tests – (boolean) True (default) to exclude modules that are inside a tests folder. False to include such modules.
Returns:

a Bundle instance.

New in version 0.1.0.

__weakref__

list of weak references to the object (if defined)

exclude_tests = None

Attribute Bundle.exclude_tests (boolean): True if modules inside a tests folder will be excluded. False otherwise.

modules = None

Attribute Bundle.modules (list): A list containing instances of Module for each module inside the bundle.

name = None

Attribute Bundle.name (string): The name of the bundle.

oca_dependencies = None

Attribute Bundle.oca_dependencies (dict): A dictionary containing key-values of the names and repositories of OCA dependencies.

path = None

Attribute Bundle.path (string): Refers to the absolute path of the root directory that contains the bundle.

class candyshop.bundle.Module(path, bundle=None)[source]

This class represents an Odoo Module.

An Odoo module is a method to extend the Odoo codebase, adding or customizing functionalities. It is declared through its manifest file, and often contains other data files.

For more information, please refer to official documentation.

Modules.

_Module__extract_properties()

Private method to extract information of the module’s manifest file.

New in version 0.1.0.

_Module__get_manifest()

Private method to find the manifest file within the module.

New in version 0.1.0.

_Module__is_python_package()

Private method to determine if a module is a python package.

New in version 0.1.0.

_Module__xmlfile_isfrom_module(xmlfile)

Private method to determine if a module contains an XML file.

New in version 0.1.0.

__init__(path, bundle=None)[source]

Initialize the Module instance.

Parameters:
  • path – a path pointing to the root directory of an Odoo Module.
  • bundle – a Bundle instance (indicating this module is part of such bundle), or None (indicating that is a standalone module).
Returns:

a Module instance.

New in version 0.1.0.

__weakref__

list of weak references to the object (if defined)

bundle = None

Attribute Module.bundle (Bundle or None): Holds the information regarding the bundle to which this Module belongs.

get_record_ids()[source]

Get all record ids contained in all of the module’s XML files.

Returns:a generator that returns an iterable of dictionaries containing a list of record ids referenced in each XML file, like this one:
[
   {'path/file1.xml': ['module_a.id_a.noupdate=0']},
   {'path/file2.xml': ['module_b.id_b.noupdate=0']}
]

New in version 0.1.0.

get_record_ids_fromfile(xmlfile, module=None)[source]

Get ids from record tags of an Odoo XML file.

Parameters:
  • xmlfile – (string) a path pointing to the XML file.
  • module – (string or None) a record module to filter. If module is None (default) then get all modules.
Returns:

a generator that produces an iterable of strings with all [MODULE].[ID] found.

New in version 0.1.0.

get_record_ids_module_references()[source]

Get all modules referenced in Odoo XML files.

Returns:a generator that returns an iterable of dictionaries containing a list of modules referenced in each XML file, like this one:
[
   {'path/file1.xml': ['module_a', 'module_b']},
   {'path/file2.xml': ['module_c']}
]

New in version 0.1.0.

get_records_fromfile(xmlfile, model=None)[source]

Get record tags of an Odoo XML file.

Parameters:
  • xmlfile – (string) a path pointing to an XML file.
  • model – (string or None) a record model to filter. If model is None (default) then get all records.
Returns:

a list of lxml record nodes. If there is a syntax error return [].

New in version 0.1.0.

manifest = None

Attribute Module.manifest (string): Refers to the absolute path to the manifest file of the module (__openerp__.py, __odoo__.py or __terp__.py).

parse_xml_fromfile(xmlfile)[source]

Get XML parsed from an input file.

Parameters:xmlfile – (string) a path pointing to an XML file.
Returns:Parsed document (lxml.etree object). If there is a syntax error return string error message.

New in version 0.1.0.

path = None

Attribute Module.path (string): Refers to the absolute path of the root directory that contains the module.

properties = None

Object Module.properties (ModuleProperties): Placeholder for the module’s properties. Access the module’s properties as attributes of this object.

candyshop.environment submodule

candyshop.utils submodule

candyshop.utils is a utility module.

This module contains several utilities to process information coming from the other modules.

class candyshop.utils.ModuleProperties(data)[source]

This class holds the properties of a module.

It recieves a Dictionary and converts it to class attributes for better access.

For example:

>>> p = ModuleProperties({'name': 'Vauxoo Module'})
>>> p.name
'Vauxoo Module'
__init__(data)[source]

Initialize the ModuleProperties instance.

Parameters:data – a dictionary containing the properties of a module as specified in the manifest file of an Odoo Module.
Returns:each key-value is assigned as an attribute to this class.

New in version 0.1.0.

__weakref__

list of weak references to the object (if defined)

candyshop.utils.find_files(path=None, pattern='*')[source]

Search for files.

Locate all the files matching the supplied filename pattern in and below the supplied root directory. If no pattern is supplied, all files will be returned.

Parameters:
  • path – a string containing a path where the files will be looked for.
  • pattern – a string containing a regular expression.
Returns:

a list of files matching the pattern within path (recursive).

New in version 0.1.0.

candyshop.utils.get_path(path=None)[source]

Build and normalize a path.

This will resolve symlinks to their destination and convert relative to absolute paths. This function does not check if the python path really exists.

Parameters:path – a list with the components of a path.
Returns:a string indicating the full path.

For example:

>>> p = ['/usr', 'share', 'logs/vars', 'included', 'hola.txt']
>>> get_path(p)
'/usr/share/logs/vars/included/hola.txt'

New in version 0.1.0.

candyshop.utils.strip_comments_and_blanks(strng=None)[source]

Remove single-line comments and blank lines.

This function receives a string and removes every line containing a comment or a blank line.

Parameters:strng – (string) a string.
Returns:(string) the string without comments or blank lines.

For example:

>>> s = '''
... # This is a comment
...
... bar # This is an inline comment
...
... foo # Another comment
... # I comment a lot
...
... '''
>>> strip_comments_and_blanks(s)
'bar\nfoo'

New in version 0.1.0.