How to use the gitman.common function in gitman

To help you get started, we’ve selected a few gitman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jacebrowning / gitman / gitman / commands.py View on Github external
def init():
    """Create a new config file for the project."""
    success = False

    config = load_config()

    if config:
        msg = "Configuration file already exists: {}".format(config.path)
        common.show(msg, color='error')

    else:
        config = Config()
        source = Source(
            type='git',
            name="sample_dependency",
            repo="https://github.com/githubtraining/hellogitworld",
        )
        config.sources.append(source)
        source = source.lock(rev="ebbbf773431ba07510251bb03f9525c7bab2b13a")
        config.sources_locked.append(source)
        config.datafile.save()

        msg = "Created sample config file: {}".format(config.path)
        common.show(msg, color='success')
        success = True
github jacebrowning / gitman / gitman / cli.py View on Github external
except exceptions.UncommittedChanges as exception:
        _show_error(exception)
        exit_message = (
            "Run again with --force/--force-interactive to discard changes "
            "or '--skip-changes' to skip this dependency"
        )
    except exceptions.ScriptFailure as exception:
        _show_error(exception)
        exit_message = "Run again with '--force' to ignore script errors"
    except exceptions.InvalidConfig as exception:
        _show_error(exception)
        exit_message = "Adapt config and run again"
    finally:
        if exit_message:
            common.show(exit_message, color='message')
            common.newline()

    if success:
        log.debug("Command succeeded")
    else:
        log.debug("Command failed")
        sys.exit(1)
github jacebrowning / gitman / gitman / models / config.py View on Github external
def get_top_level_dependencies(self):
        """Yield the path, repository, and hash of top-level dependencies."""
        if not os.path.exists(self.location_path):
            return

        shell.cd(self.location_path)
        common.newline()
        common.indent()

        for source in self.sources:

            yield os.path.join(self.location_path, source.name)

            shell.cd(self.location_path, _show=False)

        common.dedent()
github jacebrowning / gitman / gitman / cli.py View on Github external
'-q',
        '--quiet',
        action='store_const',
        const=-1,
        dest='verbose',
        help="only display errors and prompts",
    )
    project = argparse.ArgumentParser(add_help=False)
    project.add_argument(
        '-r', '--root', metavar='PATH', help="root directory of the project"
    )
    depth = argparse.ArgumentParser(add_help=False)
    depth.add_argument(
        '-d',
        '--depth',
        type=common.positive_int,
        default=5,
        metavar="NUM",
        help="limit the number of dependency levels",
    )
    options = argparse.ArgumentParser(add_help=False)
    options.add_argument(
        '-c',
        '--clean',
        action='store_true',
        help="delete ignored files in dependencies",
    )
    options_group = options.add_mutually_exclusive_group()
    options_group.add_argument(
        '-F',
        '--force',
        action='store_true',
github jacebrowning / gitman / gitman / models / config.py View on Github external
fetch=False,
        clean=True,
        skip_changes=False,
    ):  # pylint: disable=too-many-locals
        """Download or update the specified dependencies."""
        if depth == 0:
            log.info("Skipped directory: %s", self.location_path)
            return 0

        sources = self._get_sources(use_locked=False if update else None)
        sources_filter = self._get_sources_filter(*names, sources=sources)

        if not os.path.isdir(self.location_path):
            shell.mkdir(self.location_path)
        shell.cd(self.location_path)
        common.newline()
        common.indent()

        count = 0
        for source in sources:
            if source.name in sources_filter:
                sources_filter.remove(source.name)
            else:
                log.info("Skipped dependency: %s", source.name)
                continue

            source.update_files(
                force=force,
                force_interactive=force_interactive,
                fetch=fetch,
                clean=clean,
                skip_changes=skip_changes,
github jacebrowning / gitman / gitman / commands.py View on Github external
def _run_scripts(*names, depth=None, force=False, _config=None):
    """Run post-install scripts.

    Optional arguments:

    - `*names`: optional list of dependency directory names filter on
    - `depth`: number of levels of dependencies to traverse
    - `force`: indicates script errors can be ignored

    """
    assert _config, "'_config' is required"

    common.show("Running scripts...", color='message', log=False)
    common.newline()
    _config.run_scripts(*names, depth=depth, force=force)
github jacebrowning / gitman / gitman / models / source.py View on Github external
if git.changes(
                self.type,
                display_status=not allow_dirty and not skip_changes,
                _show=not skip_changes,
            ):

                if allow_dirty:
                    common.show(self.DIRTY, color='git_dirty', log=False)
                    common.newline()
                    return path, url, self.DIRTY

                if skip_changes:
                    msg = ("Skipped lock due to uncommitted changes " "in {}").format(
                        os.getcwd()
                    )
                    common.show(msg, color='git_changes')
                    common.newline()
                    return path, url, self.DIRTY

                msg = "Uncommitted changes in {}".format(os.getcwd())
                raise exceptions.UncommittedChanges(msg)

            rev = git.get_hash(self.type, _show=True)
            common.show(rev, color='git_rev', log=False)
            common.newline()
            return path, url, rev

        if allow_missing:
            return os.getcwd(), '', self.UNKNOWN

        raise self._invalid_repository