Exemplo n.º 1
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)
Exemplo n.º 2
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)
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.º 4
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."