count)
alldownloads += count
lst.append("ALL " + str(alldownloads))
- f = open('stats/total_downloads_app.txt', 'w')
- f.write('# Total downloads by application, since October 2011\n')
- for line in sorted(lst):
- 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')
+ with open('stats/total_downloads_app.txt', 'w') as f:
+ f.write('# Total downloads by application, since October 2011\n')
+ for line in sorted(lst):
+ f.write(line + '\n')
+
lst = []
for appver in appsvercount:
count = appsvercount[appver]
lst.append(appver + " " + str(count))
- for line in sorted(lst):
- f.write(line + "\n")
- f.close()
+
+ with open('stats/total_downloads_app_version.txt', 'w') as f:
+ 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...
logging.info("Processing repo types...")
if rtype == 'srclib':
rtype = common.getsrclibvcs(app['Repo'])
repotypes[rtype] += 1
- f = open('stats/repotypes.txt', 'w')
- for rtype, count in repotypes.most_common():
- f.write(rtype + ' ' + str(count) + '\n')
- f.close()
+ with open('stats/repotypes.txt', 'w') as f:
+ for rtype, count in repotypes.most_common():
+ f.write(rtype + ' ' + str(count) + '\n')
# Calculate and write stats for update check modes...
logging.info("Processing update check modes...")
if checkmode.startswith('Tags '):
checkmode = checkmode[:4]
ucms[checkmode] += 1
- f = open('stats/update_check_modes.txt', 'w')
- for checkmode, count in ucms.most_common():
- f.write(checkmode + ' ' + str(count) + '\n')
- f.close()
+ with open('stats/update_check_modes.txt', 'w') as f:
+ for checkmode, count in ucms.most_common():
+ f.write(checkmode + ' ' + str(count) + '\n')
logging.info("Processing categories...")
ctgs = Counter()
for app in metaapps:
for category in app['Categories']:
ctgs[category] += 1
- f = open('stats/categories.txt', 'w')
- for category, count in ctgs.most_common():
- f.write(category + ' ' + str(count) + '\n')
- f.close()
+ with open('stats/categories.txt', 'w') as f:
+ for category, count in ctgs.most_common():
+ f.write(category + ' ' + str(count) + '\n')
logging.info("Processing antifeatures...")
afs = Counter()
antifeatures = [a.strip() for a in app['AntiFeatures'].split(',')]
for antifeature in antifeatures:
afs[antifeature] += 1
- f = open('stats/antifeatures.txt', 'w')
- for antifeature, count in afs.most_common():
- f.write(antifeature + ' ' + str(count) + '\n')
- f.close()
+ with open('stats/antifeatures.txt', 'w') as f:
+ for antifeature, count in afs.most_common():
+ f.write(antifeature + ' ' + str(count) + '\n')
# Calculate and write stats for licenses...
logging.info("Processing licenses...")
for app in metaapps:
license = app['License']
licenses[license] += 1
- f = open('stats/licenses.txt', 'w')
- for license, count in licenses.most_common():
- f.write(license + ' ' + str(count) + '\n')
- f.close()
+ with open('stats/licenses.txt', 'w') as f:
+ for license, count in licenses.most_common():
+ f.write(license + ' ' + str(count) + '\n')
# Write list of disabled apps...
logging.info("Processing disabled apps...")
disabled = [a['id'] for a in allmetaapps if a['Disabled']]
- f = open('stats/disabled_apps.txt', 'w')
- for appid in sorted(disabled):
- f.write(appid + '\n')
- f.close()
+ with open('stats/disabled_apps.txt', 'w') as f:
+ for appid in sorted(disabled):
+ f.write(appid + '\n')
# Write list of latest apps added to the repo...
logging.info("Processing latest apps...")
latest = knownapks.getlatest(10)
- f = open('stats/latestapps.txt', 'w')
- for appid in latest:
- f.write(appid + '\n')
- f.close()
+ with open('stats/latestapps.txt', 'w') as f:
+ for appid in latest:
+ f.write(appid + '\n')
if unknownapks:
logging.info('\nUnknown apks:')
icondest = os.path.join(icon_dir, iconfilename)
try:
- iconfile = open(icondest, 'wb')
- iconfile.write(apk.read(iconsrc))
- iconfile.close()
+ with open(icondest, 'wb') as f:
+ f.write(apk.read(iconsrc))
thisinfo['icons'][density] = iconfilename
except:
iconsrc = thisinfo['icons_src']['-1']
iconpath = os.path.join(
get_icon_dir(repodir, None), iconfilename)
- iconfile = open(iconpath, 'wb')
- iconfile.write(apk.read(iconsrc))
- iconfile.close()
+ with open(iconpath, 'wb') as f:
+ f.write(apk.read(iconsrc))
try:
im = Image.open(iconpath)
dpi = px_to_dpi(im.size[0])
os.remove(siglinkname)
os.symlink(sigfile_path, siglinkname)
- of = open(os.path.join(repodir, 'index.xml'), 'wb')
if options.pretty:
output = doc.toprettyxml()
else:
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:
catdata = ''
for cat in categories:
catdata += cat + '\n'
- f = open(os.path.join(repodir, 'categories.txt'), 'w')
- f.write(catdata)
- f.close()
+ with open(os.path.join(repodir, 'categories.txt'), 'w') as f:
+ f.write(catdata)
def archive_old_apks(apps, apks, archapks, repodir, archivedir, defaultkeepversions):
if app['icon'] is not None:
data += app['icon'] + "\t"
data += app['License'] + "\n"
- f = open(os.path.join(repodirs[0], 'latestapps.dat'), 'w')
- f.write(data)
- f.close()
+ with open(os.path.join(repodirs[0], 'latestapps.dat'), 'w') as f:
+ f.write(data)
if cachechanged:
with open(apkcachefile, 'wb') as cf: