zensols.grsync package#

Submodules#

zensols.grsync.app#

Inheritance diagram of zensols.grsync.app

Application entry point.

class zensols.grsync.app.Application(dist_mng_factory)[source]#

Bases: object

Application base class.

CLASS_INSPECTOR = {}#
CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'repo_pref': {'short_name': 'r'}}}#
__init__(dist_mng_factory)#
property dist_mng: DistManager#
dist_mng_factory: DistManagerFactory#

The main class that freezes/thaws and provides repo information.

class zensols.grsync.app.CopyMoveApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)[source]#

Bases: TargetApplication

CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'dir_reduce': {'long_name': 'reduce', 'short_name': None}, 'dist_dir': {'metavar': 'DIRECTORY', 'short_name': 'd'}, 'dry_run': {'short_name': None}, 'move_dir': {'metavar': 'DIRECTORY'}, 'profiles': {'short_name': 'p'}, 'repo_pref': {'short_name': 'r'}, 'target_dir': {'metavar': 'DIRECTORY', 'short_name': 't'}}}#
__init__(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)#
copy(repo_pref=None)[source]#

Build out a distribution.

Parameters:

repo_pref (str) – the repository to make primary on thaw

move(move_dir=None, dir_reduce=False)[source]#

Move a distribution to another root (easy to delete).

Parameters:
  • move_dir (Path) – the location of build out move dir

  • reduce – dir_remove empty directories

class zensols.grsync.app.DistManagerFactory(path)[source]#

Bases: object

Creates instances of DistManager.

__init__(path)#
property config: AppConfig#
path: Path#

The path to the YAML application configuration file.

class zensols.grsync.app.FreezeApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False)[source]#

Bases: ModifyApplication

CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'dist_dir': {'metavar': 'DIRECTORY', 'short_name': 'd'}, 'dry_run': {'short_name': None}, 'profiles': {'short_name': 'p'}, 'repo_pref': {'short_name': 'r'}}}#
__init__(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False)#
freeze(wheel_dep=PosixPath('zensols.grsync'), repo_pref=None)[source]#

Create a distribution.

Parameters:
  • whee_dep – used to create the wheel dep files

  • repo_pref (str) – the repository to make primary on thaw

class zensols.grsync.app.InfoApplication(dist_mng_factory, log_config, profiles=None)[source]#

Bases: Application

Captures and syncronizes a user home and its Git repositories with other hosts.

CLI_META = {'mnemonic_overrides': {'list_profiles': 'profiles'}, 'option_excludes': {'dist_mng_factory', 'log_config'}, 'option_overrides': {'repo_pref': {'short_name': 'r'}}}#
__init__(dist_mng_factory, log_config, profiles=None)#
info()[source]#

Pretty print discovery information.

list_profiles()[source]#

Print the profiles

log_config: LogConfigurator#

The application log configurator.

profiles: str = None#

Comma spearated list of profiles in config.

repoinfo(names=None)[source]#

Get information on repositories.

Parameters:

names (str) – the last component of the repo’s directory name

repos(format='{path}')[source]#

Output all repository top level info.

Parameters:

format (str) – format string (ie {name}: {path}, remotes={remotes}, dirty={dirty})

class zensols.grsync.app.ModifyApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False)[source]#

Bases: Application

Super class for applications that modify the file system.

CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'dist_dir': {'metavar': 'DIRECTORY', 'short_name': 'd'}, 'dry_run': {'short_name': None}, 'profiles': {'short_name': 'p'}, 'repo_pref': {'short_name': 'r'}}}#
__init__(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False)#
dist_dir: Path = None#

The location of build out distribution.

dry_run: bool = False#

Do not do anything, just act like it.

profiles: str = None#

Comma spearated list of profiles in config.

class zensols.grsync.app.TargetApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)[source]#

Bases: ModifyApplication

CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'dist_dir': {'metavar': 'DIRECTORY', 'short_name': 'd'}, 'dry_run': {'short_name': None}, 'profiles': {'short_name': 'p'}, 'repo_pref': {'short_name': 'r'}, 'target_dir': {'metavar': 'DIRECTORY', 'short_name': 't'}}}#
__init__(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)#
target_dir: Path = None#

The location of build out target dir.

class zensols.grsync.app.ThawApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)[source]#

Bases: TargetApplication

CLI_META = {'option_excludes': {'dist_mng_factory'}, 'option_overrides': {'dist_dir': {'metavar': 'DIRECTORY', 'short_name': 'd'}, 'dry_run': {'short_name': None}, 'profiles': {'short_name': 'p'}, 'repo_pref': {'short_name': 'r'}, 'target_dir': {'metavar': 'DIRECTORY', 'short_name': 't'}}}#
__init__(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False, target_dir=None)#
thaw()[source]#

Build out a distribution.

zensols.grsync.bootstrap#

Inheritance diagram of zensols.grsync.bootstrap

A utility class to create a bootstrapping script to install Python.

class zensols.grsync.bootstrap.BootstrapGenerator(config)[source]#

Bases: object

Generate the script that creates the distribution on the target machine.

PARAM_PATH = 'discover.bootstrap'#
SCRIPT = '#!/bin/sh\n\nif [ $# -eq 0 ] ; then\n    echo "usage: $0 <python_dir> [grsync dir] [python<version>]"\n    echo "where: python_dir is the bin directory where python is installed"\n    echo "       grsync_dir is the distribution directory copied from the source"\n    echo "       python<version> is the version of python (i.e. python3.6)"\n    exit 1\nfi\nNATIVE_PYTHON_BIN_DIR=$1\n\nif [ $# -ge 2 ]; then\n    echo "setting inst dir: $2"\n    GRSYNC_INST_DIR=$2\nelse\n    GRSYNC_INST_DIR=`pwd`\nfi\n\nif [ $# -ge 3 ]; then\n    echo "setting python ver: $3"\n    PYTHON_VER=$3\nelse\n    PYTHON_VER=$NATIVE_PYTHON_BIN_DIR\nfi\n\nPYTHON_DIR=${HOME}/opt/lib/python3\nPIP=${PYTHON_DIR}/bin/pip3\nPYTHON_PAR=`dirname $PYTHON_DIR`\nWHEELS_DIR=${GRSYNC_INST_DIR}/%(wheel_dir)s\nWHEELS=${WHEELS_DIR}/*.whl\n\nif [ -f ${PIP} ] ; then\n    PIP=${PYTHON_DIR}/bin/pip3\nfi\n\necho "GRSYNC_INST_DIR=${GRSYNC_INST_DIR}"\necho "PYTHON_DIR=${PYTHON_DIR}"\necho "PYTHON_VER=${PYTHON_VER}"\necho "PIP=${PIP}"\necho "PYTHON_PAR=${PYTHON_PAR}"\necho "WHEELS_DIR=${WHEELS_DIR}"\necho "WHEELS=${WHEELS}"\n\necho "bootstrapping python env in ${PYTHON_DIR}, wheels: ${WHEELS}"\n\nrm -rf $PYTHON_PAR\n\ncmd="${NATIVE_PYTHON_BIN_DIR}/bin/python3 -m venv --copies ${PYTHON_DIR}"\n\necho "invoke $cmd"\nmkdir -p $PYTHON_PAR &&     cd $PYTHON_PAR &&     $cmd &&     cd - || exit 1\n\nif [ -d ${WHEELS_DIR} ] ; then\n    echo "installing from wheel"\n    ${PIP} install ${GRSYNC_INST_DIR}/%(wheel_dir)s/zensols.grsync*\nelse\n    echo "installing from net"\n    ${PIP} install zensols.grsync\nfi\n\n# ${PIP} install ${WHEELS}\n\nrm ${HOME}/.bash* ${HOME}/.profile*\n# echo to thaw the repo: ${PYTHON_DIR}/bin/grsync thaw -d ${GRSYNC_INST_DIR}\n${PYTHON_DIR}/bin/grsync thaw -d ${GRSYNC_INST_DIR}\n'#
__init__(config)[source]#
generate(path)[source]#

zensols.grsync.cli#

Inheritance diagram of zensols.grsync.cli

Command line entry point to the application.

class zensols.grsync.cli.ApplicationFactory(*args, **kwargs)[source]#

Bases: ApplicationFactory

__init__(*args, **kwargs)[source]#
zensols.grsync.cli.main(args=['/Users/landes/opt/lib/python/bin/sphinx-build', '-M', 'html', '/Users/landes/view/util/grsync/target/doc/src', '/Users/landes/view/util/grsync/target/doc/build'], **kwargs)[source]#
Return type:

ActionResult

zensols.grsync.config#

Inheritance diagram of zensols.grsync.config

Specialized application configuration.

class zensols.grsync.config.AppConfig(config_file=None, default_vars=None)[source]#

Bases: YamlConfig

Application specific configuration access and parsing.

Since much of the application centers around configuration of what to persist, this class does more heavy lifting than most configuraetion like classes.

EMPTY_DIR_PATH = 'discover.empty_dirs'#
EMPTY_DIR_PROFILE_PATH = 'discover.profiles.{}.empty_dirs'#
OBJECTS_PATH = 'discover.objects'#
OBJECTS_PROFILE_PATH = 'discover.profiles.{}.objects'#
PROFILES_PATH = 'discover.profiles'#
ROOT = 'discover'#
__init__(config_file=None, default_vars=None)[source]#

Initialize this instance. When sections are not set, and the sections are not given in configuration file at location sections_name the root is made a singleton section.

Parameters:
  • config_file – the configuration file path to read from; if the type is an instance of io.TextIOBase, then read it as a file object

  • default_vars – used in place of missing variables duing value interpolation; deprecated: this will go away in a future release

  • default_section – used as the default section when non given on the get methds such as get_option(); which defaults to defualt

  • delimiter – the delimiter used for template replacement with dot syntax, or None for no template replacement

  • sections_name – the dot notated path to the variable that has a list of sections

  • sections – used as the set of sections for this instance

property bootstrap_script_file#
property dist_dir#
get_discoverable_objects(profiles)[source]#
get_empty_dirs(profiles)[source]#
get_profiles(profile_overide=None)[source]#
static split_profiles(profile_str)[source]#
property wheel_dir_name#

zensols.grsync.distmng#

Inheritance diagram of zensols.grsync.distmng

Distribution manager class.

class zensols.grsync.distmng.DistManager(config, dist_dir=None, target_dir=None, profiles=None, repo_preference=None, dry_run=False)[source]#

Bases: object

The main entry point that supports saving user home directory information (freezing) so that the data can later be restored (thawed). It does this by finding git repositories and saving the remotes. It also finds symbolic links, files and empty directories specified in the configuration.

__init__(config, dist_dir=None, target_dir=None, profiles=None, repo_preference=None, dry_run=False)[source]#

Initialize.

Parameters:
  • config (YamlConfig) – the app config

  • dist_dir (Path) – the location of the frozen distribution

  • target_dir (Path) – the location of the distrbution to freeze or where to exapand (default to the user home)

  • profiles (List[str]) – the (maven like) profiles that define what to freeze

  • repo_preference (str) – the repository to make master on thaw (default to configuration file)

property app_version: str#
copy()[source]#

Copy a local distribution to a different directory on the local file system.

discover_info()[source]#

Proviate information about what’s found in the user home directory. This is later used to freeze the data.

property discoverer: Discoverer#
property distribution#
freeze(wheel_dependency=None)[source]#

Freeze the current configuration and file set to the distribution zip.

move(destination_path, dir_reduce=True)[source]#

Move a thawed file set to destination_path. If dir_reduce is True then recursively remove directories.

print_repo_info(names=None)[source]#
print_repos(fmt=None)[source]#
thaw()[source]#

Expand the distribution zip on to the file system.

tmp()[source]#

zensols.grsync.distribution#

Inheritance diagram of zensols.grsync.distribution

“Contains the class needed to thaw the distribution.

class zensols.grsync.distribution.Distribution(path, defs_file, target_dir, path_translator)[source]#

Bases: object

Represents a frozen distribution.

__init__(path, defs_file, target_dir, path_translator)[source]#

Initialize the distribution instance.

Parameters:
  • path (Path) – points to the distribution file itself

  • target_dir (Path) – points to the directory where we thaw the distribution

  • path_translator (PathTranslator) – translates relative paths to the thaw directory

property empty_dirs: Iterable[FileEntry]#

Get empty directories defined in the dist configuration.

property files: Iterable[FileEntry]#

Get the files in the distribution.

classmethod from_discoverer(discoverer, target_dir)[source]#

Return a distrbution directly from the data structure created from Discoverer.

Parameters:
  • discoverer (Discoverer) – a discoverer instance created by the freeze state

  • target_dir (Path) – where the distribution will be thawed

Return type:

Distribution

classmethod from_struct(struct, target_dir)[source]#

Return a distrbution directly from the data structure created from Discoverer.

Parameters:
Return type:

Distribution

Pattern links and symbolic links not pointing to repositories.

property repos: Iterable[FrozenRepo]#

Repository specifications.

property struct: Dict[str, Any]#

Return the JSON deserialized (meta data) of the distribution.

property version: str#

Get the distribution format version, which for now, is just the application version.

zensols.grsync.domain#

Inheritance diagram of zensols.grsync.domain

Domain and container classes, mostly modeling Git repos.

class zensols.grsync.domain.FileEntry(dist, finfo)[source]#

Bases: object

Represents a file based entry in the frozen version of the distribution zip.

__init__(dist, finfo)[source]#
property mode#

Return the numeric mode of the file

property modestr#

Return a human readable string of the mode of the file.

property modify_time#

Return the numeric modify time of the file

property path#

Return the absolute path of the file.

property relative#

Return the relative path of the file.

class zensols.grsync.domain.LinkEntry(dist, finfo, target_dir=None)[source]#

Bases: FileEntry

Represents a symbolic link in the frozen version of the distribution zip.

__init__(dist, finfo, target_dir=None)[source]#
property relative#

Return the relative path of the file.

property source#
property target#
class zensols.grsync.domain.PathTranslator(target_path)[source]#

Bases: object

Utility class around helping with paths.

__init__(target_path)[source]#
expand(path)[source]#

Return the user’s home directory as a pathlib.Path object.

relative_to(path)[source]#

Return a path that’s relative to the user’s home directory.

to_relative(path)[source]#
class zensols.grsync.domain.RemoteSpec(remote, is_master=None)[source]#

Bases: object

This class represents a remote for a git repo.

__init__(remote, is_master=None)[source]#

Initialize.

Parameters:
  • remote (Remote) – a remote object from the git repo

  • is_master – whether or not the remote is the primary (upstream) remote

freeze()[source]#

Freeze/create an object graph representation of the remote as a dict.

property name#

Return the remote’s name.

rename(name, url=None)[source]#

Rename the remote in the git repository itself, along with the class instance.

Bases: object

This classs represents a file system symbolic link. The class also freezes created symbol links.

__init__(source, path_translator)[source]#

Create.

Parameters:

source (Path) – the Path that points to the symbolic link on the local file system.

freeze()[source]#

Create and return an object graph as a dict of the link.

increment_use_count()[source]#

Indicate this symblic link is used (linked) to another target.

property source_relative#

The relative location source (to the user’s home).

property target#

The target (where it point to).

property target_relative#

The relative location (where it points to) relative to the user’s home.

zensols.grsync.freeze#

Inheritance diagram of zensols.grsync.freeze

Includes classes that read the configuration and traverse the file system to find matching objects to use to freeze the distribution.

class zensols.grsync.freeze.Discoverer(config, profiles, path_translator, repo_preference)[source]#

Bases: object

Discover git repositories, links, files and directories to save to reconstitute a user home directory later.

CONF_TARG_KEY = 'discover.target.config'#
REPO_PREF = 'discover.repo.remote_pref'#
__init__(config, profiles, path_translator, repo_preference)[source]#
discover(flatten)[source]#

Main worker method to capture all the user home information (git repos, files, sym links and empty directories per the configuration file).

Parameters:

flatten – if True then return a data structure appropriate for pretty printing; this will omit data needed to create the distrubtion so it shouldn’t be used for the freeze task

Return type:

Dict[str, Any]

freeze(flatten=False)[source]#

Main entry point method that creates an object graph of all the data that needs to be saved (freeze) in the user home directory to reconstitute later (thaw).

Parameters:

flatten – if True then return a data structure appropriate for pretty printing; this will omit data needed to create the distrubtion so it shouldn’t be used for the freeze task

get_discoverable_objects()[source]#

Find git repos, files, sym links and directories to reconstitute later.

property profiles#
property repo_preference#

Return the preference for which repo to make primary on thaw

class zensols.grsync.freeze.FreezeManager(config, dist_file, defs_file, discoverer, app_version, dry_run)[source]#

Bases: object

Invoked by a client to create frozen distribution .

CREATE_WHEEL = 'discover.wheel.create'#
__init__(config, dist_file, defs_file, discoverer, app_version, dry_run)[source]#
freeze(wheel_dependency=None)[source]#

Freeze the distribution by saving creating a script to thaw along with all artifacts (i.e. repo definitions) in a zip file.

zensols.grsync.mover#

Inheritance diagram of zensols.grsync.mover
class zensols.grsync.mover.DistributionMover(dist, target_dir=None, destination_dir=None, force_repo=False, force_dirs=False, dry_run=False)[source]#

Bases: object

This class moves thawed files that are defined in a distribution zip. If the file is not defined in the distribution then it doesn’t move it.

In situations where you’ve already deleted the distribution zip, you’ll have to create a new distribution by freezing what you have. For this reason it is recommended that you always include the original grsync.yml configuration file in your distribution so it migrates along with each of your freeze/thaw iterations.

__init__(dist, target_dir=None, destination_dir=None, force_repo=False, force_dirs=False, dry_run=False)[source]#

Initialize.

Parameters:
  • dist (Distribution) – the distrbution that represent the distribution zip

  • target_dir – the directory with the thawed files

  • destination_dir (Path) – where the thawed files/repos will be moved

  • force_repo – if True move repositories even if they’re dirty

  • force_dirs – if True move directories even if they’re not empty

  • dry_run – don’t actually do anything, but log like we are

dir_reduce(parent=None)[source]#

Remove empty directories recursively starting at parent.

move()[source]#

Move the files over.

zensols.grsync.repospec#

Inheritance diagram of zensols.grsync.repospec

This module includes repository domain classes.

class zensols.grsync.repospec.FrozenRepo(remotes, links, target_dir, path, repo_pref, path_translator)[source]#

Bases: object

__init__(remotes, links, target_dir, path, repo_pref, path_translator)[source]#

Initialize.

Parameters:
  • remotes (List[Dict[str, str]]) – a list of dicts with keys name, url and is_master representing a git repository remote

  • links (List[LinkEntry]) – symbol links that link in to what will become the new repository after thawed (cloned)

  • target_dir (Path) – the root target directory of where the repository will be thawed (cloned)

  • path (Path) – the directory where the repository will be thawed (cloned)

  • repo_pref (str) – the remote to use as the first remote when thawed

  • path_translator (PathTranslator) – translates the distribution root

property exists: bool#

Return whether or not the repo represented by this frozen repo already exists.

property repo_spec: RepoSpec#

Return the repo spec for this frozen repo.

thaw()[source]#

Thaw a RepoSpec object, which does a clone and then creates the (remaining if any) remotes. This also creates the symbol links that link into this repo. Then return the object represented by the new repo.

Return type:

RepoSpec

class zensols.grsync.repospec.RepoSpec(path, path_translator, repo=None)[source]#

Bases: object

This class represents a git repository and all the symbolic links from the distribution (usually the user’s home directory) that link into it.

DEFAULT_FORMAT = '{name}: {path}, remotes={remotes}, dirty={dirty}'#
SHORT_FORMAT = '{name}: {path} ({remotes})'#
__init__(path, path_translator, repo=None)[source]#

Create with the path to the repo and optionally a git.Repo.

Parameters:
  • path (Path) – the directory where the repository will be thawed (cloned)

  • path_translator (PathTranslator) – translates the distribution root

  • repo (Repo) – the git repository to use in this instance, otherwise it will be created that points to what the path_translator resolves

add_linked(links)[source]#
format(fmt=None, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#

Human readable format.

freeze()[source]#

Freeze the data in this instance in to a tree of dicts usable in a JSON dump.

Return type:

Dict[str, Any]

property master_remote: str#

Return the first (preferred) remote that is used as the master for pull, fetch and push.

property name: str#

Return the name of the repository.

property remotes: List[RemoteSpec]#

Return a list or remote specs used as the repo’s remotes.

property repo: Repo#

Return the Git repository instance.

write(writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#

Human readable output.

zensols.grsync.thaw#

Inheritance diagram of zensols.grsync.thaw

Contains utility classes used to thaw distributions.

class zensols.grsync.thaw.ThawManager(dist, path_translator, app_version, dry_run=False)[source]#

Bases: object

__init__(dist, path_translator, app_version, dry_run=False)[source]#
assert_version()[source]#
thaw()[source]#

Thaw the distribution, which includes creating git repositories, extracting (frozen) files, creating symbolic links, and creating empty directories that were captured/configured during the freezing phase.

thaw_from_in_memory(source_dir)[source]#

Copy a local distribution to a different directory on the local file system.

Parameters:

source_dir (Path) – the distribution directory from where to copy files

Module contents#