def fetch_autoname(app, tag): if not app["Repo Type"] or app['Update Check Mode'] in ('None', 'Static'): return None if app['Repo Type'] == 'srclib': app_dir = os.path.join('build', 'srclib', app['Repo']) else: app_dir = os.path.join('build/', app['id']) try: vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir) vcs.gotorevision(tag) except VCSException: return None flavour = None if len(app['builds']) > 0: if app['builds'][-1]['subdir']: app_dir = os.path.join(app_dir, app['builds'][-1]['subdir']) if app['builds'][-1]['gradle']: flavour = app['builds'][-1]['gradle'] if flavour == 'yes': flavour = None logging.debug("...fetch auto name from " + app_dir + ((" (flavour: %s)" % flavour) if flavour else "")) new_name = common.fetch_real_name(app_dir, flavour) commitmsg = None if new_name: logging.debug("...got autoname '" + new_name + "'") if new_name != app['Auto Name']: app['Auto Name'] = new_name if not commitmsg: commitmsg = "Set autoname of {0}".format( common.getappname(app)) else: logging.debug("...couldn't get autoname") if app['Current Version'].startswith('@string/'): cv = common.version_name(app['Current Version'], app_dir, flavour) if app['Current Version'] != cv: app['Current Version'] = cv if not commitmsg: commitmsg = "Fix CV of {0}".format(common.getappname(app)) return commitmsg
def fetch_autoname(app, tag): if not app["Repo Type"] or app['Update Check Mode'] in ('None', 'Static'): return None if app['Repo Type'] == 'srclib': app_dir = os.path.join('build', 'srclib', app['Repo']) else: app_dir = os.path.join('build/', app['id']) try: vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir) vcs.gotorevision(tag) except VCSException: return None flavours = [] if len(app['builds']) > 0: if app['builds'][-1]['subdir']: app_dir = os.path.join(app_dir, app['builds'][-1]['subdir']) if app['builds'][-1]['gradle']: flavours = app['builds'][-1]['gradle'] commitmsg = None if not app['Auto Name']: logging.debug("...fetch auto name from " + app_dir) new_name = common.fetch_real_name(app_dir, flavours) if new_name: logging.debug("...got autoname '" + new_name + "'") app['Auto Name'] = new_name if not commitmsg: commitmsg = "Set autoname of {0}".format(common.getappname(app)) else: logging.debug("...couldn't get autoname") if app['Current Version'].startswith('@string/'): cv = common.version_name(app['Current Version'], app_dir, flavours) if app['Current Version'] != cv: app['Current Version'] = cv if not commitmsg: commitmsg = "Fix CV of {0}".format(common.getappname(app)) return commitmsg
def main(): global config, options # Parse command line... parser = OptionParser() parser.add_option("-v", "--verbose", action="store_true", default=False, help="Spew out even more information than normal") parser.add_option("-p", "--package", default=None, help="Check only the specified package") parser.add_option("--auto", action="store_true", default=False, help="Process auto-updates") parser.add_option("--autoonly", action="store_true", default=False, help="Only process apps with auto-updates") parser.add_option("--commit", action="store_true", default=False, help="Commit changes") parser.add_option("--gplay", action="store_true", default=False, help="Only print differences with the Play Store") (options, args) = parser.parse_args() config = common.read_config(options) # Get all apps... apps = metadata.read_metadata(options.verbose) # Filter apps according to command-line options if options.package: apps = [app for app in apps if app['id'] == options.package] if len(apps) == 0: print "No such package" sys.exit(1) if options.gplay: for app in apps: version, reason = check_gplay(app) if version is None and options.verbose: if reason == '404': print "%s is not in the Play Store" % common.getappname(app) else: print "%s encountered a problem: %s" % common.getappname(app) if version is not None: stored = app['Current Version'] if LooseVersion(stored) < LooseVersion(version): print "%s has version %s on the Play Store, which is bigger than %s" % ( common.getappname(app), version, stored) elif options.verbose: print "%s has the same version %s on the Play Store" % ( common.getappname(app), version) return for app in apps: if options.autoonly and app['Auto Update Mode'] == 'None': if options.verbose: print "Nothing to do for %s..." % app['id'] continue print "Processing " + app['id'] + '...' writeit = False logmsg = None tag = None msg = None vercode = None mode = app['Update Check Mode'] if mode == 'Tags': (version, vercode, tag) = check_tags(app) elif mode == 'RepoManifest': (version, vercode) = check_repomanifest(app) elif mode.startswith('RepoManifest/'): tag = mode[13:] (version, vercode) = check_repomanifest(app, tag) elif mode == 'RepoTrunk': (version, vercode) = check_repotrunk(app) elif mode == 'HTTP': (version, vercode) = check_http(app) elif mode == 'Static': version = None msg = 'Checking disabled' elif mode == 'None': version = None msg = 'Checking disabled' else: version = None msg = 'Invalid update check method' if vercode and app['Vercode Operation']: op = app['Vercode Operation'].replace("%c", str(int(vercode))) vercode = str(eval(op)) updating = False if not version: print "...%s" % msg elif vercode == app['Current Version Code']: print "...up to date" else: app['Current Version'] = version app['Current Version Code'] = str(int(vercode)) updating = True writeit = True # Do the Auto Name thing as well as finding the CV real name if len(app["Repo Type"]) > 0: try: if app['Repo Type'] == 'srclib': app_dir = os.path.join('build', 'srclib', app['Repo']) else: app_dir = os.path.join('build/', app['id']) vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir) vcs.gotorevision(tag) flavour = None if len(app['builds']) > 0: if 'subdir' in app['builds'][-1]: app_dir = os.path.join(app_dir, app['builds'][-1]['subdir']) if 'gradle' in app['builds'][-1]: flavour = app['builds'][-1]['gradle'] new_name = common.fetch_real_name(app_dir, flavour) if new_name != app['Auto Name']: app['Auto Name'] = new_name if app['Current Version'].startswith('@string/'): cv = common.version_name(app['Current Version'], app_dir, flavour) if app['Current Version'] != cv: app['Current Version'] = cv writeit = True except Exception: print "ERROR: Auto Name or Current Version failed for %s due to exception: %s" % (app['id'], traceback.format_exc()) if updating: name = common.getappname(app) ver = common.getcvname(app) print '...updating to version %s' % ver logmsg = 'Update CV of %s to %s' % (name, ver) if options.auto: mode = app['Auto Update Mode'] if mode == 'None': pass elif mode.startswith('Version '): pattern = mode[8:] if pattern.startswith('+'): o = pattern.find(' ') suffix = pattern[1:o] pattern = pattern[o + 1:] else: suffix = '' gotcur = False latest = None for build in app['builds']: if build['vercode'] == app['Current Version Code']: gotcur = True if not latest or int(build['vercode']) > int(latest['vercode']): latest = build if not gotcur: newbuild = latest.copy() if 'origlines' in newbuild: del newbuild['origlines'] newbuild['vercode'] = app['Current Version Code'] newbuild['version'] = app['Current Version'] + suffix print "...auto-generating build for " + newbuild['version'] commit = pattern.replace('%v', newbuild['version']) commit = commit.replace('%c', newbuild['vercode']) newbuild['commit'] = commit app['builds'].append(newbuild) writeit = True name = common.getappname(app) ver = common.getcvname(app) logmsg = "Update %s to %s" % (name, ver) else: print 'Invalid auto update mode "' + mode + '"' if writeit: metafile = os.path.join('metadata', app['id'] + '.txt') metadata.write_metadata(metafile, app) if options.commit and logmsg: print "Commiting update for " + metafile gitcmd = ["git", "commit", "-m", logmsg] if 'auto_author' in config: gitcmd.extend(['--author', config['auto_author']]) gitcmd.extend(["--", metafile]) if subprocess.call(gitcmd) != 0: print "Git commit failed" sys.exit(1) print "Finished."