checkpoint package

Subpackages

Submodules

checkpoint.crypt module

class checkpoint.crypt.Crypt(key, key_path='/home/runner/work/checkpoint/checkpoint', iterations=1)[source]

Bases: object

Class to perform cryptographical operations

decrypt(file, modify_file=False)[source]

Decrypt a specific file

Parameters:
  • file (str) – Path to the file or content that isto be decrypted

  • modify_file (bool, optional) – If True, the hash will be written in the target file

encrypt(file, modify_file=False)[source]

Encrypt a specific file

Parameters:
  • file (str) – Path to the file or content that isto be encrypted

  • modify_file (bool, optional) – If True, the hash will be written in the target file

checkpoint.crypt.generate_key(name, path='/home/runner/work/checkpoint/checkpoint')[source]

Generate a key to encrypt/decrypt files

Parameters:
  • name (str) – Name of the key, should end with .key extension

  • path (str, optional) – Path where key isto be stored

checkpoint.io module

class checkpoint.io.IO(path=None, mode='a', ignore_dirs=None, lazy=True)[source]

Bases: object

Class to perform Input/Output opreations.

Provides methods to perform various IO operations in the target directory.

path

Path to the target directory

Type:

str

mode

Mode of operations, valid values are a: IO has all permissions (R/W/X/A) m: IO has moderate permissions (R/W/A) s: IO has limited permissions (R/A)

Type:

str

delete_dir(dir_name)[source]

Delete a sub directory in the root directory.

Parameters:

dir_name (str) – Name of the sub directory

get_file_extension(file_path)[source]

Get the extension from the file.

Parameters:

file_path (str) – Path to the file

make_dir(dir_name)[source]

Make a sub directory in the root directory.

Parameters:

dir_name (str) – Name of the sub directory

property mode
property mode_mapping
open(file, mode)[source]

Open a file in a given mode.

Parameters:
  • file (str) – Name of the file

  • mode (str) – Mode of operation

property path
read(file, mode='r')[source]

Read the content of a file

Parameters:
  • file (str) – Name of the file

  • mode (str, optional) – Mode of operation

setup()[source]

Setup the IO class.

update_paths(path)[source]

Update the paths of files, sub_dirs w.r.t the path.

Parameters:

path (str) – Path to the target directory

walk_directory()[source]

Walk through the root directory.

write(file, mode, content)[source]

Write some content into a file.

Parameters:
  • file (str) – Name of the file

  • mode (str) – Mode of operation

  • content (str) – Content to write in the file

checkpoint.readers module

Module that provides readers for different file extensions.

class checkpoint.readers.ByteReader[source]

Bases: Reader

Class to read byte files or files that can’t be decoded by utf-8 encoder

class checkpoint.readers.ImageReader[source]

Bases: Reader

Class to read image files.

class checkpoint.readers.Reader(valid_extensions=None)[source]

Bases: object

Umbrella for all reader classes.

read(files, validate=True)[source]

Read the content of the file.

Parameters:
  • files (list) – List of files to be read

  • validate (bool) – Flag to validate the extensions

Returns:

content – Content of the file/files

Return type:

list

validate_extensions(extensions)[source]

Validate if the additional extensions are valid.

Parameters:

extensions (list) – List of extensions to be validated

Returns:

invalid_idxs – List of indices of invalid extensions

Return type:

list

class checkpoint.readers.TextReader[source]

Bases: Reader

Class to read text files.

checkpoint.readers.get_all_readers()[source]

Get all the readers from the module.

checkpoint.sequences module

class checkpoint.sequences.CLISequence(sequence_name='CLI_Sequence', order_dict=None, arg_parser=None, args=None, terminal_log=False, env='UI')[source]

Bases: Sequence

Sequence for the CLI environment.

seq_determine_action(args)[source]

Determine the action to be performed.

Parameters:

args (ArgumentParser) – Parsed arguments from the CLI.

seq_parse_args()[source]

Parse the arguments from the CLI.

seq_perform_action(action_args)[source]

Perform the action.

Parameters:

action_args (list) – List containing action and args NameSpace.

class checkpoint.sequences.CheckpointSequence(sequence_name, order_dict, root_dir, ignore_dirs, terminal_log=False, env='UI')[source]

Bases: Sequence

Sequence to perform checkpoint operations.

seq_create_checkpoint()[source]

Create a new checkpoint for the target directory.

seq_delete_checkpoint()[source]

Delete the checkpoint for the target directory.

seq_init_checkpoint()[source]

Initialize the checkpoint directory.

seq_restore_checkpoint()[source]

Restore back to a specific checkpoint.

seq_version()[source]

Print the version of the sequence.

class checkpoint.sequences.IOSequence(sequence_name='IO_Sequence', order_dict=None, root_dir=None, ignore_dirs=None, num_cores=None, terminal_log=False, env='UI')[source]

Bases: Sequence

Class to represent a sequence of IO operations.

seq_encrypt_files(contents)[source]

Encrypt the read files.

Parameters:

contents (dict) – Dictionary of file paths and their content.

Returns:

Dictionary of file paths and their encrypted content.

Return type:

dict

seq_group_files(directory2files)[source]

Group files in the same directory.

Parameters:

directory2files (dict) – Dictionary of directory names and their files.

seq_map_readers(extensions_dict)[source]

Map the extensions to their respective Readers.

Parameters:

extensions_dict (dict) – Dictionary of extensions and their files.

Returns:

Dictionary of extensions and their Readers.

Return type:

dict

seq_read_files(readers_extension)[source]

Read the gathered files using their respective reader.

Parameters:

readers_extension (list) – Readers dict and extensions dict packed in a list.

Returns:

Dictionary of files and their content.

Return type:

dict

seq_walk_directories()[source]

Walk through all directories in the root directory.

Parameters:

root_directory (str) – The root directory to be walked through.

class checkpoint.sequences.Sequence(sequence_name, order_dict=None, terminal_log=False, env='UI')[source]

Bases: object

Class to represent a sequence of operations.

add_sequence_function(func, order=0)[source]

Add a member function to the sequence.

Parameters:
  • func (method) – Function that is to be added to the sequence.

  • order (int, optional) – The order of the function in the sequence

add_sub_sequence(sequence, order=0)[source]

Add a sub sequence to the current sequence.

sequence: :class: Sequence

The sub sequence that is to be added

order: int, optional

The order of the sub sequence in the sequence

execute_sequence(execution_policy='decreasing_order', pass_args=False)[source]

Execute all functions in the current sequence.

Parameters:
  • execution_policy (str) – The policy to be followed while executing the functions. Possible values are ‘increasing_order’ or ‘decreasing_order’.

  • pass_args (bool) – If True, the arguments of the executed function will be passed to the next function.

flush_sequence()[source]

Flush the sequence.

generate_sequence()[source]

Generate a sequence from all memeber functions.

get_sequence_functions()[source]

Get all the sequence functions.

log(*args, **kwargs)[source]

Wrapper function for logger.log

property name
property sequence_functions
update_order()[source]

Update the order of sequence functions in sequence dict.

checkpoint.utils module

Module that provides utility functions/classes.

class checkpoint.utils.LogColors[source]

Bases: object

Provides colors for terminal logs.

BLUE = '[blue]'
BOLD = '[bold]'
CYAN = '[cyan]'
ENDC = '[/]'
ERROR = '[red]'
HEADER = '[underline][bold]'
SUCCESS = '[green]'
UNDERLINE = '[underline]'
WARNING = '[yellow]'
class checkpoint.utils.Logger(file_path='logs.log', log_mode='t')[source]

Bases: object

Provides logging utility functions.

log(msg, colors=None, as_obj=False, timestamp=False, log_caller=False, log_type='INFO')[source]

Log a message.

Parameters:
  • msg (str) – Message to log.

  • colors (list) – List of colors to use for the message.

  • as_obj (bool) – If True, the message will be logged as an object.

  • timestamp (bool) – If True, the current time will be added to the message.

  • log_caller (bool) – If True, the current function name will be added to the message.

  • log_type (str) – Type of log, can take values INFO, WARNING, ERROR, SUCCESS, etc.

property log_mode
checkpoint.utils.execute_command(command)[source]

Execute a command and get continuous output.

Parameters:

command (str) – Command to execute.

Yields:

line (str) – Output line.

checkpoint.utils.get_reader_by_extension(extension)[source]

Get the reader by an extension.

Parameters:

extension (str) – Extension of the file.

Returns:

reader – Reader class.

Return type:

class:

checkpoint.readers.Reader

Module contents