def globally_get_command_help(self, *args): sys_home_project_name = self.config.get('multiproject', 'sys_home_project_name') for env_name, in self.projects_iterator(['env_name'], batch_size=1): if env_name == sys_home_project_name: continue env = None try: env_path = safe_path(self.config.get('multiproject', 'sys_projects_root'), env_name) env = open_environment(env_path, True) except TracError as e: printout(_('ERROR: Opening environment %(env_name)s failed', env_name=env_name)) continue try: command_manager = AdminCommandManager(env) helps = command_manager.get_command_help(list(args)) if not args: TracAdmin.print_doc(helps, short=True) elif len(helps) == 1: TracAdmin.print_doc(helps, long=True) else: TracAdmin.print_doc(helps) except AdminCommandError as e: printout(_('ERROR: Getting command help in environment %(env_name)s failed: ', env_name=env_name) + e) break
def globally_execute_command(self, *args): offset = 0 max_index = -1 if args and args[0].isdigit(): offset = int(args[0]) if len(args) > 1 and args[1].isdigit(): limit = int(args[1]) max_index = limit + offset args = args[2:] else: args = args[1:] upgrade_check = False env_list = False if args and args[0] == 'upgrade-check': upgrade_check = True elif args and args[0] == 'list-env': env_list = True sys_home_project_name = self.config.get('multiproject', 'sys_home_project_name') for index, row in enumerate(self.projects_iterator(['env_name'], batch_size=10)): env_name, = row if index < offset: continue if max_index != -1 and index >= max_index: break if env_name == sys_home_project_name: continue if env_list: printout("{0:4} env:'{1}'".format(index, env_name)) continue env = None try: env_path = safe_path(self.config.get('multiproject', 'sys_projects_root'), env_name) env = Environment(env_path) except TracError as e: printout(_('ERROR: Opening environment %(env_name)s failed', env_name=env_name)) continue if upgrade_check: if env.needs_upgrade(): printout("[+] {0:4} env:'{1}'".format(index, env_name)) else: printout("[ ] {0:4} env:'{1}'".format(index, env_name)) continue # To setup MultiProject specific things like 'project_identifier' MultiProjectEnvironmentInit(env).environment_needs_upgrade(None) try: command_manager = AdminCommandManager(env) printout(_("{0:4} Run in env:'{1}'".format(index, env_name))) command_manager.execute_command(*args) except AdminCommandError as e: printout(_('ERROR: Executing command in environment %(env_name)s failed: ', env_name=env_name) + str(e))
def _process_repository(self, name): if not name: return rm = RepositoryManager(self.env) trac_repo = rm.get_repository(name) if not trac_repo or not hasattr(trac_repo, 'gitrepo'): return self.env.log.debug("GitHubSync: Processing repository at '%s'", trac_repo.gitrepo) lock_file = os.path.join(trac_repo.gitrepo, 'githubsync.lock') lock = open(lock_file, 'w') fcntl.lockf(lock, fcntl.LOCK_EX) try: self.env.log.debug("GitHubSync: Lock acquired") before_revisions = set(trac_repo.git.repo.rev_list('--branches', '--tags').splitlines()) # Pulling from default source (as configured in repo configuration) output = trac_repo.git.repo.fetch('--all', '--prune', '--tags') self.env.log.debug("GitHubSync: git output: %s", output) after_revisions = set(trac_repo.git.repo.rev_list('--branches', '--tags').splitlines()) finally: fcntl.lockf(lock, fcntl.LOCK_UN) lock.close() os.unlink(lock_file) self.env.log.debug("GitHubSync: Lock released") new_revisions = after_revisions - before_revisions if len(new_revisions) > 0: self.env.log.debug("GitHubSync: New revisions: %s", new_revisions) cmd_mgr = AdminCommandManager(self.env) cmd_mgr.execute_command('changeset', 'added', name, *new_revisions)