1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 17:00:12 +01:00

Lots more FDroidPopen replacements

This commit is contained in:
Daniel Martí 2014-01-27 16:22:25 +01:00
parent 9bc8dc95ff
commit 62c3663df3
6 changed files with 49 additions and 86 deletions

View File

@ -669,16 +669,14 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
if not os.path.exists(src): if not os.path.exists(src):
raise BuildException("Unsigned apk is not at expected location of " + src) raise BuildException("Unsigned apk is not at expected location of " + src)
p = subprocess.Popen([os.path.join(config['sdk_path'], p = FDroidPopen([os.path.join(config['sdk_path'],
'build-tools', config['build_tools'], 'aapt'), 'build-tools', config['build_tools'], 'aapt'),
'dump', 'badging', src], 'dump', 'badging', src])
stdout=subprocess.PIPE)
output = p.communicate()[0]
vercode = None vercode = None
version = None version = None
foundid = None foundid = None
for line in output.splitlines(): for line in p.stdout.splitlines():
if line.startswith("package:"): if line.startswith("package:"):
pat = re.compile(".*name='([a-zA-Z0-9._]*)'.*") pat = re.compile(".*name='([a-zA-Z0-9._]*)'.*")
m = pat.match(line) m = pat.match(line)

View File

@ -440,7 +440,7 @@ class vcs_gitsvn(vcs):
if p.returncode != 0 or not git_rev: if p.returncode != 0 or not git_rev:
# Try a plain git checkout as a last resort # Try a plain git checkout as a last resort
p = subprocess.Popen(['git', 'checkout', rev], cwd=self.local) p = FDroidPopen(['git', 'checkout', rev], cwd=self.local)
if p.returncode != 0: if p.returncode != 0:
raise VCSException("No git treeish found and direct git checkout failed") raise VCSException("No git treeish found and direct git checkout failed")
else: else:
@ -530,11 +530,9 @@ class vcs_hg(vcs):
if subprocess.call(['hg', 'update', '-C', rev], if subprocess.call(['hg', 'update', '-C', rev],
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Hg checkout failed") raise VCSException("Hg checkout failed")
p = subprocess.Popen(['hg', 'purge', '--all'], stdout=subprocess.PIPE, p = FDroidPopen(['hg', 'purge', '--all'], cwd=self.local)
cwd=self.local)
result = p.communicate()[0]
# Also delete untracked files, we have to enable purge extension for that: # Also delete untracked files, we have to enable purge extension for that:
if "'purge' is provided by the following extension" in result: if "'purge' is provided by the following extension" in p.stdout:
with open(self.local+"/.hg/hgrc", "a") as myfile: with open(self.local+"/.hg/hgrc", "a") as myfile:
myfile.write("\n[extensions]\nhgext.purge=\n") myfile.write("\n[extensions]\nhgext.purge=\n")
if subprocess.call(['hg', 'purge', '--all'], cwd=self.local) != 0: if subprocess.call(['hg', 'purge', '--all'], cwd=self.local) != 0:
@ -543,9 +541,8 @@ class vcs_hg(vcs):
raise VCSException("HG purge failed") raise VCSException("HG purge failed")
def gettags(self): def gettags(self):
p = subprocess.Popen(['hg', 'tags', '-q'], p = FDroidPopen(['hg', 'tags', '-q'], cwd=self.local)
stdout=subprocess.PIPE, cwd=self.local) return p.stdout.splitlines()[1:]
return p.communicate()[0].splitlines()[1:]
class vcs_bzr(vcs): class vcs_bzr(vcs):
@ -573,10 +570,9 @@ class vcs_bzr(vcs):
raise VCSException("Bzr revert failed") raise VCSException("Bzr revert failed")
def gettags(self): def gettags(self):
p = subprocess.Popen(['bzr', 'tags'], p = FDroidPopen(['bzr', 'tags'], cwd=self.local)
stdout=subprocess.PIPE, cwd=self.local)
return [tag.split(' ')[0].strip() for tag in return [tag.split(' ')[0].strip() for tag in
p.communicate()[0].splitlines()] p.stdout.splitlines()]
def retrieve_string(xml_dir, string): def retrieve_string(xml_dir, string):
if string.startswith('@string/'): if string.startswith('@string/'):
@ -1325,15 +1321,13 @@ def isApkDebuggable(apkfile, config):
:param apkfile: full path to the apk to check""" :param apkfile: full path to the apk to check"""
p = subprocess.Popen([os.path.join(config['sdk_path'], p = FDroidPopen([os.path.join(config['sdk_path'],
'build-tools', config['build_tools'], 'aapt'), 'build-tools', config['build_tools'], 'aapt'),
'dump', 'xmltree', apkfile, 'AndroidManifest.xml'], 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'])
stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
logging.critical("Failed to get apk manifest information") logging.critical("Failed to get apk manifest information")
sys.exit(1) sys.exit(1)
for line in output.splitlines(): for line in p.stdout.splitlines():
if 'android:debuggable' in line and not line.endswith('0x0'): if 'android:debuggable' in line and not line.endswith('0x0'):
return True return True
return False return False
@ -1377,11 +1371,12 @@ def FDroidPopen(commands, cwd=None):
if cwd: if cwd:
logging.info("Directory: %s" % cwd) logging.info("Directory: %s" % cwd)
logging.info(" > %s" % ' '.join(commands)) logging.info("> %s" % ' '.join(commands))
result = PopenResult() result = PopenResult()
p = subprocess.Popen(commands, cwd=cwd, p = subprocess.Popen(commands, cwd=cwd,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
stdin=subprocess.PIPE)
stdout_queue = Queue.Queue() stdout_queue = Queue.Queue()
stdout_reader = AsynchronousFileReader(p.stdout, stdout_queue) stdout_reader = AsynchronousFileReader(p.stdout, stdout_queue)

View File

@ -24,7 +24,6 @@ import os
import re import re
import shutil import shutil
import socket import socket
import subprocess
import sys import sys
from optparse import OptionParser from optparse import OptionParser
@ -67,11 +66,8 @@ def genkey(keystore, repo_keyalias, password, keydname):
if p.returncode != 0: if p.returncode != 0:
raise BuildException("Failed to generate key", p.stdout) raise BuildException("Failed to generate key", p.stdout)
# now show the lovely key that was just generated # now show the lovely key that was just generated
p = subprocess.Popen(['keytool', '-list', '-v', p = FDroidPopen(['keytool', '-list', '-v',
'-keystore', keystore, '-alias', repo_keyalias], '-keystore', keystore, '-alias', repo_keyalias])
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = p.communicate(password)[0] output = p.communicate(password)[0]
print(output.lstrip().strip() + '\n\n') print(output.lstrip().strip() + '\n\n')

View File

@ -21,13 +21,12 @@
import sys import sys
import os import os
import shutil import shutil
import subprocess
import md5 import md5
import glob import glob
from optparse import OptionParser from optparse import OptionParser
import common, metadata import common, metadata
from common import BuildException from common import FDroidPopen, BuildException
config = None config = None
options = None options = None
@ -119,42 +118,34 @@ def main():
# See if we already have a key for this application, and # See if we already have a key for this application, and
# if not generate one... # if not generate one...
p = subprocess.Popen(['keytool', '-list', p = FDroidPopen(['keytool', '-list',
'-alias', keyalias, '-keystore', config['keystore'], '-alias', keyalias, '-keystore', config['keystore'],
'-storepass', config['keystorepass']], stdout=subprocess.PIPE) '-storepass', config['keystorepass']])
output = p.communicate()[0]
if p.returncode !=0: if p.returncode !=0:
print "Key does not exist - generating..." print "Key does not exist - generating..."
p = subprocess.Popen(['keytool', '-genkey', p = FDroidPopen(['keytool', '-genkey',
'-keystore', config['keystore'], '-alias', keyalias, '-keystore', config['keystore'], '-alias', keyalias,
'-keyalg', 'RSA', '-keysize', '2048', '-keyalg', 'RSA', '-keysize', '2048',
'-validity', '10000', '-validity', '10000',
'-storepass', config['keystorepass'], '-storepass', config['keystorepass'],
'-keypass', config['keypass'], '-keypass', config['keypass'],
'-dname', config['keydname']], stdout=subprocess.PIPE) '-dname', config['keydname']])
output = p.communicate()[0]
print output
if p.returncode != 0: if p.returncode != 0:
raise BuildException("Failed to generate key") raise BuildException("Failed to generate key")
# Sign the application... # Sign the application...
p = subprocess.Popen(['jarsigner', '-keystore', config['keystore'], p = FDroidPopen(['jarsigner', '-keystore', config['keystore'],
'-storepass', config['keystorepass'], '-storepass', config['keystorepass'],
'-keypass', config['keypass'], '-sigalg', '-keypass', config['keypass'], '-sigalg',
'MD5withRSA', '-digestalg', 'SHA1', 'MD5withRSA', '-digestalg', 'SHA1',
apkfile, keyalias], stdout=subprocess.PIPE) apkfile, keyalias])
output = p.communicate()[0]
print output
if p.returncode != 0: if p.returncode != 0:
raise BuildException("Failed to sign application") raise BuildException("Failed to sign application")
# Zipalign it... # Zipalign it...
p = subprocess.Popen([os.path.join(config['sdk_path'],'tools','zipalign'), p = FDroidPopen([os.path.join(config['sdk_path'],'tools','zipalign'),
'-v', '4', apkfile, '-v', '4', apkfile,
os.path.join(output_dir, apkfilename)], os.path.join(output_dir, apkfilename)])
stdout=subprocess.PIPE)
output = p.communicate()[0]
print output
if p.returncode != 0: if p.returncode != 0:
raise BuildException("Failed to align application") raise BuildException("Failed to align application")
os.remove(apkfile) os.remove(apkfile)

View File

@ -22,7 +22,6 @@ import sys
import os import os
import shutil import shutil
import glob import glob
import subprocess
import re import re
import zipfile import zipfile
import hashlib import hashlib
@ -34,6 +33,7 @@ import common, metadata
from metadata import MetaDataException from metadata import MetaDataException
from PIL import Image from PIL import Image
from common import FDroidPopen
def get_densities(): def get_densities():
return ['640', '480', '320', '240', '160', '120'] return ['640', '480', '320', '240', '160', '120']
@ -369,14 +369,13 @@ def scan_apks(apps, apkcache, repodir, knownapks):
thisinfo['features'] = [] thisinfo['features'] = []
thisinfo['icons_src'] = {} thisinfo['icons_src'] = {}
thisinfo['icons'] = {} thisinfo['icons'] = {}
p = subprocess.Popen([os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'aapt'), p = FDroidPopen([os.path.join(config['sdk_path'],
'dump', 'badging', apkfile], 'build-tools', config['build_tools'], 'aapt'),
stdout=subprocess.PIPE) 'dump', 'badging', apkfile])
output = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
print "ERROR: Failed to get apk information" print "ERROR: Failed to get apk information"
sys.exit(1) sys.exit(1)
for line in output.splitlines(): for line in p.stdout.splitlines():
if line.startswith("package:"): if line.startswith("package:"):
try: try:
thisinfo['id'] = re.match(name_pat, line).group(1) thisinfo['id'] = re.match(name_pat, line).group(1)
@ -450,15 +449,12 @@ def scan_apks(apps, apkcache, repodir, knownapks):
print "\tcd " + getsig_dir print "\tcd " + getsig_dir
print "\t./make.sh" print "\t./make.sh"
sys.exit(1) sys.exit(1)
p = subprocess.Popen(['java', '-cp', os.path.join(os.path.dirname(__file__), 'getsig'), p = FDroidPopen(['java', '-cp', os.path.join(os.path.dirname(__file__), 'getsig'),
'getsig', os.path.join(os.getcwd(), apkfile)], stdout=subprocess.PIPE) 'getsig', os.path.join(os.getcwd(), apkfile)])
output = p.communicate()[0] if p.returncode != 0 or not p.stdout.startswith('Result:'):
if options.verbose:
print output
if p.returncode != 0 or not output.startswith('Result:'):
print "ERROR: Failed to get apk signature" print "ERROR: Failed to get apk signature"
sys.exit(1) sys.exit(1)
thisinfo['sig'] = output[7:].strip() thisinfo['sig'] = p.stdout[7:].strip()
apk = zipfile.ZipFile(apkfile, 'r') apk = zipfile.ZipFile(apkfile, 'r')
@ -646,18 +642,16 @@ def make_index(apps, apks, repodir, archive, categories):
return " ".join(ret) return " ".join(ret)
def extract_pubkey(): def extract_pubkey():
p = subprocess.Popen(['keytool', '-exportcert', p = FDroidPopen(['keytool', '-exportcert',
'-alias', config['repo_keyalias'], '-alias', config['repo_keyalias'],
'-keystore', config['keystore'], '-keystore', config['keystore'],
'-storepass', config['keystorepass']], '-storepass', config['keystorepass']])
stdout=subprocess.PIPE)
cert = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
print "ERROR: Failed to get repo pubkey" print "ERROR: Failed to get repo pubkey"
sys.exit(1) sys.exit(1)
global repo_pubkey_fingerprint global repo_pubkey_fingerprint
repo_pubkey_fingerprint = cert_fingerprint(cert) repo_pubkey_fingerprint = cert_fingerprint(p.stdout)
return "".join("%02x" % ord(b) for b in cert) return "".join("%02x" % ord(b) for b in p.stdout)
repoel.setAttribute("pubkey", extract_pubkey()) repoel.setAttribute("pubkey", extract_pubkey())
@ -799,27 +793,19 @@ def make_index(apps, apks, repodir, archive, categories):
print "Key fingerprint:", repo_pubkey_fingerprint print "Key fingerprint:", repo_pubkey_fingerprint
#Create a jar of the index... #Create a jar of the index...
p = subprocess.Popen(['jar', 'cf', 'index.jar', 'index.xml'], p = FDroidPopen(['jar', 'cf', 'index.jar', 'index.xml'], cwd=repodir)
cwd=repodir, stdout=subprocess.PIPE)
output = p.communicate()[0]
if options.verbose:
print output
if p.returncode != 0: if p.returncode != 0:
print "ERROR: Failed to create jar file" print "ERROR: Failed to create jar file"
sys.exit(1) sys.exit(1)
# Sign the index... # Sign the index...
p = subprocess.Popen(['jarsigner', '-keystore', config['keystore'], p = FDroidPopen(['jarsigner', '-keystore', config['keystore'],
'-storepass', config['keystorepass'], '-keypass', config['keypass'], '-storepass', config['keystorepass'], '-keypass', config['keypass'],
'-digestalg', 'SHA1', '-sigalg', 'MD5withRSA', '-digestalg', 'SHA1', '-sigalg', 'MD5withRSA',
os.path.join(repodir, 'index.jar') , config['repo_keyalias']], stdout=subprocess.PIPE) os.path.join(repodir, 'index.jar') , config['repo_keyalias']])
output = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
print "Failed to sign index" print "Failed to sign index"
print output
sys.exit(1) sys.exit(1)
if options.verbose:
print output
# Copy the repo icon into the repo directory... # Copy the repo icon into the repo directory...
icon_dir = os.path.join(repodir ,'icons') icon_dir = os.path.join(repodir ,'icons')

View File

@ -24,6 +24,8 @@ import subprocess
import glob import glob
from optparse import OptionParser from optparse import OptionParser
from common import FDroidPopen
import common import common
options = None options = None
@ -75,10 +77,7 @@ def main():
os.remove(remoteapk) os.remove(remoteapk)
url = 'https://f-droid.org/repo/' + apkfilename url = 'https://f-droid.org/repo/' + apkfilename
print "...retrieving " + url print "...retrieving " + url
p = subprocess.Popen(['wget', url], p = FDroidPopen(['wget', url], cwd=tmp_dir)
cwd=tmp_dir,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
raise Exception("Failed to get " + apkfilename) raise Exception("Failed to get " + apkfilename)
@ -97,12 +96,10 @@ def main():
cwd=thatdir) != 0: cwd=thatdir) != 0:
raise Exception("Failed to unpack remote build of " + apkfilename) raise Exception("Failed to unpack remote build of " + apkfilename)
p = subprocess.Popen(['diff', '-r', 'this_apk', 'that_apk'], p = FDroidPopen(['diff', '-r', 'this_apk', 'that_apk'], cwd=tmp_dir)
cwd=tmp_dir, stdout=subprocess.PIPE) lines = p.stdout.splitlines()
out = p.communicate()[0]
lines = out.splitlines()
if len(lines) != 1 or 'META-INF' not in lines[0]: if len(lines) != 1 or 'META-INF' not in lines[0]:
raise Exception("Unexpected diff output - " + out) raise Exception("Unexpected diff output - " + p.stdout)
print "...successfully verified" print "...successfully verified"
verified += 1 verified += 1