mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
Remove the rest of the PEP8 errors from stats.py
This commit is contained in:
parent
5849b43e02
commit
bd34fc2530
1 changed files with 23 additions and 16 deletions
|
|
@ -28,10 +28,12 @@ from optparse import OptionParser
|
||||||
import paramiko
|
import paramiko
|
||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import common, metadata
|
import common
|
||||||
|
import metadata
|
||||||
import subprocess
|
import subprocess
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
|
|
||||||
def carbon_send(key, value):
|
def carbon_send(key, value):
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.connect((config['carbon_host'], config['carbon_port']))
|
s.connect((config['carbon_host'], config['carbon_port']))
|
||||||
|
|
@ -42,6 +44,7 @@ def carbon_send(key, value):
|
||||||
options = None
|
options = None
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global options, config
|
global options, config
|
||||||
|
|
@ -55,7 +58,8 @@ def main():
|
||||||
parser.add_option("-d", "--download", action="store_true", default=False,
|
parser.add_option("-d", "--download", action="store_true", default=False,
|
||||||
help="Download logs we don't have")
|
help="Download logs we don't have")
|
||||||
parser.add_option("--recalc", action="store_true", default=False,
|
parser.add_option("--recalc", action="store_true", default=False,
|
||||||
help="Recalculate aggregate stats - use when changes have been made that would invalidate old cached data.")
|
help="Recalculate aggregate stats - use when changes "
|
||||||
|
"have been made that would invalidate old cached data.")
|
||||||
parser.add_option("--nologs", action="store_true", default=False,
|
parser.add_option("--nologs", action="store_true", default=False,
|
||||||
help="Don't do anything logs-related")
|
help="Don't do anything logs-related")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
@ -108,7 +112,7 @@ def main():
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
#Disconnect
|
# Disconnect
|
||||||
if ftp is not None:
|
if ftp is not None:
|
||||||
ftp.close()
|
ftp.close()
|
||||||
if ssh is not None:
|
if ssh is not None:
|
||||||
|
|
@ -122,9 +126,11 @@ def main():
|
||||||
logging.info('Processing logs...')
|
logging.info('Processing logs...')
|
||||||
appscount = Counter()
|
appscount = Counter()
|
||||||
appsvercount = Counter()
|
appsvercount = Counter()
|
||||||
logexpr = '(?P<ip>[.:0-9a-fA-F]+) - - \[(?P<time>.*?)\] "GET (?P<uri>.*?) HTTP/1.\d" (?P<statuscode>\d+) \d+ "(?P<referral>.*?)" "(?P<useragent>.*?)"'
|
logexpr = '(?P<ip>[.:0-9a-fA-F]+) - - \[(?P<time>.*?)\] ' + \
|
||||||
|
'"GET (?P<uri>.*?) HTTP/1.\d" (?P<statuscode>\d+) ' + \
|
||||||
|
'\d+ "(?P<referral>.*?)" "(?P<useragent>.*?)"'
|
||||||
logsearch = re.compile(logexpr).search
|
logsearch = re.compile(logexpr).search
|
||||||
for logfile in glob.glob(os.path.join(logsdir,'access-*.log.gz')):
|
for logfile in glob.glob(os.path.join(logsdir, 'access-*.log.gz')):
|
||||||
logging.debug('...' + logfile)
|
logging.debug('...' + logfile)
|
||||||
|
|
||||||
# Get the date for this log - e.g. 2012-02-28
|
# Get the date for this log - e.g. 2012-02-28
|
||||||
|
|
@ -145,7 +151,7 @@ def main():
|
||||||
'unknown': []
|
'unknown': []
|
||||||
}
|
}
|
||||||
|
|
||||||
p = subprocess.Popen(["zcat", logfile], stdout = subprocess.PIPE)
|
p = subprocess.Popen(["zcat", logfile], stdout=subprocess.PIPE)
|
||||||
matches = (logsearch(line) for line in p.stdout)
|
matches = (logsearch(line) for line in p.stdout)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
if match and match.group('statuscode') == '200':
|
if match and match.group('statuscode') == '200':
|
||||||
|
|
@ -160,7 +166,7 @@ def main():
|
||||||
appver = apkname[:-4]
|
appver = apkname[:-4]
|
||||||
today['appsver'][appver] += 1
|
today['appsver'][appver] += 1
|
||||||
else:
|
else:
|
||||||
if not apkname in today['unknown']:
|
if apkname not in today['unknown']:
|
||||||
today['unknown'].append(apkname)
|
today['unknown'].append(apkname)
|
||||||
|
|
||||||
# Save calculated aggregate data for today to cache
|
# Save calculated aggregate data for today to cache
|
||||||
|
|
@ -173,7 +179,7 @@ def main():
|
||||||
for appid in today['appsver']:
|
for appid in today['appsver']:
|
||||||
appsvercount[appid] += today['appsver'][appid]
|
appsvercount[appid] += today['appsver'][appid]
|
||||||
for uk in today['unknown']:
|
for uk in today['unknown']:
|
||||||
if not uk in unknownapks:
|
if uk not in unknownapks:
|
||||||
unknownapks.append(uk)
|
unknownapks.append(uk)
|
||||||
|
|
||||||
# Calculate and write stats for total downloads...
|
# Calculate and write stats for total downloads...
|
||||||
|
|
@ -183,7 +189,8 @@ def main():
|
||||||
count = appscount[appid]
|
count = appscount[appid]
|
||||||
lst.append(appid + " " + str(count))
|
lst.append(appid + " " + str(count))
|
||||||
if config['stats_to_carbon']:
|
if config['stats_to_carbon']:
|
||||||
carbon_send('fdroid.download.' + appid.replace('.', '_'), count)
|
carbon_send('fdroid.download.' + appid.replace('.', '_'),
|
||||||
|
count)
|
||||||
alldownloads += count
|
alldownloads += count
|
||||||
lst.append("ALL " + str(alldownloads))
|
lst.append("ALL " + str(alldownloads))
|
||||||
f = open('stats/total_downloads_app.txt', 'w')
|
f = open('stats/total_downloads_app.txt', 'w')
|
||||||
|
|
@ -193,7 +200,8 @@ def main():
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = open('stats/total_downloads_app_version.txt', 'w')
|
f = open('stats/total_downloads_app_version.txt', 'w')
|
||||||
f.write('# Total downloads by application and version, since October 2011\n')
|
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]
|
||||||
|
|
@ -290,4 +298,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue