Example #1
0
    def print_version_information(self,
                                  version_check=True,
                                  version_cache=None):
        """Print out version information"""
        if version_check:
            latest_version = self.get_latest_version(version_cache)
        else:
            latest_version = Unknown()

        cprint.magenta_bold('Version:', lpad=2)
        cprint.white('Git:', lpad=4, rpad=8, end='')
        cprint.white(self.url)
        if isinstance(self.version, GitBranch):
            cprint.blue_bold('Branch: ', lpad=16, end='')
            cprint.yellow_bold(self.version.version, end='')
        elif isinstance(self.version, GitCommit):
            cprint.red('Commit: ', lpad=16, end='')
            cprint.red_bold(self.version.version[:7], end='')
        elif isinstance(self.version, GitRef):
            cprint.red('Ref: ', lpad=16, end='')
            cprint.red_bold(self.version.version, end='')
        elif isinstance(self.version, GitTag):
            cprint.blue_bold('Tag: ', lpad=16, end='')
            if latest_version.version == self.version.version:
                cprint.green_bold(self.version.version, end='')
            else:
                cprint.yellow_bold(self.version.version, end='')
        else:
            cprint.red_bold('UNSPECIFIED', lpad=16, end='')

        if version_check:
            cprint.white('[Latest: %s]' % (latest_version.report), lpad=1)
        else:
            cprint.white('')
Example #2
0
 def _bulk_update(environment, *, modules, cache):
     """updates modules in environment to latest version."""
     cprint.white_bold('Bulk update environment {}'.format(
         environment.name))
     for _, module in environment:
         if modules is not None:
             if modules[0] == '!':
                 if fnlistmatch(module.name, patterns=modules[1:]):
                     LOG.debug(
                         'module %s does match an exclude pattern %s. '
                         'Skipping.', module.name, modules[1:])
                     continue
             else:
                 if not fnlistmatch(module.name, patterns=modules):
                     LOG.debug(
                         'module %s does not match any include '
                         'pattern %s. Skipping.', module.name, modules)
                     continue
         try:
             cprint.white('Get latest version for module {}'.format(
                 module.name))
             module.version = module.get_latest_version(cache)
         except TypeError:
             LOG.debug(
                 'Could not determine latest module version for '
                 'module %s. Setting to None.', module.name)
             cprint.yellow_bold('Could not determine latest module version '
                                'for module {}!'.format(module.name))
             module.version = None
     return environment
Example #3
0
def main():
    """main entrypoint"""
    try:
        configuration = CrmngrConfig()
    except NoSectionError:
        print("No valid profile file found!")
        print("Enter git url of control repositoriy to create one.")
        print("Leave empty to abort")
        print()
        print("Control repository url: ", end="")
        default_profile_url = input().strip()
        if default_profile_url:
            configuration = CrmngrConfig.create_default_configuration(
                default_profile_url)
        else:
            sys.exit()

    cli_args = parse_cli_args(configuration)
    # now that the profile is known, reload the configuration using the
    # correct profile
    try:
        configuration = CrmngrConfig(profile=cli_args.profile)
    except NoSectionError:
        cprint.red('No configuration for profile {profile}'.format(
            profile=cli_args.profile))
        sys.exit(1)

    setup_logging(cli_args.debug)

    version_cache = JsonCache(configuration.cache_dir, ttl=cli_args.cache_ttl)

    commands = {
        'clean': command_clean,
        'create': command_create,
        'delete': command_delete,
        'environments': command_environments,
        'profiles': command_profiles,
        'report': command_report,
        'update': command_update,
    }
    try:
        commands[cli_args.command](configuration=configuration,
                                   cli_args=cli_args,
                                   version_cache=version_cache)
    except NoEnvironmentError:
        cprint.yellow_bold('no environment is affected by your command. typo?')
    except KeyboardInterrupt:
        cprint.red_bold('crmngr has been aborted.')
Example #4
0
    def report(self,
               wrap=True,
               version_check=True,
               version_cache=None,
               compare=True):
        """print control repository report"""

        for module, versions in sorted(self.modules.items()):

            # in compare mode, skip modules that are identical in all processed
            # environments.
            if compare and len(versions) == 1 and \
                            len(list(versions.values())[0]) == len(self._environments):
                continue

            cprint.white_bold('Module: %s' % module)
            for version, environments in natsorted(versions.items(),
                                                   reverse=True,
                                                   key=str):
                version.print_version_information(version_check, version_cache)
                if len(self._environments) > 1:
                    cprint.white('Used by:', lpad=4, rpad=4, end='')
                    if wrap:
                        used_by = TextWrapper(subsequent_indent=' ' * 16)
                        for line in used_by.wrap(' '.join(
                                sorted(environments))):
                            cprint.cyan(line)
                    else:
                        cprint.cyan(' '.join(sorted(environments)))
                print()

            if compare:
                # check for modules that are in not in all (but in at least one)
                # processed environments
                missing = set.union(*list(versions.values())) ^ set(
                    [environment.name for environment in self._environments])
                if missing:
                    cprint.yellow_bold('Missing from:', lpad=2)
                    if wrap:
                        not_in = TextWrapper(initial_indent=' ' * 16,
                                             subsequent_indent=' ' * 16)
                        for line in not_in.wrap(' '.join(sorted(missing))):
                            cprint.yellow(line)
                    else:
                        print(' ' * 16, end='')
                        cprint.yellow(' '.join(sorted(missing)))
                    print()
Example #5
0
def command_report(*, configuration, cli_args, version_cache, **kwargs):  # pylint: disable=unused-argument
    """run report command"""
    control_repo = ControlRepository(
        clone_url=configuration.control_repo_url,
        environments=cli_args.environments,
        modules=cli_args.modules,
    )

    if cli_args.compare and not len(control_repo.environments) >= 2:
        cprint.yellow_bold(
            'At least two environments required in compare mode. Only matched '
            'environment: {}'.format(', '.join([
                environment.name for environment in control_repo.environments
            ])))
        sys.exit(1)

    control_repo.report(
        compare=cli_args.compare,
        version_cache=version_cache,
        version_check=cli_args.version_check,
        wrap=cli_args.wrap,
    )
Example #6
0
    def print_version_information(self,
                                  version_check=True,
                                  version_cache=None):
        """Print out version information"""
        if version_check:
            latest_version = self.get_latest_version(version_cache)
        else:
            latest_version = Unknown()

        cprint.magenta_bold('Version:', lpad=2)
        cprint.white('Forge:', lpad=4, rpad=6, end='')
        cprint.white(self.forgename, suffix=':')
        if not self.version:
            cprint.red_bold('UNSPECIFIED', lpad=16, end='')
        else:
            if latest_version.version == self.version.version:
                cprint.green_bold(self.version.version, lpad=16, end='')
            else:
                cprint.yellow_bold(self.version.version, lpad=16, end='')

        if version_check:
            cprint.white(' [Latest: %s]' % latest_version.report)
        else:
            cprint.white('')