Esempio n. 1
0
def save_files_copied(files_copied, save_filename, strip_prefix=' '):
    """
    Given a dict of files that have been copied in the form {dst: src}, write a list of all files
    and their sources to the file. Optionally, a common prefix can be removed from the dst files.
    """
    printfmt = '{:<80}  <- {}\n'
    src_key = '  <source file> (preceding * indicates file is modified in git without a commit)'
    separator = '-' * (85 + len(src_key)) + '\n'
    filetext = separator
    filetext += 'Source version info:  repo [{}] - branch [{}] - commit hash [{}]\n\n'.format(
               git.get_repo(), git.get_branch(), git.get_hash())
    filetext += printfmt.format('<staged file>', src_key)
    filetext += separator
    for staged_file, source_file in files_copied.items():
        if staged_file.startswith(strip_prefix):
            staged_file = staged_file[len(strip_prefix):]
        filetext += printfmt.format(staged_file, source_file)
    save_text_to_file(filetext, save_filename)
Esempio n. 2
0
def exportGitInfoEnvVars():
    """
    Export git-related environment variables to the current environment so they may be used later
    for variable replacements.
    Variables set:
     - GIT_REPO - current repo
     - GIT_COMMIT - current commit hash
     - GIT_BRANCH - current branch
     - GIT_CLEAN - "False" if there are uncommitted changes in branch, "True" otherwise
    """
    # Exporting git information as variables
    GIT_REPO = git.get_repo()
    os.environ['GIT_REPO'] = GIT_REPO
    GIT_COMMIT = git.get_hash()
    os.environ['GIT_COMMIT'] = GIT_COMMIT
    GIT_BRANCH = git.get_branch()
    os.environ['GIT_BRANCH'] = GIT_BRANCH
    GIT_CLEAN = not git.branch_is_dirty()
    os.environ['GIT_CLEAN'] = "{}".format(GIT_CLEAN)
Esempio n. 3
0
def save_files_copied(files_copied, save_filename, strip_prefix=' '):
    """
    Given a dict of files that have been copied in the form {dst: src}, write a list of all files
    and their sources to the file. Optionally, a common prefix can be removed from the dst files.
    """
    printfmt = '{:<80}  <- {}\n'
    src_key = '  <source file> (preceding * indicates file is modified in git without a commit)'
    separator = '-' * (85 + len(src_key)) + '\n'
    filetext = separator
    filetext += 'Source version info:  repo [{}] - branch [{}] - commit hash [{}]\n\n'.format(
        git.get_repo(), git.get_branch(), git.get_hash())
    filetext += printfmt.format('<staged file>', src_key)
    filetext += separator
    staged_paths = sorted(list(files_copied.keys()))
    for staged_path in staged_paths:
        staged_file = staged_path
        if staged_file.startswith(strip_prefix):
            staged_file = staged_file[len(strip_prefix):]
        filetext += printfmt.format(staged_file, files_copied[staged_path])
    save_text_to_file(filetext, save_filename)