summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2013-05-26 09:08:49 -0400
committerDonald Stufft <donald@stufft.io>2013-05-26 09:08:49 -0400
commite70e793ebd75f13729472356e3bdf4f7644b6368 (patch)
treefac9a0f3a03e05293f6c147fc9551b31e106bc0c /tools
parent79d5868f62141080e1c91965711391ccf78c3d1e (diff)
downloaddecorator-e70e793ebd75f13729472356e3bdf4f7644b6368.tar.gz
Only create the connection to the PostgreSQL server once
Diffstat (limited to 'tools')
-rwxr-xr-xtools/integratestats28
1 files changed, 14 insertions, 14 deletions
diff --git a/tools/integratestats b/tools/integratestats
index 0800401..58ac7e1 100755
--- a/tools/integratestats
+++ b/tools/integratestats
@@ -5,23 +5,13 @@ import apache_stats
statsdir = '/data/www/pypi/stats'
-def integrate(config, data):
- # Setup database connection
- c = ConfigParser.ConfigParser({'user':'', 'password':''})
- c.read(config)
- dbname = c.get('database', 'name')
- dbuser = c.get('database', 'user')
- dbpass = c.get('database', 'password')
- dbhost = c.get('database', 'host')
- dbconn = psycopg2.connect(database=dbname, user=dbuser, password=dbpass, host=dbhost)
- cursor = dbconn.cursor()
+def integrate(config, data, dbconn):
for (filename, browser, package), count in data.items():
cursor.execute('update release_files set downloads=downloads+%s where filename=%s',
(count, filename))
dbconn.commit()
- dbconn.close()
-def integrate_remote(config, host, dbupdate=True):
+def integrate_remote(config, host, dbconn, dbupdate=True):
url = 'http://%s.pypi.python.org/local-stats/days/' % host
try:
index = urllib.urlopen(url).read()
@@ -50,11 +40,20 @@ def integrate_remote(config, host, dbupdate=True):
delta = stats.integrate_stats(statsdir, year, month, day, data)
if dbupdate:
# database integration
- integrate(config, delta)
+ integrate(config, delta, dbconn=dbconn)
integrated.add(m)
open(statsdir+'/integrated/'+host, 'w').write('\n'.join(sorted(integrated)))
def main():
+ # Setup database connection
+ c = ConfigParser.ConfigParser({'user':'', 'password':''})
+ c.read(config)
+ dbname = c.get('database', 'name')
+ dbuser = c.get('database', 'user')
+ dbpass = c.get('database', 'password')
+ dbhost = c.get('database', 'host')
+ dbconn = psycopg2.connect(database=dbname, user=dbuser, password=dbpass, host=dbhost)
+
lasts = socket.gethostbyname_ex('last.pypi.python.org')
# look for name X.pypi.python.org
lasts = [lasts[0]] + lasts[1]
@@ -70,10 +69,11 @@ def main():
# This is just a CNAME back to a.pypi.python.org
continue
- integrate_remote(sys.argv[1], host)
+ integrate_remote(sys.argv[1], host, dbconn=dbconn)
if host == last:
break
host = chr(ord(host)+1)
+ dbconn.close()
main()