From 2e8deade58a254bcf0ee0be20008344bee49baf5 Mon Sep 17 00:00:00 2001 From: Jonathan Math Date: Fri, 19 Jun 2020 02:29:40 -0400 Subject: [PATCH] 2to3 the rest of utils/ --- utils/archive/check_status.py | 2 +- utils/archive/knight.py | 10 +++++----- utils/archive/memcached_status.py | 16 ++++++++-------- utils/backups/backup_mongo.py | 10 +++++----- utils/backups/backup_psql.py | 4 ++-- utils/backups/backup_redis.py | 2 +- utils/backups/backup_redis_sessions.py | 2 +- utils/backups/backup_redis_story.py | 2 +- utils/backups/copy_mongo_serialized.py | 8 ++++---- utils/backups/s3.py | 8 ++++---- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/utils/archive/check_status.py b/utils/archive/check_status.py index 4ca8b2866..cbad9f317 100644 --- a/utils/archive/check_status.py +++ b/utils/archive/check_status.py @@ -8,6 +8,6 @@ while True: req = requests.get(url) content = req.content end = time.time() - print(" ---> [%s] Retrieved %s bytes - %s %s" % (str(end - start)[:4], len(content), req.status_code, req.reason)) + print((" ---> [%s] Retrieved %s bytes - %s %s" % (str(end - start)[:4], len(content), req.status_code, req.reason))) time.sleep(5) diff --git a/utils/archive/knight.py b/utils/archive/knight.py index 25c86c284..d8b437123 100644 --- a/utils/archive/knight.py +++ b/utils/archive/knight.py @@ -78,7 +78,7 @@ def find_entries(): entries = [] while True: - print " ---> Found %s entries so far. Now on page: %s" % (len(entries), page) + print(" ---> Found %s entries so far. Now on page: %s" % (len(entries), page)) knight_url = "http://newschallenge.tumblr.com/page/%s" % (page) html = requests.get(knight_url).content @@ -135,16 +135,16 @@ def find_entries(): for i, entry in enumerate(entries): is_winner = entry['url'] in winners if is_winner: winner_count += 1 - print " * %s#%s: %s likes - [%s](%s)%s" % ( + print(" * %s#%s: %s likes - [%s](%s)%s" % ( "**" if is_winner else "", i + 1, entry['likes'], entry['title'], entry['url'], - "**" if is_winner else "") + "**" if is_winner else "")) found_entries.append(entry) - print " ***> Found %s active entries among %s total applications with %s/%s winners." % ( - active_entry_count, total_entry_count, winner_count, len(winners)) + print(" ***> Found %s active entries among %s total applications with %s/%s winners." % ( + active_entry_count, total_entry_count, winner_count, len(winners))) return found_entries if __name__ == '__main__': diff --git a/utils/archive/memcached_status.py b/utils/archive/memcached_status.py index 04fce873b..e5be7b37a 100644 --- a/utils/archive/memcached_status.py +++ b/utils/archive/memcached_status.py @@ -7,7 +7,7 @@ from settings import CACHE_BACKEND verbose = False if not CACHE_BACKEND.startswith( 'memcached://' ): - print "you are not configured to use memcched as your django cache backend" + print("you are not configured to use memcched as your django cache backend") else: m = re.search( r'//(.+:\d+)', CACHE_BACKEND ) cache_host = m.group(1) @@ -24,7 +24,7 @@ else: while l.find( 'END' ) < 0 : l = h.readline() if verbose: - print l + print(l) m = pat.match( l ) if m : stats[ m.group(1) ] = m.group(2) @@ -33,15 +33,15 @@ else: h.close_socket() if verbose: - print stats + print(stats) items = int( stats[ 'curr_items' ] ) bytes = int( stats[ 'bytes' ] ) limit_maxbytes = int( stats[ 'limit_maxbytes' ] ) or bytes current_conns = int( stats[ 'curr_connections' ] ) - print "MemCache status for %s" % ( CACHE_BACKEND ) - print "%d items using %d of %d" % ( items, bytes, limit_maxbytes ) - print "%5.2f%% full" % ( 100.0 * bytes / limit_maxbytes ) - print "%d connections being handled" % ( current_conns ) - print \ No newline at end of file + print("MemCache status for %s" % ( CACHE_BACKEND )) + print("%d items using %d of %d" % ( items, bytes, limit_maxbytes )) + print("%5.2f%% full" % ( 100.0 * bytes / limit_maxbytes )) + print("%d connections being handled" % ( current_conns )) + print() \ No newline at end of file diff --git a/utils/backups/backup_mongo.py b/utils/backups/backup_mongo.py index a3a9c72c6..3f01388fb 100644 --- a/utils/backups/backup_mongo.py +++ b/utils/backups/backup_mongo.py @@ -24,17 +24,17 @@ os.mkdir(dir_name) for collection in collections: cmd = 'mongodump --db %s --collection %s -o %s' % (db_name, collection, dir_name) - print "Dumping %s: %s" % (collection, cmd) + print("Dumping %s: %s" % (collection, cmd)) os.system(cmd) -print "Compressing %s..." % filename +print("Compressing %s..." % filename) cmd = 'tar -zcf %s %s' % (filename, dir_name) os.system(cmd) -print 'Uploading %s to S3...' % filename +print('Uploading %s to S3...' % filename) try: s3.save_file_in_s3(filename, name="mongo/%s" % (filename)) -except Exception, e: - print " ****> Exceptions: %s" % e +except Exception as e: + print(" ****> Exceptions: %s" % e) shutil.rmtree(dir_name) os.remove(filename) \ No newline at end of file diff --git a/utils/backups/backup_psql.py b/utils/backups/backup_psql.py index af46afe1b..b89dc990f 100644 --- a/utils/backups/backup_psql.py +++ b/utils/backups/backup_psql.py @@ -16,9 +16,9 @@ db_pass = settings.DATABASES['default']['PASSWORD'] os.environ['PGPASSWORD'] = db_pass filename = 'backup_postgresql_%s.sql.gz' % time.strftime('%Y-%m-%d-%H-%M') cmd = '/usr/lib/postgresql/9.4/bin/pg_dump -U newsblur -h 127.0.0.1 -Fc %s > %s' % (db_name, filename) -print 'Backing up PostgreSQL: %s' % cmd +print('Backing up PostgreSQL: %s' % cmd) os.system(cmd) -print 'Uploading %s to S3...' % filename +print('Uploading %s to S3...' % filename) s3.save_file_in_s3(filename, name="postgres/%s" % filename) os.remove(filename) \ No newline at end of file diff --git a/utils/backups/backup_redis.py b/utils/backups/backup_redis.py index 68e645eb9..b058c6579 100644 --- a/utils/backups/backup_redis.py +++ b/utils/backups/backup_redis.py @@ -12,5 +12,5 @@ from django.conf import settings filename = 'backup_redis/backup_redis_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M') path = '/var/lib/redis/dump.rdb' -print 'Uploading %s (from %s) to S3...' % (filename, path) +print('Uploading %s (from %s) to S3...' % (filename, path)) s3.save_file_in_s3(path, name=filename) diff --git a/utils/backups/backup_redis_sessions.py b/utils/backups/backup_redis_sessions.py index 4c2cc4cbd..d12cac9b5 100644 --- a/utils/backups/backup_redis_sessions.py +++ b/utils/backups/backup_redis_sessions.py @@ -12,5 +12,5 @@ from django.conf import settings filename = 'backup_redis_sessions/backup_redis_sessions_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M') path = '/var/lib/redis/dump.rdb' -print 'Uploading %s (from %s) to S3...' % (filename, path) +print('Uploading %s (from %s) to S3...' % (filename, path)) s3.save_file_in_s3(path, name=filename) diff --git a/utils/backups/backup_redis_story.py b/utils/backups/backup_redis_story.py index a1cfe9fe7..ccb92f1ca 100644 --- a/utils/backups/backup_redis_story.py +++ b/utils/backups/backup_redis_story.py @@ -12,5 +12,5 @@ from django.conf import settings filename = 'redis_story/backup_redis_story_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M') path = '/var/lib/redis/dump.rdb' -print 'Uploading %s (from %s) to S3...' % (filename, path) +print('Uploading %s (from %s) to S3...' % (filename, path)) s3.save_file_in_s3(path, name=filename) diff --git a/utils/backups/copy_mongo_serialized.py b/utils/backups/copy_mongo_serialized.py index 5026bff23..2e081a5d5 100644 --- a/utils/backups/copy_mongo_serialized.py +++ b/utils/backups/copy_mongo_serialized.py @@ -35,9 +35,9 @@ for collection in collections: for item in items: if item.get('_id') != latest_item_id: latest_item_id = item['_id'] - print " ---> Inserted %s items in %s (at: %s) (%2s%%)" % ( + print(" ---> Inserted %s items in %s (at: %s) (%2s%%)" % ( i, collection, item['_id'], (round(i/float(total), 4)*100) - ) + )) sys.stdout.flush() db02.newsblur[collection].insert(item) i += 1 @@ -57,7 +57,7 @@ for f, feed in enumerate(feeds): total_inserted += 1 feed_inserted += 1 if feed_inserted: - print " ---> Inserted %s items (total: %s) in stories (at: %s -- %s/month) (%2s%%)" % ( + print(" ---> Inserted %s items (total: %s) in stories (at: %s -- %s/month) (%2s%%)" % ( feed_inserted, total_inserted, latest_feed_id, feed.average_stories_per_month, (round(f/float(feed_count), 4)*100) - ) + )) sys.stdout.flush() diff --git a/utils/backups/s3.py b/utils/backups/s3.py index b95e2e12a..223f3c86e 100644 --- a/utils/backups/s3.py +++ b/utils/backups/s3.py @@ -35,7 +35,7 @@ def list_backup_in_s3(): bucket = conn.get_bucket(BUCKET_NAME) for i, key in enumerate(bucket.get_all_keys()): - print "[%s] %s" % (i, key.name) + print("[%s] %s" % (i, key.name)) def delete_all_backups(): #FIXME: validate filename exists @@ -43,13 +43,13 @@ def delete_all_backups(): bucket = conn.get_bucket(BUCKET_NAME) for i, key in enumerate(bucket.get_all_keys()): - print "deleting %s" % (key.name) + print("deleting %s" % (key.name)) key.delete() if __name__ == '__main__': import sys if len(sys.argv) < 3: - print 'Usage: %s ' % (sys.argv[0]) + print('Usage: %s ' % (sys.argv[0])) else: if sys.argv[1] == 'set': save_file_in_s3(sys.argv[2]) @@ -60,4 +60,4 @@ if __name__ == '__main__': elif sys.argv[1] == 'delete': delete_all_backups() else: - print 'Usage: %s ' % (sys.argv[0]) + print('Usage: %s ' % (sys.argv[0]))