Skip to content

Instantly share code, notes, and snippets.

@rhelmer
Created August 4, 2011 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rhelmer/1126517 to your computer and use it in GitHub Desktop.
Save rhelmer/1126517 to your computer and use it in GitHub Desktop.
newtcbs
#!/usr/bin/python
import logging, sys
import psycopg2
import socorro.lib.psycopghelper as psy
import socorro.lib.util as util
logger = logging.getLogger("duplicates")
def update(config, targetDate):
functions = [
# function name, parmeters, dependencies
('update_product_versions',[],[]),
('update_signatures', [targetDate],[]),
('update_os_versions', [targetDate],[]),
('update_tcbs', [targetDate], ['update_product_versions', 'update_signatures']),
('update_adu', [targetDate],[])
]
failed = []
databaseDSN = "host=%(databaseHost)s dbname=%(databaseName)s user=%(databaseUserName)s password=%(databasePassword)s" % config
connection = psycopg2.connect(databaseDSN)
cursor = connection.cursor()
for function in functions:
(funcname, parameters, deps) = function
try:
if set(failed).intersection(set(deps)):
print >>sys.stderr, '%s dependency failed. Skipping' % (funcname)
# FIXME what to raise here?
raise
print 'running %s' % funcname
cursor.callproc(funcname, parameters)
if cursor.fetchone() is not True:
failed.append(funcname)
print >>sys.stderr, '%s failed' % (funcname)
connection.commit()
# FIXME what to catch here?
except:
failed.append(funcname)
print >>sys.stderr, '%s failed' % (funcname)
print >>sys.stderr, sys.exc_info()
connection.rollback()
return len(failed)
@lonnen
Copy link

lonnen commented Aug 5, 2011

No need for the cast to a list at line 27.

if set(failed) & set(deps): or if set(failed).intersection(set(deps)): if you want to be really explicit.

@lonnen
Copy link

lonnen commented Aug 5, 2011

Also, this could be DRYed about a bit by having line 33 throw an exception to be caught at line 36.

@lonnen
Copy link

lonnen commented Aug 5, 2011

https://gist.github.com/1128049 <- something like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment