dal.tools package

Submodules

dal.tools.backup module

Copyright (C) Mov.ai - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential

Developers: - Tiago Teixeira (tiago.teixeira@mov.ai) - 2020

Backup a.k.a. Import Export tool

class dal.tools.backup.Backup(project, debug: bool = False, recursive=True)

Bases: object

Base class for Importer and Exporter.

SCOPES = ['Flow', 'Node', 'StateMachine', 'Callback', 'GraphicScene', 'Annotation', 'Package', 'Ports', 'Message', 'GraphicAsset', 'Layout', 'Robot', 'System', 'Configuration', 'TaskTemplate', 'Translation', 'SharedDataTemplate', 'SharedDataEntry', 'Alert']
static read_manifest(manifest: str, all_default=[None]) dict

Reads a manifest file and returns the declared objects.

Parameters:
  • manifest (str) – Path to the manifest file.

  • all_default – Default value for all objects, applied when ‘*’ is found.

run(objects: dict = {})
exception dal.tools.backup.BackupException

Bases: Exception

exception dal.tools.backup.ExportException

Bases: Exception

class dal.tools.backup.Exporter(*args, **kwargs)

Bases: Backup

Exports projects data from the database.

code2file(code, path)
dependencies_node(node)
dependencies_tasktemplate(tasktemplate)
dict2file(data, path)
dump2file(data, path)
export_callback(name)
export_configuration(name)
export_default(scope, name)
export_flow(name)
export_graphicscene(name)
export_message(name)
Message/

<pack_name|obj_id>.json <pack_name|obj_id>/

<Type>(<msg_1>.source <Type>/<msg_1>.compiled <Type>/<msg_2>.source <Type>/<msg_2>.compiled …

export_node(name)
export_package(name)
export_ports(name)
export_shareddataentry(name)
export_statemachine(name)
export_tasktemplate(name)
export_translation(name)
exported(scope, name)
get_objs(scope)

Get all objects of a given scope.

override(path)
ports2file(data, path)
read_manifest(manifest)

Reads a manifest file and returns the declared objects.

Parameters:
  • manifest (str) – Path to the manifest file.

  • all_default – Default value for all objects, applied when ‘*’ is found.

run(objects: dict = {})

Exports the objects defined in the manifest.

set_exported(scope, name)
class dal.tools.backup.Factory

Bases: object

CLASSES_CACHE = {}
static get_class(scope)

Get scope class.

exception dal.tools.backup.ImportException

Bases: Exception

class dal.tools.backup.Importer(project, force: bool = False, dry: bool = False, clean_old_data: bool = False, **kwargs)

Bases: Backup

Imports project data to the database.

SKIP_SCOPE_DELETE = ['Package']
dependencies_node(node: dict)
dependencies_ports(ports: dict)
dependencies_tasktemplate(tasktemplate: dict)
get_files(scope, names, extract=<function Importer.<lambda>>, build=<function Importer.<lambda>>, list_match=<function Importer.<lambda>>, get_match=<function isfile>)
get_objs(scope)

Get all objects of a given scope.

For importer, this is always [None].

import_callback(names=None)

Imports Callback, similar to import_default but also updates Callback’s Code.

import_configuration(names=None)
import_default(scope, names=None)

Default import function.

Imports the specified names to the database, if names is None (default), imports every file.

import_flow(names=None)

Imports Flow, similar to import_default but imports dependencies.

import_graphicscene(names=None)
import_message(names=None)
import_node(names=None)

Imports Node, similar to import_default but imports dependencies.

import_package(names=None)

Import Package, recursively look for files of the package

import_ports(names=None)
import_shareddataentry(names=None)
import_statemachine(names=None)
import_tasktemplate(names=None)
import_translation(names=None)

Import translation, read all po files.

imported(scope, name) bool

Wrapper to check if a scope:name pair is already imported.

run(objects: dict = {})

Imports the objects defined in the manifest.

set_imported(scope, name)

Wrapper to set a scope:name pair as imported.

exception dal.tools.backup.RemoveException

Bases: Exception

Exception used when removing metadata.

class dal.tools.backup.Remover(force: bool = False, dry: bool = False, **kwargs)

Bases: Backup

Handles the deletion of metadata from the database.

This class does not support force, nor recursive.

force

Force flag to be validated, must be false, still an argument for validation.

Type:

bool

dry_run

If a dry run (no actual changes to database) is to be performed.

Type:

bool

dry_print

Function used during dry run to print actions that would be performed.

Type:

func

get_objs(scope)

Get all objects in given a scope.

In the case of remover, is simply [].

Parameters:

scope – Metadata scope.

Returns:

List containing a None.

remove_default(scope, names)

Deletes a series of scope:name pairs from the database.

Parameters:
  • scope – Metadata scope.

  • name – Item name.

removed(scope, name)

Wrapper to check if a scope:name pair was already removed.

Parameters:
  • scope – Metadata scope.

  • name – Item name.

Returns:

True if it has been removed, False otherwise.

run(objects: dict = {})

Remover main function, removes the defined objects.

Parameters:

objects – Dict with scope names as keys and list of items to be removed as value

set_removed(scope, name)

Wrapper to set a scope:name pair as removed.

Parameters:
  • scope – Metadata scope.

  • name – Item name.

dal.tools.backup.backup(args) int

Main function to handle the backup actions based on provided arguments.

dal.tools.backup.main() int

Main function to handle command line arguments and execute the backup tool.

dal.tools.backup.test_reachable(redis_url)

Helper function to test wether a redis_server is reachable or not :param redis_url: URL of redis server to test :type redis_url: string

Returns:

True if reachable

Return type:

bool

dal.tools.edit_yaml module

dal.tools.edit_yaml.main()

dal.tools.extract_i18n module

class dal.tools.extract_i18n.CallVisitor(filename: str)

Bases: NodeVisitor

AST visitor that collects strings from logging function calls where the ‘ui’ keyword argument is set to True.

filename

The name of the file being parsed.

Type:

str

strings

List of extracted SourceString objects.

Type:

List[SourceString]

visit_Call(funccall: Call) None

Visits each function call node in the AST. If the call is to a logging function (‘info’, ‘warning’, ‘error’, or ‘exception’) and has a keyword argument ‘ui=True’, it extracts the first argument (the log message) as a string. The extracted string, along with its location (line number, column offset, and filename), is stored for later use. Handles both regular strings and f-strings, and falls back to a placeholder if the argument type is unexpected.

class dal.tools.extract_i18n.SourceString(value: str, lineno: int, col_offset: int, filename: str, is_f_string: bool)

Bases: object

Represents a string extracted from source code, along with its location.

value

The extracted string value.

Type:

str

lineno

The line number in the source file where the string appears.

Type:

int

col_offset

The column offset in the source file.

Type:

int

filename

The name of the source file.

Type:

str

col_offset: int
filename: str
is_f_string: bool
lineno: int
value: str
dal.tools.extract_i18n.confirm_overwrite(file: Path)
dal.tools.extract_i18n.main()
dal.tools.extract_i18n.make_json_file(output_path: Path, name: str) None

Create a JSON file that lists the metadata translation file.

Parameters:
  • output_path (Path) – Directory to save the JSON file.

  • name (str) – Name of the metadata translation file.

dal.tools.extract_i18n.make_po_file(strings: List[SourceString], output_path: Path, name: str, locale: Locale) None

Write extracted strings to a .po file for translation using Babel.

Parameters:
  • strings (List[SourceString]) – List of SourceString objects to write.

  • output_path (str) – Directory to save the .po file.

  • name (str) – Name of the metadata translation file.

  • locale (str) – Locale code for the .po file.

dal.tools.extract_i18n.parse_code(code: str, filename: str) List[SourceString]

Parse Python source code and extract strings from logging calls with ‘ui=True’.

Parameters:
  • code (str) – The Python source code to parse.

  • filename (str) – The name of the source file.

Returns:

List of extracted SourceString objects.

Return type:

List[SourceString]

dal.tools.extract_i18n.parse_directory(dir_path: str) List[SourceString]

Recursively parse all Python files in a directory, extracting strings from logging calls with ‘ui=True’.

Parameters:

dir_path (str) – Path to the directory containing Python files.

Returns:

List of all extracted SourceString objects.

Return type:

List[SourceString]

dal.tools.mobdata module

Tool to import, export and remove data.

dal.tools.mobdata.main() int

dal.tools.secret_key module

class dal.tools.secret_key.BaseCommand(**kwargs)

Bases: ABC

Base Class for the varios tool commands.

check_length()

Checks the legnth argument

Raises:

ArgumentError – in case the length argument is missing or his value is not in the allowed range.

check_name()

Checks the name argument

abstract execute() int

Abstract funtion for exuting command.

Returns:

output from the command.

Return type:

any

fail_argument(arg_name: str)

A general function for raising ArgumentError.

Parameters:

arg_name (str) – The name of the argument to check

Raises:

ArgumentError – In case the argument is missing.

log = <Logger BaseCommand (INFO)>
class dal.tools.secret_key.CreateCommand(**kwargs)

Bases: BaseCommand

Creates an new secret key in DB.

Parameters:
  • name (str) –

  • length (int) –

execute() int

Abstract funtion for exuting command.

Returns:

output from the command.

Return type:

any

class dal.tools.secret_key.RemoveCommand(**kwargs)

Bases: BaseCommand

Removes a key from DB.

Parameters:

name (str) –

execute() int

Abstract funtion for exuting command.

Returns:

output from the command.

Return type:

any

class dal.tools.secret_key.SecretKeyTool

Bases: object

A class for executing the correct command

commands = {'create': <class 'dal.tools.secret_key.CreateCommand'>, 'remove': <class 'dal.tools.secret_key.RemoveCommand'>, 'show': <class 'dal.tools.secret_key.ShowCommand'>, 'update': <class 'dal.tools.secret_key.UpdateCommand'>}
class dal.tools.secret_key.ShowCommand(**kwargs)

Bases: BaseCommand

Dispalys the the key on the user terminal.

execute() int

Abstract funtion for exuting command.

Returns:

output from the command.

Return type:

any

class dal.tools.secret_key.UpdateCommand(**kwargs)

Bases: BaseCommand

Updates a key in DB.

Parameters:
  • name (str) –

  • length (int) –

execute() int

Abstract funtion for exuting command.

Returns:

output from the command.

Return type:

any

dal.tools.secret_key.main()

Module contents