chiark / gitweb /
Apply some autopep8-python2 suggestions
[fdroidserver.git] / fdroidserver / stats.py
index ff3a43b977effd6bea7109003f9ec6750715abdf..ef80fe4d0e0811204101af0fb24c11a6019f3907 100644 (file)
@@ -71,7 +71,7 @@ def main():
         sys.exit(1)
 
     # Get all metadata-defined apps...
-    metaapps = metadata.read_metadata()
+    metaapps = [a for a in metadata.read_metadata().itervalues() if not a['Disabled']]
 
     statsdir = 'stats'
     logsdir = os.path.join(statsdir, 'logs')
@@ -91,8 +91,8 @@ def main():
             logging.info('Retrieving logs')
             ssh = paramiko.SSHClient()
             ssh.load_system_host_keys()
-            ssh.connect('f-droid.org', username='fdroid', timeout=10,
-                        key_filename=config['webserver_keyfile'])
+            ssh.connect(config['stats_server'], username=config['stats_user'],
+                        timeout=10, key_filename=config['webserver_keyfile'])
             ftp = ssh.open_sftp()
             ftp.get_channel().settimeout(60)
             logging.info("...connected")
@@ -149,25 +149,31 @@ def main():
                     'apps': Counter(),
                     'appsver': Counter(),
                     'unknown': []
-                    }
+                }
 
                 p = subprocess.Popen(["zcat", logfile], stdout=subprocess.PIPE)
                 matches = (logsearch(line) for line in p.stdout)
                 for match in matches:
-                    if match and match.group('statuscode') == '200':
-                        uri = match.group('uri')
-                        if uri.endswith('.apk'):
-                            _, apkname = os.path.split(uri)
-                            app = knownapks.getapp(apkname)
-                            if app:
-                                appid, _ = app
-                                today['apps'][appid] += 1
-                                # Strip the '.apk' from apkname
-                                appver = apkname[:-4]
-                                today['appsver'][appver] += 1
-                            else:
-                                if apkname not in today['unknown']:
-                                    today['unknown'].append(apkname)
+                    if not match:
+                        continue
+                    if match.group('statuscode') != '200':
+                        continue
+                    if match.group('ip') in config['stats_ignore']:
+                        continue
+                    uri = match.group('uri')
+                    if not uri.endswith('.apk'):
+                        continue
+                    _, apkname = os.path.split(uri)
+                    app = knownapks.getapp(apkname)
+                    if app:
+                        appid, _ = app
+                        today['apps'][appid] += 1
+                        # Strip the '.apk' from apkname
+                        appver = apkname[:-4]
+                        today['appsver'][appver] += 1
+                    else:
+                        if apkname not in today['unknown']:
+                            today['unknown'].append(apkname)
 
                 # Save calculated aggregate data for today to cache
                 with open(agg_path, 'w') as f:
@@ -214,13 +220,9 @@ def main():
     logging.info("Processing repo types...")
     repotypes = Counter()
     for app in metaapps:
-        if len(app['Repo Type']) == 0:
-            rtype = 'none'
-        else:
-            if app['Repo Type'] == 'srclib':
-                rtype = common.getsrclibvcs(app['Repo'])
-            else:
-                rtype = app['Repo Type']
+        rtype = app['Repo Type'] or 'none'
+        if rtype == 'srclib':
+            rtype = common.getsrclibvcs(app['Repo'])
         repotypes[rtype] += 1
     f = open('stats/repotypes.txt', 'w')
     for rtype in repotypes: