mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 15:13:27 +02:00
Simplify some file logic with "with"
This commit is contained in:
parent
2894786ec9
commit
6fe8d96e85
@ -1097,9 +1097,8 @@ def main():
|
|||||||
build_succeeded.append(app)
|
build_succeeded.append(app)
|
||||||
wikilog = "Build succeeded"
|
wikilog = "Build succeeded"
|
||||||
except BuildException as be:
|
except BuildException as be:
|
||||||
logfile = open(os.path.join(log_dir, appid + '.log'), 'a+')
|
with open(os.path.join(log_dir, appid + '.log'), 'a+') as f:
|
||||||
logfile.write(str(be))
|
f.write(str(be))
|
||||||
logfile.close()
|
|
||||||
print("Could not build app %s due to BuildException: %s" % (appid, be))
|
print("Could not build app %s due to BuildException: %s" % (appid, be))
|
||||||
if options.stop:
|
if options.stop:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -1247,9 +1247,8 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
|
|||||||
props = ""
|
props = ""
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
logging.info("Updating local.properties file at %s" % path)
|
logging.info("Updating local.properties file at %s" % path)
|
||||||
f = open(path, 'r')
|
with open(path, 'r') as f:
|
||||||
props += f.read()
|
props += f.read()
|
||||||
f.close()
|
|
||||||
props += '\n'
|
props += '\n'
|
||||||
else:
|
else:
|
||||||
logging.info("Creating local.properties file at %s" % path)
|
logging.info("Creating local.properties file at %s" % path)
|
||||||
@ -1269,9 +1268,8 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
|
|||||||
# Add java.encoding if necessary
|
# Add java.encoding if necessary
|
||||||
if build['encoding']:
|
if build['encoding']:
|
||||||
props += "java.encoding=%s\n" % build['encoding']
|
props += "java.encoding=%s\n" % build['encoding']
|
||||||
f = open(path, 'w')
|
with open(path, 'w') as f:
|
||||||
f.write(props)
|
f.write(props)
|
||||||
f.close()
|
|
||||||
|
|
||||||
flavours = []
|
flavours = []
|
||||||
if build['type'] == 'gradle':
|
if build['type'] == 'gradle':
|
||||||
|
@ -200,22 +200,21 @@ def main():
|
|||||||
count)
|
count)
|
||||||
alldownloads += count
|
alldownloads += count
|
||||||
lst.append("ALL " + str(alldownloads))
|
lst.append("ALL " + str(alldownloads))
|
||||||
f = open('stats/total_downloads_app.txt', 'w')
|
with open('stats/total_downloads_app.txt', 'w') as f:
|
||||||
f.write('# Total downloads by application, since October 2011\n')
|
f.write('# Total downloads by application, since October 2011\n')
|
||||||
for line in sorted(lst):
|
for line in sorted(lst):
|
||||||
f.write(line + '\n')
|
f.write(line + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
f = open('stats/total_downloads_app_version.txt', 'w')
|
|
||||||
f.write('# Total downloads by application and version, '
|
|
||||||
'since October 2011\n')
|
|
||||||
lst = []
|
lst = []
|
||||||
for appver in appsvercount:
|
for appver in appsvercount:
|
||||||
count = appsvercount[appver]
|
count = appsvercount[appver]
|
||||||
lst.append(appver + " " + str(count))
|
lst.append(appver + " " + str(count))
|
||||||
for line in sorted(lst):
|
|
||||||
f.write(line + "\n")
|
with open('stats/total_downloads_app_version.txt', 'w') as f:
|
||||||
f.close()
|
f.write('# Total downloads by application and version, '
|
||||||
|
'since October 2011\n')
|
||||||
|
for line in sorted(lst):
|
||||||
|
f.write(line + "\n")
|
||||||
|
|
||||||
# Calculate and write stats for repo types...
|
# Calculate and write stats for repo types...
|
||||||
logging.info("Processing repo types...")
|
logging.info("Processing repo types...")
|
||||||
@ -225,10 +224,9 @@ def main():
|
|||||||
if rtype == 'srclib':
|
if rtype == 'srclib':
|
||||||
rtype = common.getsrclibvcs(app['Repo'])
|
rtype = common.getsrclibvcs(app['Repo'])
|
||||||
repotypes[rtype] += 1
|
repotypes[rtype] += 1
|
||||||
f = open('stats/repotypes.txt', 'w')
|
with open('stats/repotypes.txt', 'w') as f:
|
||||||
for rtype, count in repotypes.most_common():
|
for rtype, count in repotypes.most_common():
|
||||||
f.write(rtype + ' ' + str(count) + '\n')
|
f.write(rtype + ' ' + str(count) + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Calculate and write stats for update check modes...
|
# Calculate and write stats for update check modes...
|
||||||
logging.info("Processing update check modes...")
|
logging.info("Processing update check modes...")
|
||||||
@ -240,20 +238,18 @@ def main():
|
|||||||
if checkmode.startswith('Tags '):
|
if checkmode.startswith('Tags '):
|
||||||
checkmode = checkmode[:4]
|
checkmode = checkmode[:4]
|
||||||
ucms[checkmode] += 1
|
ucms[checkmode] += 1
|
||||||
f = open('stats/update_check_modes.txt', 'w')
|
with open('stats/update_check_modes.txt', 'w') as f:
|
||||||
for checkmode, count in ucms.most_common():
|
for checkmode, count in ucms.most_common():
|
||||||
f.write(checkmode + ' ' + str(count) + '\n')
|
f.write(checkmode + ' ' + str(count) + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
logging.info("Processing categories...")
|
logging.info("Processing categories...")
|
||||||
ctgs = Counter()
|
ctgs = Counter()
|
||||||
for app in metaapps:
|
for app in metaapps:
|
||||||
for category in app['Categories']:
|
for category in app['Categories']:
|
||||||
ctgs[category] += 1
|
ctgs[category] += 1
|
||||||
f = open('stats/categories.txt', 'w')
|
with open('stats/categories.txt', 'w') as f:
|
||||||
for category, count in ctgs.most_common():
|
for category, count in ctgs.most_common():
|
||||||
f.write(category + ' ' + str(count) + '\n')
|
f.write(category + ' ' + str(count) + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
logging.info("Processing antifeatures...")
|
logging.info("Processing antifeatures...")
|
||||||
afs = Counter()
|
afs = Counter()
|
||||||
@ -263,10 +259,9 @@ def main():
|
|||||||
antifeatures = [a.strip() for a in app['AntiFeatures'].split(',')]
|
antifeatures = [a.strip() for a in app['AntiFeatures'].split(',')]
|
||||||
for antifeature in antifeatures:
|
for antifeature in antifeatures:
|
||||||
afs[antifeature] += 1
|
afs[antifeature] += 1
|
||||||
f = open('stats/antifeatures.txt', 'w')
|
with open('stats/antifeatures.txt', 'w') as f:
|
||||||
for antifeature, count in afs.most_common():
|
for antifeature, count in afs.most_common():
|
||||||
f.write(antifeature + ' ' + str(count) + '\n')
|
f.write(antifeature + ' ' + str(count) + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Calculate and write stats for licenses...
|
# Calculate and write stats for licenses...
|
||||||
logging.info("Processing licenses...")
|
logging.info("Processing licenses...")
|
||||||
@ -274,26 +269,23 @@ def main():
|
|||||||
for app in metaapps:
|
for app in metaapps:
|
||||||
license = app['License']
|
license = app['License']
|
||||||
licenses[license] += 1
|
licenses[license] += 1
|
||||||
f = open('stats/licenses.txt', 'w')
|
with open('stats/licenses.txt', 'w') as f:
|
||||||
for license, count in licenses.most_common():
|
for license, count in licenses.most_common():
|
||||||
f.write(license + ' ' + str(count) + '\n')
|
f.write(license + ' ' + str(count) + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Write list of disabled apps...
|
# Write list of disabled apps...
|
||||||
logging.info("Processing disabled apps...")
|
logging.info("Processing disabled apps...")
|
||||||
disabled = [a['id'] for a in allmetaapps if a['Disabled']]
|
disabled = [a['id'] for a in allmetaapps if a['Disabled']]
|
||||||
f = open('stats/disabled_apps.txt', 'w')
|
with open('stats/disabled_apps.txt', 'w') as f:
|
||||||
for appid in sorted(disabled):
|
for appid in sorted(disabled):
|
||||||
f.write(appid + '\n')
|
f.write(appid + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Write list of latest apps added to the repo...
|
# Write list of latest apps added to the repo...
|
||||||
logging.info("Processing latest apps...")
|
logging.info("Processing latest apps...")
|
||||||
latest = knownapks.getlatest(10)
|
latest = knownapks.getlatest(10)
|
||||||
f = open('stats/latestapps.txt', 'w')
|
with open('stats/latestapps.txt', 'w') as f:
|
||||||
for appid in latest:
|
for appid in latest:
|
||||||
f.write(appid + '\n')
|
f.write(appid + '\n')
|
||||||
f.close()
|
|
||||||
|
|
||||||
if unknownapks:
|
if unknownapks:
|
||||||
logging.info('\nUnknown apks:')
|
logging.info('\nUnknown apks:')
|
||||||
|
@ -572,9 +572,8 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
icondest = os.path.join(icon_dir, iconfilename)
|
icondest = os.path.join(icon_dir, iconfilename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
iconfile = open(icondest, 'wb')
|
with open(icondest, 'wb') as f:
|
||||||
iconfile.write(apk.read(iconsrc))
|
f.write(apk.read(iconsrc))
|
||||||
iconfile.close()
|
|
||||||
thisinfo['icons'][density] = iconfilename
|
thisinfo['icons'][density] = iconfilename
|
||||||
|
|
||||||
except:
|
except:
|
||||||
@ -587,9 +586,8 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
|||||||
iconsrc = thisinfo['icons_src']['-1']
|
iconsrc = thisinfo['icons_src']['-1']
|
||||||
iconpath = os.path.join(
|
iconpath = os.path.join(
|
||||||
get_icon_dir(repodir, None), iconfilename)
|
get_icon_dir(repodir, None), iconfilename)
|
||||||
iconfile = open(iconpath, 'wb')
|
with open(iconpath, 'wb') as f:
|
||||||
iconfile.write(apk.read(iconsrc))
|
f.write(apk.read(iconsrc))
|
||||||
iconfile.close()
|
|
||||||
try:
|
try:
|
||||||
im = Image.open(iconpath)
|
im = Image.open(iconpath)
|
||||||
dpi = px_to_dpi(im.size[0])
|
dpi = px_to_dpi(im.size[0])
|
||||||
@ -923,13 +921,13 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
|||||||
os.remove(siglinkname)
|
os.remove(siglinkname)
|
||||||
os.symlink(sigfile_path, siglinkname)
|
os.symlink(sigfile_path, siglinkname)
|
||||||
|
|
||||||
of = open(os.path.join(repodir, 'index.xml'), 'wb')
|
|
||||||
if options.pretty:
|
if options.pretty:
|
||||||
output = doc.toprettyxml()
|
output = doc.toprettyxml()
|
||||||
else:
|
else:
|
||||||
output = doc.toxml()
|
output = doc.toxml()
|
||||||
of.write(output)
|
|
||||||
of.close()
|
with open(os.path.join(repodir, 'index.xml'), 'wb') as f:
|
||||||
|
f.write(output)
|
||||||
|
|
||||||
if 'repo_keyalias' in config:
|
if 'repo_keyalias' in config:
|
||||||
|
|
||||||
@ -975,9 +973,8 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
|||||||
catdata = ''
|
catdata = ''
|
||||||
for cat in categories:
|
for cat in categories:
|
||||||
catdata += cat + '\n'
|
catdata += cat + '\n'
|
||||||
f = open(os.path.join(repodir, 'categories.txt'), 'w')
|
with open(os.path.join(repodir, 'categories.txt'), 'w') as f:
|
||||||
f.write(catdata)
|
f.write(catdata)
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversions):
|
def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversions):
|
||||||
@ -1278,9 +1275,8 @@ def main():
|
|||||||
if app['icon'] is not None:
|
if app['icon'] is not None:
|
||||||
data += app['icon'] + "\t"
|
data += app['icon'] + "\t"
|
||||||
data += app['License'] + "\n"
|
data += app['License'] + "\n"
|
||||||
f = open(os.path.join(repodirs[0], 'latestapps.dat'), 'w')
|
with open(os.path.join(repodirs[0], 'latestapps.dat'), 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
|
||||||
|
|
||||||
if cachechanged:
|
if cachechanged:
|
||||||
with open(apkcachefile, 'wb') as cf:
|
with open(apkcachefile, 'wb') as cf:
|
||||||
|
Loading…
Reference in New Issue
Block a user