mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-10-08 18:31:07 +03:00
create addElementIfInApk() function for clean up common operation
There are currently a couple different ways this is done in the code, this commit changes all of them to be like addElementNonEmpty().
This commit is contained in:
parent
47d9fd330d
commit
36a585c2fc
1 changed files with 19 additions and 10 deletions
|
@ -883,6 +883,12 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
||||||
return
|
return
|
||||||
addElement(name, value, doc, parent)
|
addElement(name, value, doc, parent)
|
||||||
|
|
||||||
|
def addElementIfInApk(name, apk, key, doc, parent):
|
||||||
|
if key not in apk:
|
||||||
|
return
|
||||||
|
value = str(apk[key])
|
||||||
|
addElement(name, value, doc, parent)
|
||||||
|
|
||||||
def addElementCDATA(name, value, doc, parent):
|
def addElementCDATA(name, value, doc, parent):
|
||||||
el = doc.createElement(name)
|
el = doc.createElement(name)
|
||||||
el.appendChild(doc.createCDATASection(value))
|
el.appendChild(doc.createCDATASection(value))
|
||||||
|
@ -1069,8 +1075,7 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
||||||
addElement('version', apk['version'], doc, apkel)
|
addElement('version', apk['version'], doc, apkel)
|
||||||
addElement('versioncode', str(apk['versioncode']), doc, apkel)
|
addElement('versioncode', str(apk['versioncode']), doc, apkel)
|
||||||
addElement('apkname', apk['apkname'], doc, apkel)
|
addElement('apkname', apk['apkname'], doc, apkel)
|
||||||
if 'srcname' in apk:
|
addElementIfInApk('srcname', apk, 'srcname', doc, apkel)
|
||||||
addElement('srcname', apk['srcname'], doc, apkel)
|
|
||||||
for hash_type in ['sha256']:
|
for hash_type in ['sha256']:
|
||||||
if hash_type not in apk:
|
if hash_type not in apk:
|
||||||
continue
|
continue
|
||||||
|
@ -1081,14 +1086,18 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
||||||
addElement('sig', apk['sig'], doc, apkel)
|
addElement('sig', apk['sig'], doc, apkel)
|
||||||
addElement('size', str(apk['size']), doc, apkel)
|
addElement('size', str(apk['size']), doc, apkel)
|
||||||
addElement('sdkver', str(apk['minSdkVersion']), doc, apkel)
|
addElement('sdkver', str(apk['minSdkVersion']), doc, apkel)
|
||||||
if 'targetSdkVersion' in apk:
|
addElementIfInApk('targetSdkVersion', apk,
|
||||||
addElement('targetSdkVersion', str(apk['targetSdkVersion']), doc, apkel)
|
'targetSdkVersion', doc, apkel)
|
||||||
if 'maxSdkVersion' in apk:
|
addElementIfInApk('maxsdkver', apk,
|
||||||
addElement('maxsdkver', str(apk['maxSdkVersion']), doc, apkel)
|
'maxSdkVersion', doc, apkel)
|
||||||
addElementNonEmpty('obbMainFile', apk.get('obbMainFile'), doc, apkel)
|
addElementIfInApk('obbMainFile', apk,
|
||||||
addElementNonEmpty('obbMainFileSha256', apk.get('obbMainFileSha256'), doc, apkel)
|
'obbMainFile', doc, apkel)
|
||||||
addElementNonEmpty('obbPatchFile', apk.get('obbPatchFile'), doc, apkel)
|
addElementIfInApk('obbMainFileSha256', apk,
|
||||||
addElementNonEmpty('obbPatchFileSha256', apk.get('obbPatchFileSha256'), doc, apkel)
|
'obbMainFileSha256', doc, apkel)
|
||||||
|
addElementIfInApk('obbPatchFile', apk,
|
||||||
|
'obbPatchFile', doc, apkel)
|
||||||
|
addElementIfInApk('obbPatchFileSha256', apk,
|
||||||
|
'obbPatchFileSha256', doc, apkel)
|
||||||
if 'added' in apk:
|
if 'added' in apk:
|
||||||
addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel)
|
addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue