Merge branch 'p1' into 'master'

Fix pubkey extraction on update

Replacement of !86.

Fix pubkey extraction in case of non-empty _JAVA_OPTIONS. Fixes #133.

I didn't actually run the test suite (it looks like there are some preparations to be done for that), but I checked the commands from `test_fdroid_popen_stderr_redirect` in ipython.

See merge request !103
This commit is contained in:
Daniel Martí 2016-02-28 13:37:17 +00:00
commit bf32477433
3 changed files with 25 additions and 3 deletions

View File

@ -1626,7 +1626,7 @@ def SdkToolsPopen(commands, cwd=None, output=True):
cwd=cwd, output=output)
def FDroidPopen(commands, cwd=None, output=True):
def FDroidPopen(commands, cwd=None, output=True, stderr_to_stdout=True):
"""
Run a command and capture the possibly huge output.
@ -1642,15 +1642,28 @@ def FDroidPopen(commands, cwd=None, output=True):
logging.debug("Directory: %s" % cwd)
logging.debug("> %s" % ' '.join(commands))
stderr_param = subprocess.STDOUT if stderr_to_stdout else subprocess.PIPE
result = PopenResult()
p = None
try:
p = subprocess.Popen(commands, cwd=cwd, shell=False, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout=subprocess.PIPE, stderr=stderr_param)
except OSError as e:
raise BuildException("OSError while trying to execute " +
' '.join(commands) + ': ' + str(e))
if not stderr_to_stdout and options.verbose:
stderr_queue = Queue()
stderr_reader = AsynchronousFileReader(p.stderr, stderr_queue)
while not stderr_reader.eof():
while not stderr_queue.empty():
line = stderr_queue.get()
sys.stderr.write(line)
sys.stderr.flush()
time.sleep(0.1)
stdout_queue = Queue()
stdout_reader = AsynchronousFileReader(p.stdout, stdout_queue)

View File

@ -726,7 +726,8 @@ def extract_pubkey():
'-alias', config['repo_keyalias'],
'-keystore', config['keystore'],
'-storepass:file', config['keystorepassfile']]
+ config['smartcardoptions'], output=False)
+ config['smartcardoptions'],
output=False, stderr_to_stdout=False)
if p.returncode != 0 or len(p.output) < 20:
msg = "Failed to get repo pubkey!"
if config['keystore'] == 'NONE':

View File

@ -149,6 +149,14 @@ class CommonTest(unittest.TestCase):
self.assertIsNotNone(re.search('android:versionName="%s"' % build.version, filedata))
self.assertIsNotNone(re.search('android:versionCode="%s"' % build.vercode, filedata))
def test_fdroid_popen_stderr_redirect(self):
commands = ['sh', '-c', 'echo stdout message && echo stderr message 1>&2']
p = fdroidserver.common.FDroidPopen(commands)
self.assertEqual(p.output, 'stdout message\nstderr message\n')
p = fdroidserver.common.FDroidPopen(commands, stderr_to_stdout=False)
self.assertEqual(p.output, 'stdout message\n')
if __name__ == "__main__":
parser = optparse.OptionParser()