publish: convert to black code format

This commit is contained in:
Hans-Christoph Steiner 2025-03-19 21:33:39 +01:00
parent 68fad5c7f7
commit 8f351d8406
3 changed files with 48 additions and 29 deletions

View File

@ -347,7 +347,6 @@ def main():
glob.glob(os.path.join(unsigned_dir, '*.apk'))
+ glob.glob(os.path.join(unsigned_dir, '*.zip'))
):
appid, vercode = common.publishednameinfo(apkfile)
apkfilename = os.path.basename(apkfile)
if vercodes and appid not in vercodes:
@ -371,7 +370,6 @@ def main():
if b.get("versionCode") == vercode:
build = b
if app.Binaries or (build and build.binary):
# It's an app where we build from source, and verify the apk
# contents against a developer's binary, and then publish their
# version if everything checks out.
@ -382,15 +380,21 @@ def main():
srcapk = srcapk.replace(unsigned_dir, binaries_dir)
if not os.path.isfile(srcapk):
logging.error("...reference binary missing - publish skipped: "
"'{refpath}'".format(refpath=srcapk))
logging.error(
"...reference binary missing - publish skipped: '{refpath}'".format(
refpath=srcapk
)
)
failed += 1
else:
# Compare our unsigned one with the downloaded one...
compare_result = common.verify_apks(srcapk, apkfile, tmp_dir)
if compare_result:
logging.error("...verification failed - publish skipped : "
"{result}".format(result=compare_result))
logging.error(
"...verification failed - publish skipped : {result}".format(
result=compare_result
)
)
failed += 1
else:
# Success! So move the downloaded file to the repo, and remove
@ -402,7 +406,6 @@ def main():
logging.info('Published ' + apkfilename)
elif apkfile.endswith('.zip'):
# OTA ZIPs built by fdroid do not need to be signed by jarsigner,
# just to be moved into place in the repo
shutil.move(apkfile, os.path.join(output_dir, apkfilename))
@ -410,7 +413,6 @@ def main():
logging.info('Published ' + apkfilename)
else:
# It's a 'normal' app, i.e. we sign and publish it...
skipsigning = False
@ -449,10 +451,11 @@ def main():
signed_apk_path = os.path.join(output_dir, apkfilename)
if os.path.exists(signed_apk_path):
raise BuildException("Refusing to sign '{0}' file exists in both "
"{1} and {2} folder.".format(apkfilename,
unsigned_dir,
output_dir))
raise BuildException(
_(
"Refusing to sign '{path}' file exists in both {dir1} and {dir2} folder."
).format(path=apkfilename, dir1=unsigned_dir, dir2=output_dir)
)
# Sign the application...
common.sign_apk(apkfile, signed_apk_path, keyalias)

View File

@ -40,7 +40,6 @@ force-exclude = '''(
| fdroidserver/index\.py
| fdroidserver/metadata\.py
| fdroidserver/nightly\.py
| fdroidserver/publish\.py
| fdroidserver/update\.py
| fdroidserver/vmtools\.py
| locale/pick-complete-translations\.py
@ -50,7 +49,6 @@ force-exclude = '''(
| tests/openssl-version-check-test\.py
| tests/valid-package-names/test\.py
| tests/test_common\.py
| tests/test_publish\.py
| tests/test_signatures\.py
| tests/test_update\.py
)$'''

View File

@ -131,7 +131,7 @@ class PublishTest(unittest.TestCase):
publish.config['keypass'] = '123456'
publish.config['keystore'] = os.path.join(basedir, 'dummy-keystore.jks')
publish.config['repo_keyalias'] = 'repokey'
publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad'
os.chdir(self.testdir)
publish.store_publish_signer_fingerprints({}, indent=2)
@ -154,10 +154,16 @@ class PublishTest(unittest.TestCase):
with open(os.path.join(metadata_dir, 'com.politedroid.yml'), 'a') as fp:
fp.write('\nBinaries: https://placeholder/foo%v.apk\n')
os.mkdir(os.path.join(self.testdir, 'unsigned'))
shutil.copy('repo/com.politedroid_6.apk', os.path.join(self.testdir, 'unsigned'))
shutil.copy(
'repo/com.politedroid_6.apk', os.path.join(self.testdir, 'unsigned')
)
os.mkdir(os.path.join(self.testdir, 'unsigned', 'binaries'))
shutil.copy('repo/com.politedroid_6.apk',
os.path.join(self.testdir, 'unsigned', 'binaries', 'com.politedroid_6.binary.apk'))
shutil.copy(
'repo/com.politedroid_6.apk',
os.path.join(
self.testdir, 'unsigned', 'binaries', 'com.politedroid_6.binary.apk'
),
)
os.chdir(self.testdir)
with mock.patch.object(sys, 'argv', ['fdroid fakesubcommand']):
@ -201,7 +207,9 @@ class PublishTest(unittest.TestCase):
publish.config['keystorepass'] = '123456'
publish.config['keypass'] = '654321'
publish.config['keystore'] = "keystore.jks"
publish.config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
publish.config[
'keydname'
] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=CA, C=US'
os.chdir(self.testdir)
keystore = jks.KeyStore.new("jks", [])
keystore.save(publish.config['keystore'], publish.config['keystorepass'])
@ -211,7 +219,9 @@ class PublishTest(unittest.TestCase):
self.assertFalse(publish.create_key_if_not_existing("newalias"))
self.assertTrue(publish.create_key_if_not_existing("anotheralias"))
keystore = jks.KeyStore.load(publish.config['keystore'], publish.config['keystorepass'])
keystore = jks.KeyStore.load(
publish.config['keystore'], publish.config['keystorepass']
)
self.assertCountEqual(keystore.private_keys, ["newalias", "anotheralias"])
for alias, pk in keystore.private_keys.items():
self.assertFalse(pk.is_decrypted())
@ -236,7 +246,9 @@ class PublishTest(unittest.TestCase):
publish.status_update_json([], [])
with open('repo/status/publish.json') as fp:
data = json.load(fp)
self.assertEqual(shutil.which(publish.config['apksigner']), data['apksigner'])
self.assertEqual(
shutil.which(publish.config['apksigner']), data['apksigner']
)
publish.config = {}
common.fill_config_defaults(publish.config)
@ -254,13 +266,15 @@ class PublishTest(unittest.TestCase):
common.options = VerboseFalseOptions
config = common.read_config()
if 'apksigner' not in config:
self.skipTest('SKIPPING test_sign_then_implant_signature, apksigner not installed!')
self.skipTest(
'SKIPPING test_sign_then_implant_signature, apksigner not installed!'
)
config['repo_keyalias'] = 'sova'
config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
shutil.copy(basedir / 'keystore.jks', self.testdir)
config['keystore'] = 'keystore.jks'
config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=CA, C=US'
publish.config = config
common.config = config
@ -286,7 +300,9 @@ class PublishTest(unittest.TestCase):
# sign the unsigned APK
self.assertTrue(os.path.exists(unsigned))
self.assertFalse(os.path.exists(signed))
with mock.patch('sys.argv', ['fdroid publish', '%s:%d' % (app.id, versionCode)]):
with mock.patch(
'sys.argv', ['fdroid publish', '%s:%d' % (app.id, versionCode)]
):
publish.main()
self.assertFalse(os.path.exists(unsigned))
self.assertTrue(os.path.exists(signed))
@ -295,7 +311,9 @@ class PublishTest(unittest.TestCase):
signatures.main()
self.assertTrue(
os.path.exists(
os.path.join('metadata', 'org.fdroid.ci', 'signatures', '1', 'MANIFEST.MF')
os.path.join(
'metadata', 'org.fdroid.ci', 'signatures', '1', 'MANIFEST.MF'
)
)
)
os.remove(signed)
@ -304,7 +322,9 @@ class PublishTest(unittest.TestCase):
shutil.copy(testapk, unsigned)
self.assertTrue(os.path.exists(unsigned))
self.assertFalse(os.path.exists(signed))
with mock.patch('sys.argv', ['fdroid publish', '%s:%d' % (app.id, versionCode)]):
with mock.patch(
'sys.argv', ['fdroid publish', '%s:%d' % (app.id, versionCode)]
):
publish.main()
self.assertFalse(os.path.exists(unsigned))
self.assertTrue(os.path.exists(signed))
@ -336,9 +356,7 @@ class PublishTest(unittest.TestCase):
config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
shutil.copy(basedir / 'keystore.jks', self.testdir)
config['keystore'] = 'keystore.jks'
config[
'keydname'
] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=CA, C=US'
publish.config = config
common.config = config