curs = connection.cursor()
curs.execute("SELECT pg_try_advisory_lock(2896719)")
if not curs.fetchall()[0][0]:
- print "Failed to get advisory lock, existing cleanup_old_records process stuck?"
+ print("Failed to get advisory lock, existing cleanup_old_records process stuck?")
sys.exit(1)
# Clean up old email change tokens
session = Session.objects.get(session_key=options['sessionid']).get_decoded()
uid = session.get('_auth_user_id')
- print u"Session {0}".format(options['sessionid'])
+ print("Session {0}".format(options['sessionid']))
try:
user = User.objects.get(pk=uid)
- print " -- Logged in user --"
- print u"Userid: {0}".format(uid)
- print u"Username: {0}".format(user.username)
- print u"Name: {0}".format(user.get_full_name())
- print u"Email: {0}".format(user.email)
+ print(" -- Logged in user --")
+ print("Userid: {0}".format(uid))
+ print("Username: {0}".format(user.username))
+ print("Name: {0}".format(user.get_full_name()))
+ print("Email: {0}".format(user.email))
except User.DoesNotExist:
- print "** Associated user not found. Maybe not logged in?"
+ print("** Associated user not found. Maybe not logged in?")
# Remove known keys
for k in ('_auth_user_id', '_auth_user_hash', '_auth_user_backend'):
session.pop(k, None)
if session:
- print " -- Other session values --"
- for k, v in session.items():
- print u"{0:20} {1}".format(k, v)
+ print(" -- Other session values --")
+ for k, v in list(session.items()):
+ print("{0:20} {1}".format(k, v))
except Session.DoesNotExist:
raise CommandError('Session not found')
# Add any groups necessary
curs.execute("INSERT INTO lists_mailinglistgroup (groupname, sortkey) SELECT n,50 FROM UNNEST(%s) n(n) WHERE NOT EXISTS (SELECT 1 FROM lists_mailinglistgroup WHERE groupname=n) RETURNING groupname", (allgroups,))
for n, in curs.fetchall():
- print "Added group %s" % n
+ print("Added group %s" % n)
# Add and update lists
for l in j:
if curs.rowcount == 0:
curs.execute("INSERT INTO lists_mailinglist (listname, group_id, active, description, shortdesc) VALUES (%s, (SELECT id FROM lists_mailinglistgroup WHERE groupname=%s), %s, %s, %s)", (
l['name'], l['group'], l['active'], l['description'], l['shortdesc']))
- print "Added list %s" % l['name']
+ print("Added list %s" % l['name'])
else:
curs.execute("UPDATE lists_mailinglist SET group_id=(SELECT id FROM lists_mailinglistgroup WHERE groupname=%s), active=%s, description=%s, shortdesc=%s WHERE listname=%s AND NOT (group_id=(SELECT id FROM lists_mailinglistgroup WHERE groupname=%s) AND active=%s AND description=%s AND shortdesc=%s) RETURNING listname", (
l['group'], l['active'], l['description'], l['shortdesc'],
l['group'], l['active'], l['description'], l['shortdesc'],
))
for n, in curs.fetchall():
- print "Updated list %s" % n
+ print("Updated list %s" % n)
# Delete any lists that shouldn't exist anymore (this is safe because we don't keep any data about them,
# so they are trivial to add back)
curs.execute("DELETE FROM lists_mailinglist WHERE NOT listname=ANY(%s) RETURNING listname", ([l['name'] for l in j],))
for n, in curs.fetchall():
- print "Deleted list %s" % n
+ print("Deleted list %s" % n)
# Delete listgroups
curs.execute("DELETE FROM lists_mailinglistgroup WHERE NOT groupname=ANY(%s) RETURNING groupname", (allgroups,))
for n, in curs.fetchall():
- print "Deleted group %s" % n
+ print("Deleted group %s" % n)
if options['dryrun']:
raise CommandError("Dry run, rolling back")
fetch_response = oauth.fetch_request_token('https://api.twitter.com/oauth/request_token')
authorization_url = oauth.authorization_url('https://api.twitter.com/oauth/authorize')
- print 'Please go here and authorize: %s' % authorization_url
+ print('Please go here and authorize: %s' % authorization_url)
- pin = raw_input('Paste the PIN here: ')
+ pin = input('Paste the PIN here: ')
oauth = requests_oauthlib.OAuth1Session(settings.TWITTER_CLIENT,
settings.TWITTER_CLIENTSECRET,
import base64
if __name__ == "__main__":
- print "The next row contains a 32-byte (256-bit) symmetric crypto key."
- print "This key should be used to integrate a community auth site."
- print "Note that each site should have it's own key!!"
- print ""
+ print("The next row contains a 32-byte (256-bit) symmetric crypto key.")
+ print("This key should be used to integrate a community auth site.")
+ print("Note that each site should have it's own key!!")
+ print("")
r = Random.new()
key = r.read(32)
sys.exit(1)
if not options.key:
- options.key = raw_input("Enter key (BASE64 encoded): ")
+ options.key = input("Enter key (BASE64 encoded): ")
if not options.user:
- options.user = raw_input("Enter username: ")
+ options.user = input("Enter username: ")
if not options.first:
options.first = "FirstName"
if not options.last:
else:
title = ""
if not quiet:
- print "--- file: %s (%s) ---" % (filename, title)
+ print("--- file: %s (%s) ---" % (filename, title))
s = tidy.parseString(contents.encode('utf-8'), **tidyopts)
curs.execute("INSERT INTO docs (file, version, title, content) VALUES (%(f)s, %(v)s, %(t)s, %(c)s)", {
config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'docload.ini'))
if not os.path.isfile(tarfilename):
- print "File %s not found" % tarfilename
+ print("File %s not found" % tarfilename)
sys.exit(1)
tf = tarfile.open(tarfilename)
curs.execute("SELECT current FROM core_version WHERE tree=%(v)s", {'v': ver})
r = curs.fetchall()
if len(r) != 1:
- print "Version %s not found in the system, cannot load!" % ver
+ print("Version %s not found in the system, cannot load!" % ver)
sys.exit(1)
iscurrent = r[0][0]
connection.close()
if not quiet:
- print "Done (%i pages)." % pagecount
+ print("Done (%i pages)." % pagecount)
def Usage():
- print "Usage: spider_ftp.py <ftp_root> <pickle_file>"
- print ""
- print "If <pickle_file> starts with http[s]://, the file will be uploaded"
- print "to that URL instead of written to the filesystem."
+ print("Usage: spider_ftp.py <ftp_root> <pickle_file>")
+ print("")
+ print("If <pickle_file> starts with http[s]://, the file will be uploaded")
+ print("to that URL instead of written to the filesystem.")
sys.exit(1)
u = o.open(r)
x = u.read()
if x != "NOT CHANGED" and x != "OK":
- print "Failed to upload: %s" % x
+ print("Failed to upload: %s" % x)
sys.exit(1)
else:
f = open(sys.argv[2] + ".tmp", "wb")
j = json.dumps({'platforms': platforms, 'reporpms': reporpms})
if args.target.startswith('http://') or args.target.startswith('https://'):
- o = urllib2.build_opener(urllib2.HTTPHandler)
- r = urllib2.Request(sys.argv[2], data=j)
+ o = urllib.request.build_opener(urllib.request.HTTPHandler)
+ r = urllib.request.Request(sys.argv[2], data=j)
r.add_header('Content-type', 'application/json')
r.add_header('Host', 'www.postgresql.org')
r.get_method = lambda: 'PUT'
u = o.open(r)
x = u.read()
if x != "NOT CHANGED" and x != "OK":
- print "Failed to upload: %s" % x
+ print("Failed to upload: %s" % x)
sys.exit(1)
else:
with NamedTemporaryFile(dir=os.path.dirname(os.path.abspath(args.target))) as f:
if __name__ == "__main__":
if len(sys.argv) != 2:
- print "Usage: localhtmlvalidate.py <local url>"
+ print("Usage: localhtmlvalidate.py <local url>")
sys.exit(1)
contents = urllib.urlopen(sys.argv[1]).read()
errcode, errmsg, headers = h.getreply()
rbody = h.getfile().read()
if headers['x-w3c-validator-status'] == 'Valid':
- print "Page validates!"
+ print("Page validates!")
sys.exit(0)
elif headers['x-w3c-validator-status'] == 'Invalid':
- print "Invalid!"
- print "Errors: %s" % headers['x-w3c-validator-errors']
- print "Warnings: %s" % headers['x-w3c-validator-warnings']
+ print("Invalid!")
+ print("Errors: %s" % headers['x-w3c-validator-errors'])
+ print("Warnings: %s" % headers['x-w3c-validator-warnings'])
hp = HTMLParser.HTMLParser()
for m in re.findall('<li class="msg_err">.*?</li>', rbody, re.DOTALL):
r = re.search('<em>Line (\d+).*<span class="msg">(.*?)</span>', m, re.DOTALL)
- print "Line %s (should be around %s): %s" % (r.group(1), int(r.group(1)) - firstline, hp.unescape(r.group(2)))
+ print("Line %s (should be around %s): %s" % (r.group(1), int(r.group(1)) - firstline, hp.unescape(r.group(2))))
r2 = re.search('<code class="input">(.*?)<strong title=".*?">(.*?)</strong>(.*?)</code>', unicode(m, 'utf8'), re.DOTALL)
if r2:
- s = u"%s%s%s" % r2.groups()
- print "Source: %s" % hp.unescape(s).encode('utf-8')
- print ""
+ s = "%s%s%s" % r2.groups()
+ print("Source: %s" % hp.unescape(s).encode('utf-8'))
+ print("")
else:
- print "Unknown status: %s" % headers['x-w3c-validator-status']
- print headers
+ print("Unknown status: %s" % headers['x-w3c-validator-status'])
+ print(headers)
sys.exit(1)
# Do one specific month
pieces = month.split("-")
if len(pieces) != 2:
- print "Month format is <y>-<m>, cannot parse '%s'" % month
+ print("Month format is <y>-<m>, cannot parse '%s'" % month)
sys.exit(1)
try:
pieces = [int(x) for x in pieces]
except:
- print "Month format is <y>-<m>, cannot convert '%s' to integers" % month
+ print("Month format is <y>-<m>, cannot convert '%s' to integers" % month)
sys.exit(1)
self.queue.put((listid, listname, pieces[0], pieces[1], -1))
else:
def log(msg):
- print "%s: %s" % (datetime.datetime.now(), msg)
+ print("%s: %s" % (datetime.datetime.now(), msg))
try:
p.join()
except KeyboardInterrupt as e:
- print "Keyboard interrupt, terminating child process!"
+ print("Keyboard interrupt, terminating child process!")
p.terminate()
except Exception as e:
- print "Exception %s, terminating child process!" % e
+ print("Exception %s, terminating child process!" % e)
p.terminate()
(opt, args) = parser.parse_args()
if opt.full and opt.month:
- print "Can't use both full and specific month!"
+ print("Can't use both full and specific month!")
sys.exit(1)
# assign default values
if __name__ == "__main__":
if len(sys.argv) != 2:
- print "Usage: nagios_check.py <dsn>"
+ print("Usage: nagios_check.py <dsn>")
sys.exit(1)
conn = psycopg2.connect(sys.argv[1])
conn.close()
if len(rows) == 0:
- print "OK, queue is empty"
+ print("OK, queue is empty")
sys.exit(0)
age = rows[0][0]
if age < WARNING_THRESHOLD:
- print "OK, queue age is %s" % age
+ print("OK, queue age is %s" % age)
sys.exit(0)
elif age < CRITICAL_THRESHOLD:
- print "WARNING, queue age is %s" % age
+ print("WARNING, queue age is %s" % age)
sys.exit(1)
else:
- print "CRITICAL, queue age is %s" % age
+ print("CRITICAL, queue age is %s" % age)
sys.exit(2)
if __name__ == "__main__":
if len(sys.argv) != 2:
- print "Usage: varnish_queue.py <dsn>"
+ print("Usage: varnish_queue.py <dsn>")
sys.exit(1)
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.INFO)