def _checkout_branch(self, repo): """Checkout the proper branch in repo""" current_dir = os.getcwd() try: os.chdir(repo) except OSError as e: logger.error('OSError: %s', e.strerror) return command.run('git checkout -qf %s' % self.xbmc_branch) os.chdir(current_dir)
def do_pr(addon_id, addon_version, url, revision, xbmc_branch, pull_type, git_parent_dir, tmp_dir, force=False): logger.info('Processing %s (%s) pull request for %s...', addon_id, addon_version, xbmc_branch) # Pull the addon in a temporary directory os.chdir(tmp_dir) try: getattr(command, pull_type + '_pull')(addon_id, url, revision) except AttributeError: logger.error('Unknown pull request type: %s. Aborting.', pull_type) return # Check the addon try: addon_check = addonparser.AddonCheck(addon_id, xbmc_branch, addon_id, addon_version, git_parent_dir) except Exception as e: logger.error(e) logger.error("Aborting.") return else: (warnings, errors) = addon_check.run() if errors > 0: if force: logger.warning("Error(s) detected. Processing anyway (force=True).") else: shutil.rmtree(addon_id, ignore_errors=True) logger.error("Error(s) detected. Aborting.") return addon = addon_check.addon addon_path = addon_check.addon_path if git_parent_dir is None: logger.error('Git parent dir not set. Aborting.') return git_dir = os.path.join(git_parent_dir, addon.addon_type + 's') try: os.chdir(git_dir) except OSError as e: logger.error('OSError: %s', e.strerror) return command.run('git checkout -qf %s' % xbmc_branch) if os.path.isdir(addon_id): command.run('git rm -rfq %s' % addon_id) # Directory might still exist due to files in .gitignore shutil.rmtree(addon_id, ignore_errors=True) if addon.is_broken(): msg = '[%s] marked as broken' % addon_id else: msg = '[%s] updated to version %s' % (addon_id, addon_version) else: msg = '[%s] initial version (%s) thanks to %s' % (addon_id, addon_version, addon.provider) shutil.move(os.path.join(tmp_dir, addon_path), addon_id) command.run('git add %s' % addon_id) command.run('git commit -m "%s"' % msg)
def clean_repo(conf, xbmc_branch, addon_type): config = ConfigParser.ConfigParser() config.read(os.path.expanduser(conf)) try: git_parent_dir = config.get('git', 'parent_dir') except ConfigParser.NoSectionError: logger.warning('No git parent_dir defined. Using "."') repo = "." else: repo = os.path.join(git_parent_dir, addon_type) os.chdir(repo) command.run('git checkout -qf %s' % xbmc_branch) for addon_path in os.listdir("."): if addon_path.startswith("."): continue addon = addonparser.Addon(addon_path) if addon.is_broken(): logging.debug("{} is broken".format(addon.addon_id)) if addon.is_last_commit_older_than(days=182): logging.info("Removing {} (broken for more than 6 months)".format(addon.addon_id)) command.run('git rm -rf {}'.format(addon.addon_id)) msg = '[%s] removed (broken for more than 6 months)' % addon.addon_id command.run('git commit -m "%s"' % msg)
def last_commit_date(self): """Return the last commit date""" timestamp = command.run( 'git log -n1 --format="%ct" {}'.format( os.path.join(self.addon_id, 'addon.xml'))) return datetime.fromtimestamp(float(timestamp))