1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-17 18:50:11 +02: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):
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'),
'dump', 'badging', src],
stdout=subprocess.PIPE)
output = p.communicate()[0]
'dump', 'badging', src])
vercode = None
version = None
foundid = None
for line in output.splitlines():
for line in p.stdout.splitlines():
if line.startswith("package:"):
pat = re.compile(".*name='([a-zA-Z0-9._]*)'.*")
m = pat.match(line)

View File

@ -440,7 +440,7 @@ class vcs_gitsvn(vcs):
if p.returncode != 0 or not git_rev:
# 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:
raise VCSException("No git treeish found and direct git checkout failed")
else:
@ -530,11 +530,9 @@ class vcs_hg(vcs):
if subprocess.call(['hg', 'update', '-C', rev],
cwd=self.local) != 0:
raise VCSException("Hg checkout failed")
p = subprocess.Popen(['hg', 'purge', '--all'], stdout=subprocess.PIPE,
cwd=self.local)
result = p.communicate()[0]
p = FDroidPopen(['hg', 'purge', '--all'], cwd=self.local)
# 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:
myfile.write("\n[extensions]\nhgext.purge=\n")
if subprocess.call(['hg', 'purge', '--all'], cwd=self.local) != 0:
@ -543,9 +541,8 @@ class vcs_hg(vcs):
raise VCSException("HG purge failed")
def gettags(self):
p = subprocess.Popen(['hg', 'tags', '-q'],
stdout=subprocess.PIPE, cwd=self.local)
return p.communicate()[0].splitlines()[1:]
p = FDroidPopen(['hg', 'tags', '-q'], cwd=self.local)
return p.stdout.splitlines()[1:]
class vcs_bzr(vcs):
@ -573,10 +570,9 @@ class vcs_bzr(vcs):
raise VCSException("Bzr revert failed")
def gettags(self):
p = subprocess.Popen(['bzr', 'tags'],
stdout=subprocess.PIPE, cwd=self.local)
p = FDroidPopen(['bzr', 'tags'], cwd=self.local)
return [tag.split(' ')[0].strip() for tag in
p.communicate()[0].splitlines()]
p.stdout.splitlines()]
def retrieve_string(xml_dir, string):
if string.startswith('@string/'):
@ -1325,15 +1321,13 @@ def isApkDebuggable(apkfile, config):
: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'),
'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
stdout=subprocess.PIPE)
output = p.communicate()[0]
'dump', 'xmltree', apkfile, 'AndroidManifest.xml'])
if p.returncode != 0:
logging.critical("Failed to get apk manifest information")
sys.exit(1)
for line in output.splitlines():
for line in p.stdout.splitlines():
if 'android:debuggable' in line and not line.endswith('0x0'):
return True
return False
@ -1377,11 +1371,12 @@ def FDroidPopen(commands, cwd=None):
if cwd:
logging.info("Directory: %s" % cwd)
logging.info(" > %s" % ' '.join(commands))
logging.info("> %s" % ' '.join(commands))
result = PopenResult()
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_reader = AsynchronousFileReader(p.stdout, stdout_queue)

View File

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

View File

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

View File

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

View File

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