def _after_lock_release(self):
        announce = 'Pruned MediaWiki: %s' % self.arguments.branch
        if not self.arguments.delete:
            announce += ' [keeping static files]'

        self.announce(announce + ' (duration: %s)' %
                      utils.human_duration(self.get_duration()))
Example #2
0
File: cli.py Project: saloniig/scap
    def handle_keyboard_interrupt(self):
        """
        Handle ctrl-c from interactive user.

        :returns: exit status
        """
        self.announce('{} aborted: {} (duration: {})'.format(
            self.program_name, self.arguments.message,
            utils.human_duration(self.get_duration())))
        return 130
Example #3
0
    def handle_keyboard_interrupt(self):
        """
        Handle ctrl-c from interactive user.

        :returns: exit status
        """
        self.announce('{} aborted: {} (duration: {})'.format(
                      self.program_name,
                      self.arguments.message,
                      utils.human_duration(self.get_duration())))
        return 130
Example #4
0
    def main(self, *extra_args):
        logger = self.get_logger()

        if self.arguments.message == '(no justification provided)':
            logger.fatal('Cannot lock repositories without a reason')
            return 1

        if self.arguments.all:
            lock_path = lock.GLOBAL_LOCK_FILE
            repo = 'ALL REPOSITORIES'
        else:
            lock_path = self.get_lock_file()
            repo = self.config['git_repo']

        got_lock = False
        with lock.Lock(lock_path, self.arguments.message, group_write=True):
            got_lock = True
            self.announce(
                'Locking from deployment [%s]: %s (planned duration: %s)',
                repo, self.arguments.message,
                utils.human_duration(self.arguments.time))

            logger.info('Press enter to abort early...')
            try:
                rlist, _, _ = select.select([sys.stdin], [], [],
                                            self.arguments.time)
                if rlist:
                    sys.stdin.readline()
            except KeyboardInterrupt:
                pass  # We don't care here

        if got_lock:
            self.announce(
                'Unlocked for deployment [%s]: %s (duration: %s)', repo,
                self.arguments.message,
                utils.human_duration(self.get_duration()))

        return 0
Example #5
0
File: log.py Project: saloniig/scap
    def _record_elapsed(self, label, elapsed):
        """
        Log the elapsed duration.

        :param label: Label for elapsed time
        :type label: str
        :param elapsed: Elapsed duration
        :type elapsed: float
        """
        self.logger.info('Finished %s (duration: %s)', label,
                         utils.human_duration(elapsed))
        if self.stats:
            label = re.sub(r'\W', '_', label.lower())
            self.stats.timing('scap.%s' % label, elapsed * 1000)
Example #6
0
    def _record_elapsed(self, label, elapsed):
        """
        Log the elapsed duration.

        :param label: Label for elapsed time
        :type label: str
        :param elapsed: Elapsed duration
        :type elapsed: float
        """
        self.logger.info('Finished %s (duration: %s)',
                         label, utils.human_duration(elapsed))
        if self.stats:
            label = re.sub(r'\W', '_', label.lower())
            self.stats.timing('scap.%s' % label, elapsed * 1000)
Example #7
0
    def main(self, *extra_args):
        logger = self.get_logger()

        if self.arguments.message == '(no justification provided)':
            logger.fatal('Cannot lock repositories without a reason')
            return 1

        if self.arguments.all:
            lock_path = lock.GLOBAL_LOCK_FILE
            repo = 'ALL REPOSITORIES'
        else:
            lock_path = self.get_lock_file()
            repo = self.config['git_repo']

        got_lock = False
        with lock.Lock(lock_path, self.arguments.message, group_write=True):
            got_lock = True
            self.announce(
                'Locking from deployment [%s]: %s (planned duration: %s)',
                repo, self.arguments.message,
                utils.human_duration(self.arguments.time))

            logger.info('Press enter to abort early...')
            try:
                rlist, _, _ = select.select([sys.stdin], [], [],
                                            self.arguments.time)
                if rlist:
                    sys.stdin.readline()
            except KeyboardInterrupt:
                pass  # We don't care here

        if got_lock:
            self.announce('Unlocked for deployment [%s]: %s (duration: %s)',
                          repo, self.arguments.message,
                          utils.human_duration(self.get_duration()))

        return 0
 def _after_lock_release(self):
     self.announce(self.arguments.message + ' (duration: %s)' %
                   utils.human_duration(self.get_duration()))
Example #9
0
    def main(self, *extra_args):
        logger = self.get_logger()

        self.repo = self.config['git_repo']

        if self.arguments.stages:
            stages = self.arguments.stages.split(',')
        else:
            stages = STAGES

        if self.arguments.service_restart:
            stages = [RESTART]
            if not self.config.get('service_name'):
                raise RuntimeError(
                    '--service-restart flag requires a `service_name` in '
                    'the config'
                )

        if self.arguments.dry_run:
            stages = ['config_diff']

        restart_only = False
        if len(stages) == 1 and stages[0] == RESTART:
            restart_only = True

        if not git.is_dir(self.context.root):
            raise RuntimeError(errno.EPERM, 'Script must be run from git repo')

        self._build_deploy_groups()

        if not self.all_targets:
            logger.warning('No targets selected, check limits and dsh_targets')
            return 1

        short_sha1 = git.info(self.context.root)['headSHA1'][:7]
        if not short_sha1:
            short_sha1 = 'UNKNOWN'

        deploy_name = 'deploy'

        if self.arguments.init:
            deploy_name = 'setup'
        elif restart_only:
            deploy_name = 'restart'

        display_name = '{} [{}@{}]'.format(deploy_name, self.repo, short_sha1)

        environment_name = self.config['environment']

        if environment_name is not None:
            display_name = '{} ({})'.format(display_name, environment_name)

        rev = self.arguments.rev

        # No revision passed on the command line, let's check the config
        if not rev:
            rev = self.config.get('git_rev')
            if rev:
                use_upstream = self.config.get(
                    'git_upstream_submodules', False)
                if rev.startswith('origin/') and not use_upstream:
                    logger.warning('You have set `git_rev` to "%s" without ' +
                                   'setting `git_upstream_submodules=True`. ' +
                                   'This could lead to unexpected behavior.',
                                   rev)

        # No revision from the config or cli
        # AND we're not running a stage that we want to deploy new code
        if not rev and not self._needs_latest_sha1(stages):
            last_deploy_tag = git.last_deploy_tag(self.context.root)
            if last_deploy_tag is not None:
                # This is what we want to pass to rev-parse to get the sha1 of
                # the annotated commit, rather than the sha1 of the annotation.
                rev = '%s^{}' % last_deploy_tag

        # We must be trying to deploy the latest and greatest
        if not rev:
            rev = 'HEAD'

        with lock.Lock(self.get_lock_file(), self.arguments.message):
            with log.Timer(display_name):
                timestamp = datetime.utcnow()
                tag = git.next_deploy_tag(location=self.context.root)
                commit = git.sha(location=self.context.root, rev=rev)
                logger.info('Deploying Rev: {} = {}'.format(rev, commit))

                self.config_deploy_setup(commit)
                self.checks_setup()
                self.config['git_rev'] = commit

                self.deploy_info.update({
                    'tag': tag,
                    'commit': commit,
                    'user': utils.get_username(),
                    'timestamp': timestamp.isoformat(),
                })

                # Handle JSON output from deploy-local
                self.deploy_info['log_json'] = True

                self.get_logger().debug('Update DEPLOY_HEAD')

                self.deploy_info.update({
                    key: self.config.get(key)
                    for key in self.DEPLOY_CONF
                    if self.config.get(key) is not None
                })

                git.update_deploy_head(self.deploy_info, self.context.root)

                git.tag_repo(self.deploy_info, location=self.context.root)

                # Remove old tags
                git.clean_tags(self.context.root, self.config['tags_to_keep'])

                # Run git update-server-info because git repo is a dumb
                # apache server
                git.update_server_info(self.config['git_submodules'])

                if self.arguments.init:
                    return 0

                self.announce('Started %s: %s', display_name,
                              self.arguments.message)
                exec_result = self._execute_for_groups(stages)
                if not restart_only:
                    self.announce('Finished %s: %s (duration: %s)',
                                  display_name, self.arguments.message,
                                  utils.human_duration(self.get_duration()))
                return exec_result
        return 0
Example #10
0
 def _after_lock_release(self):
     self.announce(
         'scap sync-l10n completed (%s) (duration: %s)',
         self.arguments.version, utils.human_duration(self.get_duration()))
     self.increment_stat('l10nupdate-sync')
Example #11
0
 def _after_lock_release(self):
     self.announce(
         'Synchronized %s: %s (duration: %s)',
         self.arguments.file, self.arguments.message,
         utils.human_duration(self.get_duration()))
     self.increment_stat('sync-file')
Example #12
0
 def _handle_exception(self, ex):
     self.get_logger().warning('Unhandled error:', exc_info=True)
     self.announce(
         'scap failed: %s %s (duration: %s)',
         type(ex).__name__, ex, utils.human_duration(self.get_duration()))
     return 1
Example #13
0
 def _after_lock_release(self):
     self.announce('Finished scap: %s (duration: %s)',
                   self.arguments.message,
                   utils.human_duration(self.get_duration()))
     self.increment_stat('scap')
Example #14
0
 def _after_lock_release(self):
     self.announce('scap sync-l10n completed (%s) (duration: %s)',
                   self.arguments.version,
                   utils.human_duration(self.get_duration()))
     self.increment_stat('l10nupdate-sync')
Example #15
0
 def _after_lock_release(self):
     self.announce('Synchronized %s: %s (duration: %s)',
                   self.arguments.file, self.arguments.message,
                   utils.human_duration(self.get_duration()))
     self.increment_stat('sync-file')
Example #16
0
 def _handle_exception(self, ex):
     self.get_logger().warning('Unhandled error:', exc_info=True)
     self.announce('scap failed: %s %s (duration: %s)',
                   type(ex).__name__, ex,
                   utils.human_duration(self.get_duration()))
     return 1
Example #17
0
    def main(self, *extra_args):
        logger = self.get_logger()

        self.repo = self.config['git_repo']

        if self.arguments.stages:
            stages = self.arguments.stages.split(',')
        else:
            stages = STAGES

        if self.arguments.service_restart:
            stages = [RESTART]
            if not self.config.get('service_name'):
                raise RuntimeError(
                    '--service-restart flag requires a `service_name` in '
                    'the config')

        if self.arguments.dry_run:
            stages = ['config_diff']

        restart_only = False
        if len(stages) == 1 and stages[0] == RESTART:
            restart_only = True

        if not git.is_dir(self.context.root):
            raise RuntimeError(errno.EPERM, 'Script must be run from git repo')

        self._build_deploy_groups()

        if not self.all_targets:
            logger.warning('No targets selected, check limits and dsh_targets')
            return 1

        short_sha1 = git.info(self.context.root)['headSHA1'][:7]
        if not short_sha1:
            short_sha1 = 'UNKNOWN'

        deploy_name = 'deploy'

        if self.arguments.init:
            deploy_name = 'setup'
        elif restart_only:
            deploy_name = 'restart'

        display_name = '{} [{}@{}]'.format(deploy_name, self.repo, short_sha1)

        environment_name = self.config['environment']

        if environment_name is not None:
            display_name = '{} ({})'.format(display_name, environment_name)

        rev = self.arguments.rev

        # No revision passed on the command line, let's check the config
        if not rev:
            rev = self.config.get('git_rev')
            if rev:
                use_upstream = self.config.get('git_upstream_submodules',
                                               False)
                if rev.startswith('origin/') and not use_upstream:
                    logger.warning(
                        'You have set `git_rev` to "%s" without ' +
                        'setting `git_upstream_submodules=True`. ' +
                        'This could lead to unexpected behavior.', rev)

        # No revision from the config or cli
        # AND we're not running a stage that we want to deploy new code
        if not rev and not self._needs_latest_sha1(stages):
            last_deploy_tag = git.last_deploy_tag(self.context.root)
            if last_deploy_tag is not None:
                # This is what we want to pass to rev-parse to get the sha1 of
                # the annotated commit, rather than the sha1 of the annotation.
                rev = '%s^{}' % last_deploy_tag

        # We must be trying to deploy the latest and greatest
        if not rev:
            rev = 'HEAD'

        with lock.Lock(self.get_lock_file(), self.arguments.message):
            with log.Timer(display_name):
                timestamp = datetime.utcnow()
                tag = git.next_deploy_tag(location=self.context.root)
                commit = git.sha(location=self.context.root, rev=rev)
                logger.info('Deploying Rev: {} = {}'.format(rev, commit))

                self.config_deploy_setup(commit)
                self.checks_setup()
                self.config['git_rev'] = commit

                self.deploy_info.update({
                    'tag': tag,
                    'commit': commit,
                    'user': utils.get_username(),
                    'timestamp': timestamp.isoformat(),
                })

                # Handle JSON output from deploy-local
                self.deploy_info['log_json'] = True

                self.get_logger().debug('Update DEPLOY_HEAD')

                self.deploy_info.update({
                    key: self.config.get(key)
                    for key in self.DEPLOY_CONF
                    if self.config.get(key) is not None
                })

                git.update_deploy_head(self.deploy_info, self.context.root)

                git.tag_repo(self.deploy_info, location=self.context.root)

                # Remove old tags
                git.clean_tags(self.context.root, self.config['tags_to_keep'])

                # Run git update-server-info because git repo is a dumb
                # apache server
                git.update_server_info(self.config['git_submodules'])

                if self.arguments.init:
                    return 0

                self.announce('Started %s: %s', display_name,
                              self.arguments.message)
                exec_result = self._execute_for_groups(stages)
                if not restart_only:
                    self.announce('Finished %s: %s (duration: %s)',
                                  display_name, self.arguments.message,
                                  utils.human_duration(self.get_duration()))
                return exec_result
        return 0
Example #18
0
 def _after_lock_release(self):
     self.announce(
         'Finished scap: %s (duration: %s)',
         self.arguments.message, utils.human_duration(self.get_duration()))
     self.increment_stat('scap')