zensols.grsync package¶
Submodules¶
zensols.grsync.app module¶
Application entry point.
- class zensols.grsync.app.Application(dist_mng_factory)[source]¶
Bases:
objectApplication 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)¶
- class zensols.grsync.app.DistManagerFactory(path)[source]¶
Bases:
objectCreates instances of
DistManager.- __init__(path)¶
- 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)¶
- class zensols.grsync.app.InfoApplication(dist_mng_factory, log_config, profiles=None)[source]¶
Bases:
ApplicationCaptures 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)¶
-
log_config:
LogConfigurator¶ The application log configurator.
- class zensols.grsync.app.ModifyApplication(dist_mng_factory, dist_dir=None, profiles=None, dry_run=False)[source]¶
Bases:
ApplicationSuper 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)¶
- 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)¶
- 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)¶
zensols.grsync.bootstrap module¶
A utility class to create a bootstrapping script to install Python.
- class zensols.grsync.bootstrap.BootstrapGenerator(config)[source]¶
Bases:
objectGenerate 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'¶
zensols.grsync.cli module¶
Command line entry point to the application.
- class zensols.grsync.cli.ApplicationFactory(*args, **kwargs)[source]¶
Bases:
ApplicationFactory
zensols.grsync.config module¶
Specialized application configuration.
- class zensols.grsync.config.AppConfig(config_file=None, default_vars=None)[source]¶
Bases:
YamlConfigApplication 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_namethe 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 objectdefault_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 todefualtdelimiter – the delimiter used for template replacement with dot syntax, or
Nonefor no template replacementsections_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¶
- default_section¶
- property dist_dir¶
- serializer¶
- property wheel_dir_name¶
zensols.grsync.distmng module¶
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:
objectThe 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 configdist_dir (
Path) – the location of the frozen distributiontarget_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 freezerepo_preference (
str) – the repository to make master on thaw (default to configuration file)
- 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.
zensols.grsync.distribution module¶
“Contains the class needed to thaw the distribution.
- class zensols.grsync.distribution.Distribution(path, defs_file, target_dir, path_translator)[source]¶
Bases:
objectRepresents a frozen distribution.
- __init__(path, defs_file, target_dir, path_translator)[source]¶
Initialize the distribution instance.
- Parameters:
path (
Path) – points to the distribution file itselftarget_dir (
Path) – points to the directory where we thaw the distributionpath_translator (
PathTranslator) – translates relative paths to the thaw directory
- 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 statetarget_dir (
Path) – where the distribution will be thawed
- Return type:
- classmethod from_struct(struct, target_dir)[source]¶
Return a distrbution directly from the data structure created from
Discoverer.- Parameters:
struct (
Dict[str,Any]) – the data structure given byDiscoverer.freeze()usingflatten=Truetarget_dir (
Path) – where the distribution will be thawed
- Return type:
- property repos: Iterable[FrozenRepo]¶
Repository specifications.
zensols.grsync.domain module¶
Domain and container classes, mostly modeling Git repos.
- class zensols.grsync.domain.FileEntry(dist, finfo)[source]¶
Bases:
objectRepresents a file based entry in the frozen version of the distribution zip.
- 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:
FileEntryRepresents a symbolic link in the frozen version of the distribution zip.
- property relative¶
Return the relative path of the file.
- property source¶
- property target¶
- class zensols.grsync.domain.PathTranslator(target_path)[source]¶
Bases:
objectUtility class around helping with paths.
- class zensols.grsync.domain.RemoteSpec(remote, is_master=None)[source]¶
Bases:
objectThis class represents a remote for a git repo.
- __init__(remote, is_master=None)[source]¶
Initialize.
- Parameters:
remote (
Remote) – a remote object from the git repois_master – whether or not the remote is the primary (upstream) remote
- property name¶
Return the remote’s name.
- class zensols.grsync.domain.SymbolicLink(source, path_translator)[source]¶
Bases:
objectThis classs represents a file system symbolic link. The class also freezes created symbol links.
- __init__(source, path_translator)[source]¶
Create.
- Parameters:
source (
Path) – thePaththat points to the symbolic link on the local file system.
- 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 module¶
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:
objectDiscover 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'¶
- TARG_LINKS = 'discover.target.links'¶
- 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).
- 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
Truethen 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
zensols.grsync.mover module¶
- class zensols.grsync.mover.DistributionMover(dist, target_dir=None, destination_dir=None, force_repo=False, force_dirs=False, dry_run=False)[source]¶
Bases:
objectThis 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 ziptarget_dir – the directory with the thawed files
destination_dir (
Path) – where the thawed files/repos will be movedforce_repo – if
Truemove repositories even if they’re dirtyforce_dirs – if
Truemove directories even if they’re not emptydry_run – don’t actually do anything, but log like we are
zensols.grsync.repospec module¶
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 keysname,urlandis_masterrepresenting a git repository remotelinks (
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 thawedpath_translator (
PathTranslator) – translates the distribution root
- class zensols.grsync.repospec.RepoSpec(path, path_translator, repo=None)[source]¶
Bases:
objectThis 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 rootrepo (
Repo) – the git repository to use in this instance, otherwise it will be created that points to what thepath_translatorresolves
- format(fmt=None, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Human readable format.
- property master_remote: str¶
Return the first (preferred) remote that is used as the master for pull, fetch and push.
- property remotes: List[RemoteSpec]¶
Return a list or remote specs used as the repo’s remotes.
- property repo: Repo¶
Return the Git repository instance.
zensols.grsync.thaw module¶
Contains utility classes used to thaw distributions.
- class zensols.grsync.thaw.ThawManager(dist, path_translator, app_version, dry_run=False)[source]¶
Bases:
object