chiark / gitweb /
Add "Auto Name" field, fill it in checkupdates
authorDaniel Martí <mvdan@mvdan.cc>
Mon, 10 Jun 2013 22:30:30 +0000 (00:30 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Mon, 10 Jun 2013 22:30:30 +0000 (00:30 +0200)
fdroidserver/checkupdates.py
fdroidserver/common.py

index b1db1d10da2971282dfbfd3c142fed22704a53c6..850e15b713a346a4963c63bfa5554379197571fe 100644 (file)
@@ -268,6 +268,24 @@ def main():
             writeit = True
             logmsg = "Update current version of " + app['id'] + " to " + version
 
+        if app['Repo Type'] == 'srclib':
+            app_dir = os.path.join('build', 'srclib', app['Repo'])
+        else:
+            app_dir = os.path.join('build/', app['id'])
+
+        vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir, sdk_path)
+        vcs.gotorevision(None)
+
+        if len(app['builds']) > 0:
+            if 'subdir' in app['builds'][-1]:
+                app_dir = os.path.join(app_dir, app['builds'][-1]['subdir'])
+
+        new_name = common.fetch_real_name(app_dir)
+        if new_name != app['Auto Name']:
+            app['Auto Name'] = new_name
+            writeit = True
+            logmsg = "Update auto name of " + app['id'] + " to " + new_name
+
         if options.auto:
             mode = app['Auto Update Mode']
             if mode == 'None':
index 80730fd847f3124dc96942bead21a37e50b6f3ad..73777c45ed731dd08adbf5a017264eaf254808d2 100644 (file)
@@ -466,6 +466,7 @@ def parse_metadata(metafile, **kw):
 
     # Defaults for fields that come from metadata...
     thisinfo['Name'] = None
+    thisinfo['Auto Name'] = ''
     thisinfo['Category'] = 'None'
     thisinfo['Description'] = []
     thisinfo['Summary'] = ''
@@ -621,6 +622,7 @@ def write_metadata(dest, app):
     mf.write('\n')
     if app['Name']:
         writefield('Name')
+    writefield('Auto Name')
     writefield('Summary')
     writefield('Description', '')
     for line in app['Description']:
@@ -860,6 +862,32 @@ def description_html(lines,linkres):
     return ps.text_html
 
 
+# Retrieve the package name
+def fetch_real_name(app_dir):
+    name_search = re.compile(r'.*android:label="([^"]+)".*').search
+    name = None
+    for line in file(os.path.join(app_dir, 'AndroidManifest.xml')):
+        if name is not None:
+            break
+        matches = name_search(line)
+        if matches:
+            name = matches.group(1)
+
+    if name.startswith('@string/'):
+        id = name[8:]
+        name2 = None
+        string_search= re.compile(r'.*"'+id+'">([^<]+?)<.*').search
+        for xmlfile in glob.glob(os.path.join(
+                app_dir, 'res', 'values', 'strings*.xml')):
+            for line in file(xmlfile):
+                if name2 is not None:
+                    break
+                matches = string_search(line)
+                if matches:
+                    name2 = matches.group(1)
+        return name2
+
+    return name
 
 # Extract some information from the AndroidManifest.xml at the given path.
 # Returns (version, vercode, package), any or all of which might be None.