cots.core – Product Handler Core Module¶
This module defines core functions and classes for product handlers.
Product handlers are derived classes from BaseProduct class.
Public Classes¶
This module has has several public class listed below in alphabetical order.
Public Functions¶
This module has a number of functions listed below in alphabetical order.
Objects reference¶
This section details the objects defined in this module.
- class cots.core.BaseProduct¶
Bases:
objectCommon base class for all product handlers.
- name¶
The name of the product. It is used in report mail, log file and as filename for the installer (see
fetch)- Type
- display_name¶
The name of the product as it appears in the ‘Programs and Features’ control panel (see Uninstall Registry Key).
- Type
- target¶
The target architecture type (the Windows’ one) for the product. This argument must be one of the following values:
TARGET_X86,TARGET_X64orTARGET_UNIFIED. The “build target” of the application to retrieve. This part must contain one of the following values:win: Windows 32 bitswin64: Windows 64 bitsosx: MacOS Xlinux64: Linux x86 64 bitslinux: Linux i686
- Type
- release_note_location¶
The location of the release note for the detailed history change of the product.
- Type
- secure_hash¶
The secure_hash value of the product installer. It’s a 2-tuple containing, in this order, the name of secure_hash algorithm (see
hashlib.algorithms_guaranteed) and the secure_hash value in hexadecimal notation.- Type
2-tuple
- silent_inst_args¶
Arguments to use with the installer for a silent installation (i.e. without any user’s interaction, typically while an automated deployment using
lappdeployscript).- Type
- Public Methods
This class has a number of public methods listed below in alphabetical order.
- Methods to Override
This class is a base class, so a number of public methods must be overridden. They are listed below in alphabetical order.
- Using BaseProduct…
This class is the base class for product handler used by
lapptrack.LAppTrackand this one only use the public methods.After created a class instance, the
get_originmethod populate the attributes with the most up-to-date information from the editor’s site. An alternative way, is to call theloadmethod to populate attributes with a set of data previously saved on disk.Then calling
fetchmethod retrieves the current version (i.e. the one described in the attributes) of the installer and store it on the local disk.Then you can save the updated instances by calling the
dumpmethod.
- dump()¶
Dump a product class.
- Returns
Contain a copy of the instance variables values.
- Return type
- fetch(dirpath)¶
Download the product installer.
- get_name()¶
Return a comprehensive name of the product
- Returns
a human readable string with the handler attributes.
- Return type
- get_origin()¶
Get product information from the remote repository.
The latest catalog of the product is downloaded and parsed.
- is_update(product)¶
Return if this instance is an update of the product
This method compare the version of the two product, and return the comparison result.
- Parameters
product (BaseProduct) – The reference product (i.e. the deployed one)
- Returns
Trueif this instance is an update of the product specified by theproductparameter.- Return type
- load(attributes)¶
Load a product class.
- class cots.core.DownloadHandler(url, path=None, type=None, length=None, hash=None, progress=None)¶
Bases:
objectFile Download Handler
This class is a handler to download files available on a HTTP or FTP server. It fully manages the download process and the retrieved file may be stored in a regular or a temporary file.
- Parameters
url (str) – The URL of the file to retrieve.
path (str) – The local pathname of the retrieved file. An empty string will force the use of a temporary file (see
NamedTemporaryFile()). If the pathname is a directory, the retrieved file will be written in this directory, and the filename will be guessed from the url or HTTP response headers. [TODO]If the pathname is a valid filename, the retrieved file will use it.type (str) – (optional) The expected mime type of the retrieved file. No check will be done if the value is
None.length (int) – (optional) The expected length of the retrieved file expressed in bytes.
Nonemeans that the expected length is unknown.hash (tuple) – The expected secure hash value of the retrieved file. No check will be done if the value is
None. It’s a 2-tuple containing, in this order, the name of secure hash algorithm (seealgorithms_guaranteed) and the secure hash value in hexadecimal notation. If the secure hash algorithm is not supported, it will be ignored.progress (ProgressIndicatorWidget) – The progress widget. The
Nonevalue means that no progress indicator will be displayed.
- Raises
TypeError – Parameters type mismatch.
- Public Methods
This class has a number of public methods listed below in alphabetical order.
- Using DownloadHandler…
After created a class instance, the
fetchmethod downloads the file and populates the attributes.
- _close_container(keep=True)¶
Close the container and check its content.
- _get_filename_from_headers()¶
Get the file name from the
Content-Dispositionheader field.This method returns the file name specified in the
Content-Dispositionheader field as described in the RFC 2183 if it exists.TODO This method checks the file name compatibility with the underlying file system. If the suggested file name is not compatible, the method returns
None.
- _get_filename_from_url()¶
Get the file name from the url attribute.
This method returns the file name specified in the URL.
TODO This method checks the file name compatibility with the underlying file system. If the suggested file name is not compatible, the method returns
None.
- _open_container()¶
Open the container for the future retrieved file.
This method opens either a temporary file or a regular file depending on the value of the
pathattribute. It sets the_fileand thefilenameattributes.
- _post_check_hash()¶
Check the secure hash of the retrieved file.
- _post_check_length()¶
Check the length of the retrieved file.
- _pre_check_length()¶
Check the length of the file to retrieve.
- _pre_check_type()¶
Check the mime type of the file to retrieve.
- _write_container()¶
Fill the container with the content of the retrieved files
- fetch()¶
Download the product installer.
- hash¶
The secure hash value of the retrieved file. A secure hash is always computed and the default algorithm is SHA-1.
- Type
hashlib.hash
Functions reference¶
This section details the specific functions used in this module.
- cots.core.get_handler(qualname)¶
Retrieve an instance of a handler class.
A handler class is appointed by its qualified name (
package.module.MyHandlerfor example). If the module part is not specified, an ImportError exception is raised.- Parameters
qualname (str) – The qualified name of the handler class.
- Returns
an instance of the handler class.
- Return type
- Raises
TypeError – Parameters type mismatch.
ImportError – Import fails to find the handler module or class.
- cots.core.get_file_hash(path, hash_name)¶
Compute a secure hash based on the content of a file.
- Parameters
path (str) – The pathname of the file
hash_name – The name of secure hash algorithm (see
hashlib.algorithms_guaranteed). If the secure hash algorithm is not supported, aValueErrorexception is raised.
- Returns
A hash object instance (see
hashlib). This instance contains the computed hash of the given path.- Return type
HASH
Data reference¶
This section details global data, including both variables and values used as ‘defined constants’.
- cots.core.TARGET_X86 = 'x86'¶
The application works only on 32 bits architecture.
- cots.core.TARGET_X64 = 'x64'¶
The application works only on 64 bits architecture.
- cots.core.TARGET_UNIFIED = 'unified'¶
The application or the installation program work on both architectures.