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 aoca_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 theBundle
.-
_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 atests
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 atests
folder will be excluded. False otherwise.
-
modules
= None¶ Attribute
Bundle.modules
(list): A list containing instances ofModule
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.
-
_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), orNone
(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
orNone
): 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 (__manifest__.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.environment
is a module for creating Odoo environments.
This module implements an abstraction layer to create an environment where bundles can be consulted for different reports.
-
class
candyshop.environment.
Environment
(init=True, init_from=None, url='https://github.com/odoo/odoo', branch='15.0')[source]¶ An Environment is a virtual space where you can enclose bundles.
Think about it as an invisible container where you can put bundles to study its relationships; for example, listing all modules and see which ones have missing dependencies (that are not within the environment).
-
_Environment__clone_deptree
()¶ Private method that clones the dependency tree of existing bundles.
It reads the oca_dependencies attribute of each bundle, clones each one (if any) and then adds them as bundles (which invokes this method again to satisfy dependencies in the new bundles).
New in version 0.1.0.
-
_Environment__deps_notin_e
(deps=None)¶ Private method that informs about missing modules in the environment.
Parameters: deps – (list) a list of module names to check. Returns: (generator) a generator that produces an iterable of module names that are not present in the environment. New in version 0.1.0.
-
static
_Environment__git_clone
(url, branch, path)¶ Private method to clone a git repository.
This method clones a git repository specified by
url
andbranch
to a folderpath
. The--depth=1
option is passed to the command to avoid cloning full history.New in version 0.1.0.
-
_Environment__initialize_odoo
(url='https://github.com/odoo/odoo', branch='15.0', init_from=None)¶ Private method to clone an Odoo codebase inside the Environment path.
This method clones an odoo codebase specified by
url
andbranch
so that bundles can have the native odoo bundles to compare with. Without this method, native modules (base, board, etc) would appear as missing dependencies.New in version 0.1.0.
-
__init__
(init=True, init_from=None, url='https://github.com/odoo/odoo', branch='15.0')[source]¶ Initialize the
Environment
instance.Parameters: - init – (boolean) specifies if the environment should be initialized, that is, if an Odoo repo should be cloned and the native addons added as bundles. Default: True.
- init_from – (string) a path pointing to an Odoo codebase. If present, the Odoo codebase will be taken from this folder instead of cloning from start.
- url – (string) an URL pointing to a git repository. This URL is
used to clone the Odoo Codebase if
init
isTrue
andinit_from
isNone
. - branch – (string) the branch used to clone
url
.
Returns: an
Environment
instance.New in version 0.1.0.
-
__weakref__
¶ list of weak references to the object (if defined)
-
addbundles
(locations=None, exclude_tests=True)[source]¶ Public method that inserts bundles inside the environment.
This method register a list of bundles and builds the dependency tree of each bundle recursively by calling
__clone_deptree()
.Parameters: - locations – (list) a list of strings containing relative or absolute paths to directories containig bundles.
- exclude_tests – (boolean) if
True
, will exclude modules insidetests
directories.
New in version 0.1.0.
-
bundles
= None¶ Attribute
Environment.bundles
(list): A list ofBundle
instances representing the bundles contained in this environment.
-
destroy
()[source]¶ Public method to destroy an
Environment
instance.This method empties the bundle list and deletes the environment path, including all previously clones bundles.
New in version 0.1.0.
-
get_bundle_path_list
()[source]¶ Public method that informs about bundle paths.
Returns: (generator) a generator that produces an iterable of paths pointing to the bundles registered so far. New in version 0.1.0.
-
get_modules_list
()[source]¶ Public method that informs about modules instances.
Returns: (generator) a generator that produces an iterable of Module
instances of all the modules present within the environment.New in version 0.1.0.
-
get_modules_slug_list
()[source]¶ Public method that informs about module names.
Returns: (generator) a generator that produces an iterable of strings containing the names of all the modules present within the environment. New in version 0.1.0.
-
get_notmet_dependencies
()[source]¶ Public method that informs about missing dependencies in modules.
Returns: (generator) a generator that produces an iterable of dictionaries containing references to each bundle that have unmet dependencies within a module. The output is something similar tho this: [ {'bundle-name': { 'module_name': ['missing_module_a', 'missing_module_b'] } } ]
New in version 0.1.0.
-
get_notmet_dependencies_report
()[source]¶ Public method that reports missing dependencies in modules.
Returns: (string) a report of human readable output for the get_notmet_dependencies()
method.New in version 0.1.0.
-
get_notmet_record_ids
()[source]¶ Public method that informs about missing dependencies in XML files.
Returns: (generator) a generator that produces an iterable of dictionaries containing references to each bundle that have unmet dependencies refereced inside XML record ids. The output is something similar to this: [ {'bundle-name': { 'module_name/path/file.xml': ['missing_module_a', 'missing_module_b'] } } ]
New in version 0.1.0.
-
get_notmet_record_ids_report
()[source]¶ Public method that reports missing dependencies in XML files.
Returns: (string) a report of human readable output for the get_notmet_record_ids()
method.New in version 0.1.0.
-
path
= None¶ Attribute
Environment.path
(string): A path pointing to the temporary directory where odoo and OCA dependencies will be cloned.
-
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.