Exemplo n.º 1
0
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
Exemplo n.º 3
0
def fetch_autoname(app, tag):

    if not app.RepoType or app.UpdateCheckMode in ('None', 'Static'):
        return None

    if app.RepoType == 'srclib':
        build_dir = os.path.join('build', 'srclib', app.Repo)
    else:
        build_dir = os.path.join('build', app.id)

    try:
        vcs = common.getvcs(app.RepoType, app.Repo, build_dir)
        vcs.gotorevision(tag)
    except VCSException:
        return None

    last_build = metadata.Build()
    if len(app.builds) > 0:
        last_build = app.builds[-1]

    logging.debug("...fetch auto name from " + build_dir)
    new_name = None
    for subdir in possible_subdirs(app):
        if subdir == '.':
            root_dir = build_dir
        else:
            root_dir = os.path.join(build_dir, subdir)
        new_name = common.fetch_real_name(root_dir, last_build.gradle)
        if new_name is not None:
            break
    commitmsg = None
    if new_name:
        logging.debug("...got autoname '" + new_name + "'")
        if new_name != app.AutoName:
            app.AutoName = new_name
            if not commitmsg:
                commitmsg = "Set autoname of {0}".format(common.getappname(app))
    else:
        logging.debug("...couldn't get autoname")

    return commitmsg
Exemplo n.º 4
0
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']

    logging.debug("...fetch auto name from " + app_dir)
    new_name = common.fetch_real_name(app_dir, flavours)
    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")

    return commitmsg
Exemplo n.º 5
0
def main():

    global config, options

    # Parse command line...
    parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
    common.setup_global_opts(parser)
    parser.add_argument("appid", nargs='*', help="app-id to check for updates")
    parser.add_argument("--auto", action="store_true", default=False,
                        help="Process auto-updates")
    parser.add_argument("--autoonly", action="store_true", default=False,
                        help="Only process apps with auto-updates")
    parser.add_argument("--commit", action="store_true", default=False,
                        help="Commit changes")
    parser.add_argument("--gplay", action="store_true", default=False,
                        help="Only print differences with the Play Store")
    options = parser.parse_args()

    config = common.read_config(options)

    # Get all apps...
    allapps = metadata.read_metadata()

    apps = common.read_app_args(options.appid, allapps, False)

    if options.gplay:
        for app in apps:
            version, reason = check_gplay(app)
            if version is None:
                if reason == '404':
                    logging.info("{0} is not in the Play Store".format(common.getappname(app)))
                else:
                    logging.info("{0} encountered a problem: {1}".format(common.getappname(app), reason))
            if version is not None:
                stored = app.CurrentVersion
                if not stored:
                    logging.info("{0} has no Current Version but has version {1} on the Play Store"
                                 .format(common.getappname(app), version))
                elif LooseVersion(stored) < LooseVersion(version):
                    logging.info("{0} has version {1} on the Play Store, which is bigger than {2}"
                                 .format(common.getappname(app), version, stored))
                else:
                    if stored != version:
                        logging.info("{0} has version {1} on the Play Store, which differs from {2}"
                                     .format(common.getappname(app), version, stored))
                    else:
                        logging.info("{0} has the same version {1} on the Play Store"
                                     .format(common.getappname(app), version))
        return

    for appid, app in apps.iteritems():

        if options.autoonly and app.AutoUpdateMode in ('None', 'Static'):
            logging.debug("Nothing to do for {0}...".format(appid))
            continue

        logging.info("Processing " + appid + '...')

        checkupdates_app(app)

    logging.info("Finished.")
Exemplo n.º 6
0
def checkupdates_app(app, first=True):

    # If a change is made, commitmsg should be set to a description of it.
    # Only if this is set will changes be written back to the metadata.
    commitmsg = None

    tag = None
    msg = None
    vercode = None
    noverok = False
    mode = app.UpdateCheckMode
    if mode.startswith('Tags'):
        pattern = mode[5:] if len(mode) > 4 else None
        (version, vercode, tag) = check_tags(app, pattern)
        msg = vercode
    elif mode == 'RepoManifest':
        (version, vercode) = check_repomanifest(app)
        msg = vercode
    elif mode.startswith('RepoManifest/'):
        tag = mode[13:]
        (version, vercode) = check_repomanifest(app, tag)
        msg = vercode
    elif mode == 'RepoTrunk':
        (version, vercode) = check_repotrunk(app)
        msg = vercode
    elif mode == 'HTTP':
        (version, vercode) = check_http(app)
        msg = vercode
    elif mode in ('None', 'Static'):
        version = None
        msg = 'Checking disabled'
        noverok = True
    else:
        version = None
        msg = 'Invalid update check method'

    if version and vercode and app.VercodeOperation:
        oldvercode = str(int(vercode))
        op = app.VercodeOperation.replace("%c", oldvercode)
        vercode = str(eval(op))
        logging.debug("Applied vercode operation: %s -> %s" % (oldvercode, vercode))

    if version and any(version.startswith(s) for s in [
            '${',  # Gradle variable names
            '@string/',  # Strings we could not resolve
            ]):
        version = "Unknown"

    updating = False
    if version is None:
        logmsg = "...{0} : {1}".format(app.id, msg)
        if noverok:
            logging.info(logmsg)
        else:
            logging.warn(logmsg)
    elif vercode == app.CurrentVersionCode:
        logging.info("...up to date")
    else:
        app.CurrentVersion = version
        app.CurrentVersionCode = str(int(vercode))
        updating = True

    commitmsg = fetch_autoname(app, tag)

    if updating:
        name = common.getappname(app)
        ver = common.getcvname(app)
        logging.info('...updating to version %s' % ver)
        commitmsg = 'Update CV of %s to %s' % (name, ver)

    if options.auto:
        mode = app.AutoUpdateMode
        if mode in ('None', 'Static'):
            pass
        elif mode.startswith('Version '):
            pattern = mode[8:]
            if pattern.startswith('+'):
                try:
                    suffix, pattern = pattern.split(' ', 1)
                except ValueError:
                    raise MetaDataException("Invalid AUM: " + mode)
            else:
                suffix = ''
            gotcur = False
            latest = None
            for build in app.builds:
                if int(build.vercode) >= int(app.CurrentVersionCode):
                    gotcur = True
                if not latest or int(build.vercode) > int(latest.vercode):
                    latest = build

            if int(latest.vercode) > int(app.CurrentVersionCode):
                logging.info("Refusing to auto update, since the latest build is newer")

            if not gotcur:
                newbuild = copy.deepcopy(latest)
                newbuild.disable = False
                newbuild.vercode = app.CurrentVersionCode
                newbuild.version = app.CurrentVersion + suffix
                logging.info("...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)
                name = common.getappname(app)
                ver = common.getcvname(app)
                commitmsg = "Update %s to %s" % (name, ver)
        else:
            logging.warn('Invalid auto update mode "' + mode + '" on ' + app.id)

    if commitmsg:
        metadatapath = os.path.join('metadata', app.id + '.txt')
        with open(metadatapath, 'w') as f:
            metadata.write_metadata('txt', f, app)
        if options.commit:
            logging.info("Commiting update for " + metadatapath)
            gitcmd = ["git", "commit", "-m", commitmsg]
            if 'auto_author' in config:
                gitcmd.extend(['--author', config['auto_author']])
            gitcmd.extend(["--", metadatapath])
            if subprocess.call(gitcmd) != 0:
                logging.error("Git commit failed")
                sys.exit(1)
def main():

    global config, options

    # Parse command line...
    parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
    parser.add_option("-v", "--verbose", action="store_true", default=False,
                      help="Spew out even more information than normal")
    parser.add_option("-q", "--quiet", action="store_true", default=False,
                      help="Restrict output to warnings and errors")
    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...
    allapps = metadata.read_metadata()

    apps = common.read_app_args(args, allapps, False)

    if options.gplay:
        for app in apps:
            version, reason = check_gplay(app)
            if version is None:
                if reason == '404':
                    logging.info("{0} is not in the Play Store".format(common.getappname(app)))
                else:
                    logging.info("{0} encountered a problem: {1}".format(common.getappname(app), reason))
            if version is not None:
                stored = app['Current Version']
                if not stored:
                    logging.info("{0} has no Current Version but has version {1} on the Play Store"
                                 .format(common.getappname(app), version))
                elif LooseVersion(stored) < LooseVersion(version):
                    logging.info("{0} has version {1} on the Play Store, which is bigger than {2}"
                                 .format(common.getappname(app), version, stored))
                else:
                    if stored != version:
                        logging.info("{0} has version {1} on the Play Store, which differs from {2}"
                                     .format(common.getappname(app), version, stored))
                    else:
                        logging.info("{0} has the same version {1} on the Play Store"
                                     .format(common.getappname(app), version))
        return

    for appid, app in apps.iteritems():

        if options.autoonly and app['Auto Update Mode'] in ('None', 'Static'):
            logging.debug("Nothing to do for {0}...".format(appid))
            continue

        logging.info("Processing " + appid + '...')

        checkupdates_app(app)

    logging.info("Finished.")
def checkupdates_app(app, first=True):

    # If a change is made, commitmsg should be set to a description of it.
    # Only if this is set will changes be written back to the metadata.
    commitmsg = None

    tag = None
    msg = None
    vercode = None
    noverok = False
    mode = app['Update Check Mode']
    if mode.startswith('Tags'):
        pattern = mode[5:] if len(mode) > 4 else None
        (version, vercode, tag) = check_tags(app, pattern)
        msg = vercode
    elif mode == 'RepoManifest':
        (version, vercode) = check_repomanifest(app)
        msg = vercode
    elif mode.startswith('RepoManifest/'):
        tag = mode[13:]
        (version, vercode) = check_repomanifest(app, tag)
        msg = vercode
    elif mode == 'RepoTrunk':
        (version, vercode) = check_repotrunk(app)
        msg = vercode
    elif mode == 'HTTP':
        (version, vercode) = check_http(app)
        msg = vercode
    elif mode in ('None', 'Static'):
        version = None
        msg = 'Checking disabled'
        noverok = True
    else:
        version = None
        msg = 'Invalid update check method'

    if first and version is None and vercode == "Couldn't find package ID":
        logging.warn("Couldn't find any version information. Looking for a subdir change...")
        new_subdir = check_changed_subdir(app)
        if new_subdir is None:
            logging.warn("Couldn't find any new subdir.")
        else:
            logging.warn("Trying a new subdir: %s" % new_subdir)
            new_build = {}
            metadata.fill_build_defaults(new_build)
            new_build['version'] = "Ignore"
            new_build['vercode'] = "-1"
            new_build['subdir'] = new_subdir
            app['builds'].append(new_build)
            return checkupdates_app(app, first=False)

    if version and vercode and app['Vercode Operation']:
        op = app['Vercode Operation'].replace("%c", str(int(vercode)))
        vercode = str(eval(op))

    updating = False
    if version is None:
        logmsg = "...{0} : {1}".format(app['id'], msg)
        if noverok:
            logging.info(logmsg)
        else:
            logging.warn(logmsg)
    elif vercode == app['Current Version Code']:
        logging.info("...up to date")
    else:
        app['Current Version'] = version
        app['Current Version Code'] = str(int(vercode))
        updating = True

    commitmsg = fetch_autoname(app, tag)

    if updating:
        name = common.getappname(app)
        ver = common.getcvname(app)
        logging.info('...updating to version %s' % ver)
        commitmsg = 'Update CV of %s to %s' % (name, ver)

    if options.auto:
        mode = app['Auto Update Mode']
        if mode in ('None', 'Static'):
            pass
        elif mode.startswith('Version '):
            pattern = mode[8:]
            if pattern.startswith('+'):
                try:
                    suffix, pattern = pattern.split(' ', 1)
                except ValueError:
                    raise MetaDataException("Invalid AUM: " + mode)
            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['disable'] = False
                newbuild['vercode'] = app['Current Version Code']
                newbuild['version'] = app['Current Version'] + suffix
                logging.info("...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)
                name = common.getappname(app)
                ver = common.getcvname(app)
                commitmsg = "Update %s to %s" % (name, ver)
        else:
            logging.warn('Invalid auto update mode "' + mode + '" on ' + app['id'])

    if commitmsg:
        metafile = os.path.join('metadata', app['id'] + '.txt')
        metadata.write_metadata(metafile, app)
        if options.commit:
            logging.info("Commiting update for " + metafile)
            gitcmd = ["git", "commit", "-m", commitmsg]
            if 'auto_author' in config:
                gitcmd.extend(['--author', config['auto_author']])
            gitcmd.extend(["--", metafile])
            if subprocess.call(gitcmd) != 0:
                logging.error("Git commit failed")
                sys.exit(1)
Exemplo n.º 9
0
def main():

    global config, options

    # Parse command line...
    parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
    parser.add_option("-v", "--verbose", action="store_true", default=False,
                      help="Spew out even more information than normal")
    parser.add_option("-q", "--quiet", action="store_true", default=False,
                      help="Restrict output to warnings and errors")
    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...
    allapps = metadata.read_metadata()

    apps = common.read_app_args(args, allapps, False)

    if options.gplay:
        for app in apps:
            version, reason = check_gplay(app)
            if version is None:
                if reason == '404':
                    logging.info("{0} is not in the Play Store".format(common.getappname(app)))
                else:
                    logging.info("{0} encountered a problem: {1}".format(common.getappname(app), reason))
            if version is not None:
                stored = app['Current Version']
                if not stored:
                    logging.info("{0} has no Current Version but has version {1} on the Play Store"
                                 .format(common.getappname(app), version))
                elif LooseVersion(stored) < LooseVersion(version):
                    logging.info("{0} has version {1} on the Play Store, which is bigger than {2}"
                                 .format(common.getappname(app), version, stored))
                else:
                    if stored != version:
                        logging.info("{0} has version {1} on the Play Store, which differs from {2}"
                                     .format(common.getappname(app), version, stored))
                    else:
                        logging.info("{0} has the same version {1} on the Play Store"
                                     .format(common.getappname(app), version))
        return

    for appid, app in apps.iteritems():

        if options.autoonly and app['Auto Update Mode'] in ('None', 'Static'):
            logging.debug("Nothing to do for {0}...".format(appid))
            continue

        logging.info("Processing " + appid + '...')

        checkupdates_app(app)

    logging.info("Finished.")
Exemplo n.º 10
0
def checkupdates_app(app, first=True):

    # If a change is made, commitmsg should be set to a description of it.
    # Only if this is set will changes be written back to the metadata.
    commitmsg = None

    tag = None
    msg = None
    vercode = None
    noverok = False
    mode = app['Update Check Mode']
    if mode.startswith('Tags'):
        pattern = mode[5:] if len(mode) > 4 else None
        (version, vercode, tag) = check_tags(app, pattern)
        msg = vercode
    elif mode == 'RepoManifest':
        (version, vercode) = check_repomanifest(app)
        msg = vercode
    elif mode.startswith('RepoManifest/'):
        tag = mode[13:]
        (version, vercode) = check_repomanifest(app, tag)
        msg = vercode
    elif mode == 'RepoTrunk':
        (version, vercode) = check_repotrunk(app)
        msg = vercode
    elif mode == 'HTTP':
        (version, vercode) = check_http(app)
        msg = vercode
    elif mode in ('None', 'Static'):
        version = None
        msg = 'Checking disabled'
        noverok = True
    else:
        version = None
        msg = 'Invalid update check method'

    if first and version is None and vercode == "Couldn't find package ID":
        logging.warn("Couldn't find any version information. Looking for a subdir change...")
        new_subdir = check_changed_subdir(app)
        if new_subdir is None:
            logging.warn("Couldn't find any new subdir.")
        else:
            logging.warn("Trying a new subdir: %s" % new_subdir)
            new_build = {}
            metadata.fill_build_defaults(new_build)
            new_build['version'] = "Ignore"
            new_build['vercode'] = "-1"
            new_build['subdir'] = new_subdir
            app['builds'].append(new_build)
            return checkupdates_app(app, first=False)

    if version and vercode and app['Vercode Operation']:
        op = app['Vercode Operation'].replace("%c", str(int(vercode)))
        vercode = str(eval(op))

    updating = False
    if version is None:
        logmsg = "...{0} : {1}".format(app['id'], msg)
        if noverok:
            logging.info(logmsg)
        else:
            logging.warn(logmsg)
    elif vercode == app['Current Version Code']:
        logging.info("...up to date")
    else:
        app['Current Version'] = version
        app['Current Version Code'] = str(int(vercode))
        updating = True

    commitmsg = fetch_autoname(app, tag)

    if updating:
        name = common.getappname(app)
        ver = common.getcvname(app)
        logging.info('...updating to version %s' % ver)
        commitmsg = 'Update CV of %s to %s' % (name, ver)

    if options.auto:
        mode = app['Auto Update Mode']
        if mode in ('None', 'Static'):
            pass
        elif mode.startswith('Version '):
            pattern = mode[8:]
            if pattern.startswith('+'):
                try:
                    suffix, pattern = pattern.split(' ', 1)
                except ValueError:
                    raise MetaDataException("Invalid AUM: " + mode)
            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['disable'] = False
                newbuild['vercode'] = app['Current Version Code']
                newbuild['version'] = app['Current Version'] + suffix
                logging.info("...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)
                name = common.getappname(app)
                ver = common.getcvname(app)
                commitmsg = "Update %s to %s" % (name, ver)
        else:
            logging.warn('Invalid auto update mode "' + mode + '" on ' + app['id'])

    if commitmsg:
        metafile = os.path.join('metadata', app['id'] + '.txt')
        metadata.write_metadata(metafile, app)
        if options.commit:
            logging.info("Commiting update for " + metafile)
            gitcmd = ["git", "commit", "-m", commitmsg]
            if 'auto_author' in config:
                gitcmd.extend(['--author', config['auto_author']])
            gitcmd.extend(["--", metafile])
            if subprocess.call(gitcmd) != 0:
                logging.error("Git commit failed")
                sys.exit(1)
Exemplo n.º 11
0
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."