chiark / gitweb /
Add retrieve_string(); use it in parse_androidmanifest
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 5 Jul 2013 20:34:53 +0000 (22:34 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 5 Jul 2013 20:34:53 +0000 (22:34 +0200)
fdroidserver/common.py

index 1f6a266e483d9dc87d652e9ac14e3648534082cb..ce6177e5f7c56baf932aca73081b241cf84bcbac 100644 (file)
@@ -861,6 +861,15 @@ def description_html(lines,linkres):
     ps.end()
     return ps.text_html
 
+def retrieve_string(app_dir, string_id):
+    string_search = re.compile(r'.*"'+string_id+'".*>([^<]+?)<.*').search
+    for xmlfile in glob.glob(os.path.join(
+            app_dir, 'res', 'values', '*string*.xml')):
+        for line in file(xmlfile):
+            matches = string_search(line)
+            if matches:
+                return matches.group(1)
+    return ''
 
 # Retrieve the package name
 def fetch_real_name(app_dir):
@@ -880,20 +889,7 @@ def fetch_real_name(app_dir):
                 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', '*string*.xml')):
-            for line in file(xmlfile):
-                if name2 is not None:
-                    break
-                matches = string_search(line)
-                if matches:
-                    name2 = matches.group(1)
-        if name2 is not None:
-            return name2
-        return ''
+        return retrieve_string(app_dir, name[8:])
 
     else:
         return name
@@ -923,23 +919,8 @@ def parse_androidmanifest(app_dir):
             matches = vcsearch(line)
             if matches:
                 vercode = matches.group(1)
-    if version:
-        return (version, vercode, package)
-    for xmlfile in glob.glob(os.path.join(
-            app_dir, 'res', 'values', 'strings*transl*.xml')):
-        for line in file(xmlfile):
-            if not version:
-                matches = vnsearch_xml(line)
-                if matches:
-                    version = matches.group(2)
-    if not version:
-        for line in file(os.path.join(app_dir, 'res/values/strings.xml')):
-            if not version:
-                matches = vnsearch_xml(line)
-                if matches:
-                    version = matches.group(2)
-    if not version:
-        version = "None"
+    if version.startswith('@string/'):
+        version = retrieve_string(app_dir, version[8:])
     return (version, vercode, package)
 
 class BuildException(Exception):