Recognise changes in subdirs in Tags and RepoManifest

This commit is contained in:
Daniel Martí 2014-07-03 17:25:31 +02:00
parent 00066a9b45
commit eaf3216e40
2 changed files with 233 additions and 165 deletions

View file

@ -299,69 +299,46 @@ def check_gplay(app):
return (version.strip(), None) return (version.strip(), None)
config = None # Return all directories under startdir that contain any of the manifest
options = None # files, and thus are probably an Android project.
def dirs_with_manifest(startdir):
for r, d, f in os.walk(startdir):
if any(m in f for m in [
'AndroidManifest.xml', 'pom.xml', 'build.gradle']):
yield r
def main(): # Tries to find a new subdir starting from the root build_dir. Returns said
# subdir relative to the build dir if found, None otherwise.
def check_changed_subdir(app):
global config, options appid = app['Update Check Name'] if app['Update Check Name'] else app['id']
if app['Repo Type'] == 'srclib':
# Parse command line... build_dir = os.path.join('build', 'srclib', app['Repo'])
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: else:
logging.info("{0} encountered a problem: {1}".format(common.getappname(app), reason)) build_dir = os.path.join('build/', app['id'])
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 app in apps: if not os.path.isdir(build_dir):
return None
if options.autoonly and app['Auto Update Mode'] in ('None', 'Static'): flavour = None
logging.debug("Nothing to do for {0}...".format(app['id'])) if len(app['builds']) > 0 and app['builds'][-1]['gradle']:
continue flavour = app['builds'][-1]['gradle']
if flavour == 'yes':
flavour = None
logging.info("Processing " + app['id'] + '...') for d in dirs_with_manifest(build_dir):
logging.debug("Trying possible dir %s." % d)
m_paths = common.manifest_paths(d, flavour)
package = common.parse_androidmanifests(m_paths, app['Update Check Ignore'])[2]
if package and package == appid:
logging.debug("Manifest exists in possible dir %s." % d)
return os.path.relpath(d, build_dir)
return None
def checkupdates_app(app, first=True):
# If a change is made, commitmsg should be set to a description of it. # 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. # Only if this is set will changes be written back to the metadata.
@ -397,7 +374,22 @@ def main():
version = None version = None
msg = 'Invalid update check method' msg = 'Invalid update check method'
if vercode and app['Vercode Operation']: 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))) op = app['Vercode Operation'].replace("%c", str(int(vercode)))
vercode = str(eval(op)) vercode = str(eval(op))
@ -516,6 +508,73 @@ def main():
logging.error("Git commit failed") logging.error("Git commit failed")
sys.exit(1) sys.exit(1)
config = None
options = None
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 app in apps:
if options.autoonly and app['Auto Update Mode'] in ('None', 'Static'):
logging.debug("Nothing to do for {0}...".format(app['id']))
continue
logging.info("Processing " + app['id'] + '...')
checkupdates_app(app)
logging.info("Finished.") logging.info("Finished.")
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -533,6 +533,23 @@ def flagtype(name):
return 'string' return 'string'
def fill_build_defaults(build):
def get_build_type():
for t in ['maven', 'gradle', 'kivy']:
if build[t]:
return t
if build['output']:
return 'raw'
return 'ant'
for flag, value in flag_defaults.iteritems():
if flag in build:
continue
build[flag] = value
build['type'] = get_build_type()
# Parse metadata for a single application. # Parse metadata for a single application.
# #
# 'metafile' - the filename to read. The package id for the application comes # 'metafile' - the filename to read. The package id for the application comes
@ -628,14 +645,6 @@ def parse_metadata(metafile):
thisinfo['comments'].append((key, comment)) thisinfo['comments'].append((key, comment))
del curcomments[:] del curcomments[:]
def get_build_type(build):
for t in ['maven', 'gradle', 'kivy']:
if build[t]:
return t
if build['output']:
return 'raw'
return 'ant'
thisinfo = {} thisinfo = {}
if metafile: if metafile:
if not isinstance(metafile, file): if not isinstance(metafile, file):
@ -767,11 +776,7 @@ def parse_metadata(metafile):
thisinfo['Description'].append('No description available') thisinfo['Description'].append('No description available')
for build in thisinfo['builds']: for build in thisinfo['builds']:
for flag, value in flag_defaults.iteritems(): fill_build_defaults(build)
if flag in build:
continue
build[flag] = value
build['type'] = get_build_type(build)
return thisinfo return thisinfo
@ -841,6 +846,10 @@ def write_metadata(dest, app):
writefield('Repo') writefield('Repo')
mf.write('\n') mf.write('\n')
for build in app['builds']: for build in app['builds']:
if build['version'] == "Ignore":
continue
writecomments('build:' + build['vercode']) writecomments('build:' + build['vercode'])
mf.write("Build:%s,%s\n" % (build['version'], build['vercode'])) mf.write("Build:%s,%s\n" % (build['version'], build['vercode']))