chiark / gitweb /
Find aapt as part of the main config initialisation
[fdroidserver.git] / fdroidserver / update.py
index e8b76cf84ba384a2f4429cf87666579fc5b461ad..a1955e5b7ed765c219016590d1f4db40d8aaf44c 100644 (file)
@@ -34,7 +34,7 @@ import logging
 
 import common
 import metadata
-from common import FDroidPopen
+from common import FDroidPopen, SilentPopen
 from metadata import MetaDataException
 
 
@@ -355,7 +355,7 @@ def scan_apks(apps, apkcache, repodir, knownapks):
 
         apkfilename = apkfile[len(repodir) + 1:]
         if ' ' in apkfilename:
-            logging.error("No spaces in APK filenames!")
+            logging.critical("Spaces in filenames are not allowed.")
             sys.exit(1)
 
         if apkfilename in apkcache:
@@ -374,9 +374,7 @@ def scan_apks(apps, apkcache, repodir, knownapks):
             thisinfo['features'] = []
             thisinfo['icons_src'] = {}
             thisinfo['icons'] = {}
-            p = FDroidPopen([os.path.join(config['sdk_path'], 'build-tools',
-                                          config['build_tools'], 'aapt'),
-                             'dump', 'badging', apkfile])
+            p = SilentPopen([config['aapt'], 'dump', 'badging', apkfile])
             if p.returncode != 0:
                 if options.delete_unknown:
                     if os.path.exists(apkfile):
@@ -387,14 +385,14 @@ def scan_apks(apps, apkcache, repodir, knownapks):
                 else:
                     logging.error("Failed to get apk information, skipping " + apkfile)
                 continue
-            for line in p.stdout.splitlines():
+            for line in p.output.splitlines():
                 if line.startswith("package:"):
                     try:
                         thisinfo['id'] = re.match(name_pat, line).group(1)
                         thisinfo['versioncode'] = int(re.match(vercode_pat, line).group(1))
                         thisinfo['version'] = re.match(vername_pat, line).group(1)
                     except Exception, e:
-                        logging.info("Package matching failed: " + str(e))
+                        logging.error("Package matching failed: " + str(e))
                         logging.info("Line was: " + line)
                         sys.exit(1)
                 elif line.startswith("application:"):
@@ -470,10 +468,10 @@ def scan_apks(apps, apkcache, repodir, knownapks):
                 sys.exit(1)
             p = FDroidPopen(['java', '-cp', os.path.join(os.path.dirname(__file__), 'getsig'),
                              'getsig', os.path.join(os.getcwd(), apkfile)])
-            if p.returncode != 0 or not p.stdout.startswith('Result:'):
+            if p.returncode != 0 or not p.output.startswith('Result:'):
                 logging.critical("Failed to get apk signature")
                 sys.exit(1)
-            thisinfo['sig'] = p.stdout[7:].strip()
+            thisinfo['sig'] = p.output[7:].strip()
 
             apk = zipfile.ZipFile(apkfile, 'r')
 
@@ -539,8 +537,8 @@ def scan_apks(apps, apkcache, repodir, knownapks):
                     continue
                 if last_density is None:
                     continue
-                logging.info("Density %s not available, resizing down from %s"
-                             % (density, last_density))
+                logging.debug("Density %s not available, resizing down from %s"
+                              % (density, last_density))
 
                 last_iconpath = os.path.join(
                     get_icon_dir(repodir, last_density), iconfilename)
@@ -566,8 +564,8 @@ def scan_apks(apps, apkcache, repodir, knownapks):
                     continue
                 if last_density is None:
                     continue
-                logging.info("Density %s not available, copying from lower density %s"
-                             % (density, last_density))
+                logging.debug("Density %s not available, copying from lower density %s"
+                              % (density, last_density))
 
                 shutil.copyfile(
                     os.path.join(get_icon_dir(repodir, last_density), iconfilename),
@@ -664,7 +662,7 @@ def make_index(apps, apks, repodir, archive, categories):
                              '-alias', config['repo_keyalias'],
                              '-keystore', config['keystore'],
                              '-storepass:file', config['keystorepassfile']]
-                            + config['smartcardoptions'])
+                            + config['smartcardoptions'], output=False)
             if p.returncode != 0:
                 msg = "Failed to get repo pubkey!"
                 if config['keystore'] == 'NONE':
@@ -672,8 +670,8 @@ def make_index(apps, apks, repodir, archive, categories):
                 logging.critical(msg)
                 sys.exit(1)
             global repo_pubkey_fingerprint
-            repo_pubkey_fingerprint = cert_fingerprint(p.stdout)
-            return "".join("%02x" % ord(b) for b in p.stdout)
+            repo_pubkey_fingerprint = cert_fingerprint(p.output)
+            return "".join("%02x" % ord(b) for b in p.output)
 
         repoel.setAttribute("pubkey", extract_pubkey())
 
@@ -833,7 +831,7 @@ def make_index(apps, apks, repodir, archive, categories):
         p = FDroidPopen(args)
         # TODO keypass should be sent via stdin
         if p.returncode != 0:
-            logging.info("Failed to sign index")
+            logging.critical("Failed to sign index")
             sys.exit(1)
 
     # Copy the repo icon into the repo directory...
@@ -876,6 +874,12 @@ def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversi
                 if 'srcname' in apk:
                     shutil.move(os.path.join(repodir, apk['srcname']),
                                 os.path.join(archivedir, apk['srcname']))
+                    # Move GPG signature too...
+                    sigfile = apk['srcname'] + '.asc'
+                    sigsrc = os.path.join(repodir, sigfile)
+                    if os.path.exists(sigsrc):
+                        shutil.move(sigsrc, os.path.join(archivedir, sigfile))
+
                 archapks.append(apk)
                 apks.remove(apk)
 
@@ -927,6 +931,13 @@ def main():
         resize_all_icons(repodirs)
         sys.exit(0)
 
+    # check that icons exist now, rather than fail at the end of `fdroid update`
+    for k in ['repo_icon', 'archive_icon']:
+        if k in config:
+            if not os.path.exists(config[k]):
+                logging.critical(k + ' "' + config[k] + '" does not exist! Correct it in config.py.')
+                sys.exit(1)
+
     # Get all apps...
     apps = metadata.read_metadata()