chiark / gitweb /
Added dates for when added and last updated to repo index
authorCiaran Gultnieks <ciaran@ciarang.com>
Thu, 12 Jul 2012 20:48:59 +0000 (21:48 +0100)
committerCiaran Gultnieks <ciaran@ciarang.com>
Thu, 12 Jul 2012 20:48:59 +0000 (21:48 +0100)
Under each 'app' element there is now an 'added' and a 'lastupdated'
element with the date the application was originally added to the repo,
and when the most recent version was added. Under each 'apk' element there
is also an 'added' for that particular version. For all three of these,
the element contains just a date in YYYY-MM-DD format.

fdroidserver/common.py
fdroidserver/update.py

index bf1eb8d68b3f6d1f6a15681eb3ff5c26d069df20..06f1b94f98a78d7ec77c2eb38965bb616e2b25a4 100644 (file)
@@ -1100,16 +1100,24 @@ class KnownApks:
                 f.write(line + '\n')
             f.close()
 
+    # Record an apk (if it's new, otherwise does nothing)
+    # Returns the date it was added.
     def recordapk(self, apk, app):
         if not apk in self.apks:
             self.apks[apk] = (app, time.gmtime(time.time()))
             self.changed = True
+        _, added = self.apks[apk]
+        return added
 
+    # Look up information - given the 'apkname', returns (app id, date added/None).
+    # Or returns None for an unknown apk.
     def getapp(self, apkname):
         if apkname in self.apks:
             return self.apks[apkname]
         return None
 
+    # Get the most recent 'num' apps added to the repo, as a list of package ids
+    # with the most recent first.
     def getlatest(self, num):
         apps = {}
         for apk, app in self.apks.iteritems():
index 7049c86f6308e40a281ed39636c5fc78f4ef898d..0e68f2fddbeda2b0f82ed03fd4ccdc8087d35f2c 100644 (file)
@@ -74,6 +74,9 @@ def main():
         if app['Category'] not in categories:
             categories.append(app['Category'])
 
+    # Read known apks data (will be updated and written back when we've finished)
+    knownapks = common.KnownApks()
+
     # Gather information about all the apk files in the repo directory...
     apks = []
     for apkfile in glob.glob(os.path.join('repo','*.apk')):
@@ -183,18 +186,42 @@ def main():
             warnings += 1
         apk.close()
 
+        # Record in known apks, getting the added date at the same time..
+        added = knownapks.recordapk(thisinfo['apkname'], thisinfo['id'])
+        if added:
+            thisinfo['added'] = added
+
         apks.append(thisinfo)
 
     # Some information from the apks needs to be applied up to the application
     # level. When doing this, we use the info from the most recent version's apk.
+    # We deal with figuring out when the app was added and last updated at the
+    # same time.
     for app in apps:
-        bestver = 0 
+        bestver = 0
+        added = None
+        lastupdated = None
         for apk in apks:
             if apk['id'] == app['id']:
                 if apk['versioncode'] > bestver:
                     bestver = apk['versioncode']
                     bestapk = apk
 
+                if 'added' in apk:
+                    if not added or apk['added'] < added:
+                        added = apk['added']
+                    if not lastupdated or apk['added'] > lastupdated:
+                        lastupdated = apk['added']
+
+        if added:
+            app['added'] = added
+        else:
+            print "WARNING: Don't know when " + app['id'] + " was added"
+        if lastupdated:
+            app['lastupdated'] = lastupdated
+        else:
+            print "WARNING: Don't know when " + app['id'] + " was last updated"
+
         if bestver == 0:
             if app['Name'] is None:
                 app['Name'] = app['id']
@@ -306,6 +333,10 @@ def main():
                 root.appendChild(apel)
 
                 addElement('id', app['id'], doc, apel)
+                if 'added' in app:
+                    addElement('added', time.strftime('%Y-%m-%d', app['added']), doc, apel)
+                if 'lastupdated' in app:
+                    addElement('lastupdated', time.strftime('%Y-%m-%d', app['lastupdated']), doc, apel)
                 addElement('name', app['Name'], doc, apel)
                 addElement('summary', app['Summary'], doc, apel)
                 addElement('icon', app['icon'], doc, apel)
@@ -361,6 +392,8 @@ def main():
                     addElement('sig', apk['sig'], doc, apkel)
                     addElement('size', str(apk['size']), doc, apkel)
                     addElement('sdkver', str(apk['sdkversion']), doc, apkel)
+                    if 'added' in apk:
+                        addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel)
                     perms = ""
                     for p in apk['permissions']:
                         if len(perms) > 0:
@@ -480,9 +513,6 @@ def main():
     f.close()
 
     # Update known apks info...
-    knownapks = common.KnownApks()
-    for apk in apks:
-        knownapks.recordapk(apk['apkname'], apk['id'])
     knownapks.writeifchanged()
 
     # Generate latest apps data for widget