chiark / gitweb /
static URLs to "Current Version" of each app
authorHans-Christoph Steiner <hans@eds.org>
Sat, 11 Oct 2014 00:47:21 +0000 (20:47 -0400)
committerHans-Christoph Steiner <hans@eds.org>
Tue, 11 Nov 2014 14:06:52 +0000 (15:06 +0100)
I wrote up the feature to automatically generate symlinks with a constant name
that points to the current release version. I have it on by default, with a
*config.py* option to turn it off. There is also an option to set where the
symlink name comes from which defaults to app['Name'] i.e. F-Droid.apk, but
can easily be set to app['id'], i.e. _org.fdroid.fdroid.apk_. I think the best
place for the symlinks is in the root of the repo, so like
https://f-droid.org/F-Droid.apk or https://guardianproject.info/fdroid/ChatSecure.apk

For the case of the current FDroid static link https://f-droid.org/FDroid.apk
it can just be a symlink to the generated one (https://f-droid.org/F-Droid.apk
or https://f-droid.org/org.fdroid.fdroid.apk). Right now, this feature is all
or nothing, meaning it generates symlinks for all apps in the repo, or none. I
can’t think of any problems that this might cause since its only symlinks, so
the amount of disk space is tiny. Also, I think it would be useful for having
an easy “Download this app” button on each app’s page on the “Browse” view. As
long as this button is less prominent than the “Download F-Droid” button, and
it is clear that it is better to use the FDroid app than doing direct
downloads. For the f-droid.org repo, the symlinks should probably be based on
app['id'] to prevent name conflicts.

more info here:
https://f-droid.org/forums/topic/static-urls-to-current-version-of-each-app/

examples/config.py
fdroidserver/common.py
fdroidserver/update.py

index e1272649b02b82433ea1f276befb49f90b12eb82..974a4d5bc04ba43a574c0aa399061e02118019a8 100644 (file)
@@ -52,6 +52,15 @@ archive_description = """
 The repository of older versions of applications from the main demo repository.
 """
 
+# `fdroid update` will create a link to the current version of a given app.
+# This provides a static path to the current APK.  To disable the creation of
+# this link, uncomment this:
+# make_current_version_link = False
+
+# By default, the "current version" link will be based on the "Name" of the
+# app from the metadata.  You can change it to use a different field from the
+# metadata here:
+# current_version_name_source = 'id'
 
 # The ID of a GPG key for making detached signatures for apks. Optional.
 # gpgkey = '1DBA2E89'
index 033cba8b64c8cc25182313c64de92d40b67169a3..f6e9538f9530ad0996a32045f1ca838752eb2f0d 100644 (file)
@@ -47,6 +47,8 @@ default_config = {
     'mvn3': "mvn",
     'gradle': 'gradle',
     'sync_from_local_copy_dir': False,
+    'make_current_version_link': True,
+    'current_version_name_source': 'Name',
     'update_stats': False,
     'stats_ignore': [],
     'stats_server': None,
index 225f594d0ab3e69130a154e501cb1c28da1e3623..cd59a656956a51eb979665fa1e821a0d85508d25 100644 (file)
@@ -824,7 +824,15 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
                     apklist[i]['apkname'], apklist[i + 1]['apkname']))
                 sys.exit(1)
 
+        current_version_code = 0
+        current_version_file = None
         for apk in apklist:
+            # find the APK for the "Current Version"
+            if current_version_code < apk['versioncode']:
+                current_version_code = apk['versioncode']
+            if current_version_code < int(app['Current Version Code']):
+                current_version_file = apk['apkname']
+
             apkel = doc.createElement("package")
             apel.appendChild(apkel)
             addElement('version', apk['version'], doc, apkel)
@@ -857,6 +865,14 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
             if len(apk['features']) > 0:
                 addElement('features', ','.join(apk['features']), doc, apkel)
 
+        if current_version_file is not None \
+                and config['make_current_version_link'] \
+                and repodir == 'repo':  # only create these
+            apklinkname = app[config['current_version_name_source']] + '.apk'
+            if os.path.exists(apklinkname):
+                os.remove(apklinkname)
+            os.symlink(os.path.join(repodir, current_version_file), apklinkname)
+
     of = open(os.path.join(repodir, 'index.xml'), 'wb')
     if options.pretty:
         output = doc.toprettyxml()