mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-14 19:10:11 +01:00
Re-use config and options from common module in index
This commit is contained in:
parent
f9321f6032
commit
389fd7e6c9
@ -37,9 +37,6 @@ from fdroidserver import metadata, signindex, common
|
|||||||
from fdroidserver.common import FDroidPopen, FDroidPopenBytes
|
from fdroidserver.common import FDroidPopen, FDroidPopenBytes
|
||||||
from fdroidserver.metadata import MetaDataException
|
from fdroidserver.metadata import MetaDataException
|
||||||
|
|
||||||
options = None
|
|
||||||
config = None
|
|
||||||
|
|
||||||
|
|
||||||
def make(apps, sortedids, apks, repodir, archive):
|
def make(apps, sortedids, apks, repodir, archive):
|
||||||
"""Generate the repo index files.
|
"""Generate the repo index files.
|
||||||
@ -61,22 +58,22 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||||||
raise MetaDataException("Cannot resolve app id " + appid)
|
raise MetaDataException("Cannot resolve app id " + appid)
|
||||||
|
|
||||||
nosigningkey = False
|
nosigningkey = False
|
||||||
if not options.nosign:
|
if not common.options.nosign:
|
||||||
if 'repo_keyalias' not in config:
|
if 'repo_keyalias' not in common.config:
|
||||||
nosigningkey = True
|
nosigningkey = True
|
||||||
logging.critical("'repo_keyalias' not found in config.py!")
|
logging.critical("'repo_keyalias' not found in config.py!")
|
||||||
if 'keystore' not in config:
|
if 'keystore' not in common.config:
|
||||||
nosigningkey = True
|
nosigningkey = True
|
||||||
logging.critical("'keystore' not found in config.py!")
|
logging.critical("'keystore' not found in config.py!")
|
||||||
if 'keystorepass' not in config and 'keystorepassfile' not in config:
|
if 'keystorepass' not in common.config and 'keystorepassfile' not in common.config:
|
||||||
nosigningkey = True
|
nosigningkey = True
|
||||||
logging.critical("'keystorepass' not found in config.py!")
|
logging.critical("'keystorepass' not found in config.py!")
|
||||||
if 'keypass' not in config and 'keypassfile' not in config:
|
if 'keypass' not in common.config and 'keypassfile' not in common.config:
|
||||||
nosigningkey = True
|
nosigningkey = True
|
||||||
logging.critical("'keypass' not found in config.py!")
|
logging.critical("'keypass' not found in config.py!")
|
||||||
if not os.path.exists(config['keystore']):
|
if not os.path.exists(common.config['keystore']):
|
||||||
nosigningkey = True
|
nosigningkey = True
|
||||||
logging.critical("'" + config['keystore'] + "' does not exist!")
|
logging.critical("'" + common.config['keystore'] + "' does not exist!")
|
||||||
if nosigningkey:
|
if nosigningkey:
|
||||||
logging.warning("`fdroid update` requires a signing key, you can create one using:")
|
logging.warning("`fdroid update` requires a signing key, you can create one using:")
|
||||||
logging.warning("\tfdroid update --create-key")
|
logging.warning("\tfdroid update --create-key")
|
||||||
@ -86,27 +83,27 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||||||
repodict['timestamp'] = datetime.utcnow()
|
repodict['timestamp'] = datetime.utcnow()
|
||||||
repodict['version'] = METADATA_VERSION
|
repodict['version'] = METADATA_VERSION
|
||||||
|
|
||||||
if config['repo_maxage'] != 0:
|
if common.config['repo_maxage'] != 0:
|
||||||
repodict['maxage'] = config['repo_maxage']
|
repodict['maxage'] = common.config['repo_maxage']
|
||||||
|
|
||||||
if archive:
|
if archive:
|
||||||
repodict['name'] = config['archive_name']
|
repodict['name'] = common.config['archive_name']
|
||||||
repodict['icon'] = os.path.basename(config['archive_icon'])
|
repodict['icon'] = os.path.basename(common.config['archive_icon'])
|
||||||
repodict['address'] = config['archive_url']
|
repodict['address'] = common.config['archive_url']
|
||||||
repodict['description'] = config['archive_description']
|
repodict['description'] = common.config['archive_description']
|
||||||
urlbasepath = os.path.basename(urllib.parse.urlparse(config['archive_url']).path)
|
urlbasepath = os.path.basename(urllib.parse.urlparse(common.config['archive_url']).path)
|
||||||
else:
|
else:
|
||||||
repodict['name'] = config['repo_name']
|
repodict['name'] = common.config['repo_name']
|
||||||
repodict['icon'] = os.path.basename(config['repo_icon'])
|
repodict['icon'] = os.path.basename(common.config['repo_icon'])
|
||||||
repodict['address'] = config['repo_url']
|
repodict['address'] = common.config['repo_url']
|
||||||
repodict['description'] = config['repo_description']
|
repodict['description'] = common.config['repo_description']
|
||||||
urlbasepath = os.path.basename(urllib.parse.urlparse(config['repo_url']).path)
|
urlbasepath = os.path.basename(urllib.parse.urlparse(common.config['repo_url']).path)
|
||||||
|
|
||||||
mirrorcheckfailed = False
|
mirrorcheckfailed = False
|
||||||
mirrors = []
|
mirrors = []
|
||||||
for mirror in sorted(config.get('mirrors', [])):
|
for mirror in sorted(common.config.get('mirrors', [])):
|
||||||
base = os.path.basename(urllib.parse.urlparse(mirror).path.rstrip('/'))
|
base = os.path.basename(urllib.parse.urlparse(mirror).path.rstrip('/'))
|
||||||
if config.get('nonstandardwebroot') is not True and base != 'fdroid':
|
if common.config.get('nonstandardwebroot') is not True and base != 'fdroid':
|
||||||
logging.error("mirror '" + mirror + "' does not end with 'fdroid'!")
|
logging.error("mirror '" + mirror + "' does not end with 'fdroid'!")
|
||||||
mirrorcheckfailed = True
|
mirrorcheckfailed = True
|
||||||
# must end with / or urljoin strips a whole path segment
|
# must end with / or urljoin strips a whole path segment
|
||||||
@ -114,7 +111,7 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||||||
mirrors.append(urllib.parse.urljoin(mirror, urlbasepath))
|
mirrors.append(urllib.parse.urljoin(mirror, urlbasepath))
|
||||||
else:
|
else:
|
||||||
mirrors.append(urllib.parse.urljoin(mirror + '/', urlbasepath))
|
mirrors.append(urllib.parse.urljoin(mirror + '/', urlbasepath))
|
||||||
for mirror in config.get('servergitmirrors', []):
|
for mirror in common.config.get('servergitmirrors', []):
|
||||||
mirror = get_raw_mirror(mirror)
|
mirror = get_raw_mirror(mirror)
|
||||||
if mirror is not None:
|
if mirror is not None:
|
||||||
mirrors.append(mirror + '/')
|
mirrors.append(mirror + '/')
|
||||||
@ -142,11 +139,11 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||||||
for command in ('install', 'uninstall'):
|
for command in ('install', 'uninstall'):
|
||||||
packageNames = []
|
packageNames = []
|
||||||
key = command + '_list'
|
key = command + '_list'
|
||||||
if key in config:
|
if key in common.config:
|
||||||
if isinstance(config[key], str):
|
if isinstance(common.config[key], str):
|
||||||
packageNames = [config[key]]
|
packageNames = [common.config[key]]
|
||||||
elif all(isinstance(item, str) for item in config[key]):
|
elif all(isinstance(item, str) for item in common.config[key]):
|
||||||
packageNames = config[key]
|
packageNames = common.config[key]
|
||||||
else:
|
else:
|
||||||
raise TypeError('only accepts strings, lists, and tuples')
|
raise TypeError('only accepts strings, lists, and tuples')
|
||||||
requestsdict[command] = packageNames
|
requestsdict[command] = packageNames
|
||||||
@ -221,10 +218,10 @@ def make_v1(apps, packages, repodir, repodict, requestsdict):
|
|||||||
with open(index_file, 'w') as fp:
|
with open(index_file, 'w') as fp:
|
||||||
json.dump(output, fp, default=_index_encoder_default)
|
json.dump(output, fp, default=_index_encoder_default)
|
||||||
|
|
||||||
if options.nosign:
|
if common.options.nosign:
|
||||||
logging.debug('index-v1 must have a signature, use `fdroid signindex` to create it!')
|
logging.debug('index-v1 must have a signature, use `fdroid signindex` to create it!')
|
||||||
else:
|
else:
|
||||||
signindex.config = config
|
signindex.config = common.config
|
||||||
signindex.sign_index_v1(repodir, json_name)
|
signindex.sign_index_v1(repodir, json_name)
|
||||||
|
|
||||||
|
|
||||||
@ -432,9 +429,9 @@ def make_v0(apps, apks, repodir, repodict, requestsdict):
|
|||||||
addElementNonEmpty('features', ','.join(sorted(apk['features'])), doc, apkel)
|
addElementNonEmpty('features', ','.join(sorted(apk['features'])), doc, apkel)
|
||||||
|
|
||||||
if current_version_file is not None \
|
if current_version_file is not None \
|
||||||
and config['make_current_version_link'] \
|
and common.config['make_current_version_link'] \
|
||||||
and repodir == 'repo': # only create these
|
and repodir == 'repo': # only create these
|
||||||
namefield = config['current_version_name_source']
|
namefield = common.config['current_version_name_source']
|
||||||
sanitized_name = re.sub('''[ '"&%?+=/]''', '', app.get(namefield))
|
sanitized_name = re.sub('''[ '"&%?+=/]''', '', app.get(namefield))
|
||||||
apklinkname = sanitized_name + '.apk'
|
apklinkname = sanitized_name + '.apk'
|
||||||
current_version_path = os.path.join(repodir, current_version_file)
|
current_version_path = os.path.join(repodir, current_version_file)
|
||||||
@ -450,7 +447,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict):
|
|||||||
os.remove(siglinkname)
|
os.remove(siglinkname)
|
||||||
os.symlink(sigfile_path, siglinkname)
|
os.symlink(sigfile_path, siglinkname)
|
||||||
|
|
||||||
if options.pretty:
|
if common.options.pretty:
|
||||||
output = doc.toprettyxml(encoding='utf-8')
|
output = doc.toprettyxml(encoding='utf-8')
|
||||||
else:
|
else:
|
||||||
output = doc.toxml(encoding='utf-8')
|
output = doc.toxml(encoding='utf-8')
|
||||||
@ -458,16 +455,16 @@ def make_v0(apps, apks, repodir, repodict, requestsdict):
|
|||||||
with open(os.path.join(repodir, 'index.xml'), 'wb') as f:
|
with open(os.path.join(repodir, 'index.xml'), 'wb') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
if 'repo_keyalias' in config:
|
if 'repo_keyalias' in common.config:
|
||||||
|
|
||||||
if options.nosign:
|
if common.options.nosign:
|
||||||
logging.info("Creating unsigned index in preparation for signing")
|
logging.info("Creating unsigned index in preparation for signing")
|
||||||
else:
|
else:
|
||||||
logging.info("Creating signed index with this key (SHA256):")
|
logging.info("Creating signed index with this key (SHA256):")
|
||||||
logging.info("%s" % repo_pubkey_fingerprint)
|
logging.info("%s" % repo_pubkey_fingerprint)
|
||||||
|
|
||||||
# Create a jar of the index...
|
# Create a jar of the index...
|
||||||
jar_output = 'index_unsigned.jar' if options.nosign else 'index.jar'
|
jar_output = 'index_unsigned.jar' if common.options.nosign else 'index.jar'
|
||||||
p = FDroidPopen(['jar', 'cf', jar_output, 'index.xml'], cwd=repodir)
|
p = FDroidPopen(['jar', 'cf', jar_output, 'index.xml'], cwd=repodir)
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
logging.critical("Failed to create {0}".format(jar_output))
|
logging.critical("Failed to create {0}".format(jar_output))
|
||||||
@ -475,18 +472,18 @@ def make_v0(apps, apks, repodir, repodict, requestsdict):
|
|||||||
|
|
||||||
# Sign the index...
|
# Sign the index...
|
||||||
signed = os.path.join(repodir, 'index.jar')
|
signed = os.path.join(repodir, 'index.jar')
|
||||||
if options.nosign:
|
if common.options.nosign:
|
||||||
# Remove old signed index if not signing
|
# Remove old signed index if not signing
|
||||||
if os.path.exists(signed):
|
if os.path.exists(signed):
|
||||||
os.remove(signed)
|
os.remove(signed)
|
||||||
else:
|
else:
|
||||||
signindex.config = config
|
signindex.config = common.config
|
||||||
signindex.sign_jar(signed)
|
signindex.sign_jar(signed)
|
||||||
|
|
||||||
# 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')
|
||||||
iconfilename = os.path.join(icon_dir, os.path.basename(config['repo_icon']))
|
iconfilename = os.path.join(icon_dir, os.path.basename(common.config['repo_icon']))
|
||||||
shutil.copyfile(config['repo_icon'], iconfilename)
|
shutil.copyfile(common.config['repo_icon'], iconfilename)
|
||||||
|
|
||||||
|
|
||||||
def extract_pubkey():
|
def extract_pubkey():
|
||||||
@ -494,18 +491,18 @@ def extract_pubkey():
|
|||||||
Extracts and returns the repository's public key from the keystore.
|
Extracts and returns the repository's public key from the keystore.
|
||||||
:return: public key in hex, repository fingerprint
|
:return: public key in hex, repository fingerprint
|
||||||
"""
|
"""
|
||||||
if 'repo_pubkey' in config:
|
if 'repo_pubkey' in common.config:
|
||||||
pubkey = unhexlify(config['repo_pubkey'])
|
pubkey = unhexlify(common.config['repo_pubkey'])
|
||||||
else:
|
else:
|
||||||
p = FDroidPopenBytes([config['keytool'], '-exportcert',
|
p = FDroidPopenBytes([common.config['keytool'], '-exportcert',
|
||||||
'-alias', config['repo_keyalias'],
|
'-alias', common.config['repo_keyalias'],
|
||||||
'-keystore', config['keystore'],
|
'-keystore', common.config['keystore'],
|
||||||
'-storepass:file', config['keystorepassfile']]
|
'-storepass:file', common.config['keystorepassfile']]
|
||||||
+ config['smartcardoptions'],
|
+ common.config['smartcardoptions'],
|
||||||
output=False, stderr_to_stdout=False)
|
output=False, stderr_to_stdout=False)
|
||||||
if p.returncode != 0 or len(p.output) < 20:
|
if p.returncode != 0 or len(p.output) < 20:
|
||||||
msg = "Failed to get repo pubkey!"
|
msg = "Failed to get repo pubkey!"
|
||||||
if config['keystore'] == 'NONE':
|
if common.config['keystore'] == 'NONE':
|
||||||
msg += ' Is your crypto smartcard plugged in?'
|
msg += ' Is your crypto smartcard plugged in?'
|
||||||
logging.critical(msg)
|
logging.critical(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -1481,10 +1481,6 @@ def main():
|
|||||||
# name comes from there!)
|
# name comes from there!)
|
||||||
sortedids = sorted(apps.keys(), key=lambda appid: apps[appid].Name.upper())
|
sortedids = sorted(apps.keys(), key=lambda appid: apps[appid].Name.upper())
|
||||||
|
|
||||||
# pass options and config for repo index handling
|
|
||||||
index.options = options
|
|
||||||
index.config = config
|
|
||||||
|
|
||||||
# APKs are placed into multiple repos based on the app package, providing
|
# APKs are placed into multiple repos based on the app package, providing
|
||||||
# per-app subscription feeds for nightly builds and things like it
|
# per-app subscription feeds for nightly builds and things like it
|
||||||
if config['per_app_repos']:
|
if config['per_app_repos']:
|
||||||
|
Loading…
Reference in New Issue
Block a user