chiark / gitweb /
Added auto-update mode
authorCiaran Gultnieks <ciaran@ciarang.com>
Thu, 20 Sep 2012 13:16:55 +0000 (14:16 +0100)
committerCiaran Gultnieks <ciaran@ciarang.com>
Thu, 20 Sep 2012 13:16:55 +0000 (14:16 +0100)
fdroidserver/checkupdates.py
fdroidserver/common.py

index 1b99b0859a29a9f0aba4f9d984e321d8122cb4fa..aa7c648e820a6c9f871cfa4f74dda49c9ffb06de 100644 (file)
@@ -181,7 +181,9 @@ def main():
     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="Build only the specified package")
+                      help="Check only the specified package")
+    parser.add_option("--auto", action="store_true", default=False,
+                      help="Process auto-updates")
     (options, args) = parser.parse_args()
 
     # Get all apps...
@@ -197,6 +199,8 @@ def main():
     for app in apps:
             print "Processing " + app['id'] + '...'
 
+            writeit = False
+
             mode = app['Update Check Mode']
             if mode == 'Market':
                 (version, vercode) = check_market(app)
@@ -219,8 +223,38 @@ def main():
                 print '...updating to version:' + version + ' vercode:' + vercode
                 app['Current Version'] = version
                 app['Current Version Code'] = str(int(vercode))
-                metafile = os.path.join('metadata', app['id'] + '.txt')
-                common.write_metadata(metafile, app)
+                writeit = True
+
+            if options.auto:
+                mode = app['Auto Update Mode']
+                if mode == 'None':
+                    pass
+                elif mode.startswith('Version '):
+                    pattern = mode[8:]
+                    gotcur = False
+                    latest = None
+                    for build in app['builds']:
+                        if build['vercode'] == app['Current Version Code']:
+                            gotcur = True
+                        if not latest or build['vercode'] > latest['vercode']:
+                            latest = build
+                    if not gotcur:
+                        newbuild = latest.copy()
+                        del newbuild['origlines']
+                        newbuild['vercode'] = app['Current Version Code']
+                        newbuild['version'] = app['Current Version']
+                        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
+                else:
+                    print 'Invalid auto update mode'
+
+                if writeit:
+                    metafile = os.path.join('metadata', app['id'] + '.txt')
+                    common.write_metadata(metafile, app)
 
     print "Finished."
 
index 58d05bb8bfdda397244b0b9797e44ad455d87430..3c6695ff56ce0b0210d8adb620f91d0d37019457 100644 (file)
@@ -426,6 +426,7 @@ def parse_metadata(metafile, **kw):
     thisinfo['Disabled'] = None
     thisinfo['AntiFeatures'] = None
     thisinfo['Update Check Mode'] = 'Market'
+    thisinfo['Auto Update Mode'] = 'None'
     thisinfo['Current Version'] = ''
     thisinfo['Current Version Code'] = '0'
     thisinfo['Repo Type'] = ''
@@ -594,6 +595,7 @@ def write_metadata(dest, app):
             mf.write('\n')
     if len(app['builds']) > 0:
         mf.write('\n')
+    writefield('Auto Update Mode')
     writefield('Update Check Mode')
     if len(app['Current Version']) > 0:
         writefield('Current Version')