From f4cbb6b3f88fde1c5bd29d76ef7374f9d2a7d0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 28 Aug 2015 18:26:23 -0700 Subject: [PATCH] Simlify known_apks writing --- fdroidserver/common.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index fe159105..f546020a 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1669,20 +1669,23 @@ class KnownApks: self.changed = False def writeifchanged(self): - if self.changed: - if not os.path.exists('stats'): - os.mkdir('stats') - f = open(self.path, 'w') - lst = [] - for apk, app in self.apks.iteritems(): - appid, added = app - line = apk + ' ' + appid - if added: - line += ' ' + time.strftime('%Y-%m-%d', added) - lst.append(line) + if not self.changed: + return + + if not os.path.exists('stats'): + os.mkdir('stats') + + lst = [] + for apk, app in self.apks.iteritems(): + appid, added = app + line = apk + ' ' + appid + if added: + line += ' ' + time.strftime('%Y-%m-%d', added) + lst.append(line) + + with open(self.path, 'w') as f: for line in sorted(lst): f.write(line + '\n') - f.close() # Record an apk (if it's new, otherwise does nothing) # Returns the date it was added.