chiark / gitweb /
More update check wip
authorCiaran Gultnieks <ciaran@ciarang.com>
Fri, 13 Jan 2012 10:29:19 +0000 (10:29 +0000)
committerCiaran Gultnieks <ciaran@ciarang.com>
Fri, 13 Jan 2012 10:29:19 +0000 (10:29 +0000)
checkupdates.py
common.py

index 0d6310611c5f7e623ead7e1b1fffab395fdd633a..caa27c822c500b4230e3f5b7b53bcc614e9f6807 100755 (executable)
@@ -31,20 +31,11 @@ import common
 execfile('config.py')
 
 
-# Parse command line...
-parser = OptionParser()
-parser.add_option("-v", "--verbose", action="store_true", default=False,
-                  help="Spew out even more information than normal")
-(options, args) = parser.parse_args()
-
-# Get all apps...
-apps = common.read_metadata(options.verbose)
-
-html_parser = HTMLParser.HTMLParser()
-
-for app in apps:
-
-    print "Processing " + app['id']
+# Check for a new version by looking at the Google market.
+# Returns (None, "a message") if this didn't work, or (version, vercode) for
+# the details of the current version.
+def check_market(app):
+    time.sleep(5)
     url = 'http://market.android.com/details?id=' + app['id']
     page = urllib.urlopen(url).read()
 
@@ -60,9 +51,41 @@ for app in apps:
         vercode = m.group(1)
 
     if not vercode:
-        print "...couldn't find version code"
-    elif not version:
-        print "...couldn't find version"
+        return (None, "Couldn't find version code")
+    if not version:
+        return (None, "Couldn't find version")
+    return (version, vercode)
+
+
+
+
+# Parse command line...
+parser = OptionParser()
+parser.add_option("-v", "--verbose", action="store_true", default=False,
+                  help="Spew out even more information than normal")
+(options, args) = parser.parse_args()
+
+# Get all apps...
+apps = common.read_metadata(options.verbose)
+
+html_parser = HTMLParser.HTMLParser()
+
+for app in apps:
+
+    print "Processing " + app['id'] + '...'
+
+    mode = app['Update Check Mode']
+    if mode == 'Market':
+        (version, vercode) = check_market(app)
+    elif mode == 'None':
+        version = None
+        vercode = 'Checking disabled'
+    else:
+        version = None
+        vercode = 'Invalid update check method'
+
+    if not version:
+        print "..." + vercode
     elif vercode == app['Market Version Code'] and version == app['Market Version']:
         print "...up to date"
     else:
@@ -72,7 +95,5 @@ for app in apps:
         metafile = os.path.join('metadata', app['id'] + '.txt')
         common.write_metadata(metafile, app)
 
-    time.sleep(5)
-
 print "Finished."
 
index c825d7ce439802cddbe6a26a9768a9f6c92544a2..262208d106a3a5bc22eec96e67b6ecd08eef97c0 100644 (file)
--- a/common.py
+++ b/common.py
@@ -473,10 +473,11 @@ def write_metadata(dest, app):
         mf.write('\\\n'.join(build['origlines']) + '\n')
     if len(app['builds']) > 0:
         mf.write('\n')
+    writefield('Update Check Mode')
     if len(app['Market Version']) > 0:
         writefield('Market Version')
         writefield('Market Version Code')
-        mf.write('\n')
+    mf.write('\n')
     writecomments(None)
     mf.close()