Code documentation

Documentation of code for developers.

jobs.py

class jobs.AdditiveJob(params)

Updating target with new files from sources.

class jobs.BaseSyncJob(params)

Base class for sync-type jobs.

run()

Run rsync to sync one or more sources with one target directory.

class jobs.Job(params)

Parent class for backup jobs.

excludes_to_options(excludes)

Convert a list of strings to a list of exclude options to rsync.

Parameters:excludes – List of excludes.
class jobs.SyncJob(params)

Simple backup syncing multiple sources to a target directory with full tree structure.

jobs.create_job_from_file(job_file)

Creates a job from a JSON job specification.

Parameters:job_file (str) – Path to job file.
Returns:Job object of specified type.

utils.py

class utils.FailureNotifier(job_file)

Keeps track of when the last time a job was successfully run.

Notifies user per e-mail.

notify()

Check if conditions for notification are fulfilled, and send e-mail.

record_successful_run()

Create an empty .josync-job-success file to mark a successful run.

class utils.Rsync(source, target, options=None)

Sub-class of subprocess.Popen to run rsync process.

output_thread(pipe, send)

Start thread handling output from rsync.

utils.enumerate_net_drives()

Runs NET USE and parses output.

Returns:List of drive letters and corresponding UNC path as dictionary.
utils.get_cygwin_path(path)

Return cygwin path for a given windows path.

Parameters:path (str) – The windows path to convert.
Returns:str – The cygwin path to path.
Raises:IOError
utils.get_file_modification_date(filename)

Read ‘last modified’ metadata of file

Parameters:filename (str) – filename (with path)
Returns:Datetime object with last modified datetime
utils.is_net_drive(drive)

Looks up drive in net_drives

Returns:True if drive is a net drive (is in net_drives list)
utils.read_config(default_cfg, user_cfg)

Reads config file and checks values.

Parameters:
  • default_cfg (str) – Path to default config file.
  • user_cfg (str) – Path to user config file.
Raises:

KeyError, IOError

utils.send_email(msg_address, msg_subject, msg_body)

Sends an e-mail notification using SMTP settings in config.

Parameters:
  • msg_subject (str) – Message subject.
  • msg_body (str) – Message body.
  • user_email (str) – E-mail to send notification to.
utils.shell_execute(command)

Run command with subprocess.Popen

Parameters:command (str) – Command to run.
Returns:2-tuple with return code and stdout.
utils.update_config(config_file)

Update the module config dict from a config file.

Parameters:config_file (str) – Path to JSON config file.
utils.volume_shadow(drive)

Creates a shadow copy of a drive and mounts it at a temporary directory.

Implemented with contextmanager to be used through the python with statement.

Parameters:drive (str) – Drive to shadow copy.
Yields:str – Path to temp folder where shadow copy is mounted.
Raises:OSError