From 6b1ce30eb20a38e8aace7d930c3394830b14a935 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 18 Feb 2016 16:19:26 +0530 Subject: [PATCH] from __future__ import print_function --- .../management/commands/import_srt.py | 5 ++- pandora/app/config.py | 24 ++++++------ pandora/app/management/commands/init_db.py | 6 ++- .../management/commands/south_installed.py | 6 ++- pandora/archive/extract.py | 16 ++++---- .../management/commands/import_streams.py | 8 ++-- .../management/commands/migrate_timelines.py | 8 ++-- .../management/commands/orphaned_media.py | 4 +- pandora/archive/queue.py | 6 +-- pandora/changelog/recover.py | 4 +- pandora/item/management/commands/get_frame.py | 4 +- .../management/commands/rebuild_filter.py | 4 +- .../item/management/commands/rebuild_find.py | 3 +- .../management/commands/rebuild_indexes.py | 4 +- .../item/management/commands/rebuild_sort.py | 4 +- .../management/commands/rebuild_timelines.py | 3 +- .../item/management/commands/sqlfindindex.py | 4 +- .../item/management/commands/sync_itemsort.py | 9 +++-- .../management/commands/update_external.py | 6 ++- pandora/item/timelines.py | 19 +++++---- pandora/item/views.py | 4 +- update.py | 39 ++++++++++--------- 22 files changed, 109 insertions(+), 81 deletions(-) diff --git a/pandora/annotation/management/commands/import_srt.py b/pandora/annotation/management/commands/import_srt.py index f2a44a20e..8659b6e8a 100644 --- a/pandora/annotation/management/commands/import_srt.py +++ b/pandora/annotation/management/commands/import_srt.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function from django.core.management.base import BaseCommand from django.db import transaction @@ -25,7 +26,7 @@ class Command(BaseCommand): def handle(self, *args, **options): if len(args) != 4: - print self.usage('import_srt') + print(self.usage('import_srt')) return username, public_id, layer_id, filename = args user = User.objects.get(username=username) @@ -33,7 +34,7 @@ class Command(BaseCommand): layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0] annotations = ox.srt.load(filename) - print 'importing %d annotations into %s/%s' % (len(annotations), public_id, layer_id) + print('importing %d annotations into %s/%s' % (len(annotations), public_id, layer_id)) for i in range(len(annotations)-1): if annotations[i]['out'] == annotations[i+1]['in']: annotations[i]['out'] = annotations[i]['out'] - 0.001 diff --git a/pandora/app/config.py b/pandora/app/config.py index c56593a81..c82f43a0f 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import division, with_statement +from __future__ import division, with_statement, print_function import os import sys @@ -50,7 +50,7 @@ def load_config(init=False): except ValueError as e: if init: print("Failed to parse %s:\n" % settings.SITE_CONFIG) - print (e) + print(e) sys.exit(1) else: config = None @@ -61,7 +61,7 @@ def load_config(init=False): except ValueError as e: if init: print("Failed to default config %s:\n" % settings.DEFAULT_CONFIG) - print (e) + print(e) sys.exit(1) else: default = None @@ -102,7 +102,7 @@ def load_config(init=False): 'menuExtras', 'languages' )): parts = map(lambda p: p.replace('\0', '\\.'), section.replace('\\.', '\0').split('.')) - #print 'checking', section + #print('checking', section) c = config d = default while len(parts): @@ -225,7 +225,7 @@ def reloader_thread(): def update_static(): oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py') if os.path.exists(oxjs_build): - print 'update oxjs' + print('update oxjs') os.system('%s >/dev/null' % oxjs_build) data = '' @@ -250,12 +250,12 @@ def update_static(): js += [ 'png/icon.png', ] - print 'write', pandora_js + print('write', pandora_js) data = ox.js.minify(data) with open(pandora_js, 'w') as f: f.write(data) - print 'write', pandora_json + print('write', pandora_json) with open(pandora_json, 'w') as f: json.dump(sorted(js), f, indent=2) @@ -283,11 +283,11 @@ def update_static(): locale = json.load(fd) site_locale = f.replace('locale.pandora', 'locale.' + settings.CONFIG['site']['id']) locale_file = f.replace('locale.pandora', 'locale') - print 'write', locale_file - print ' adding', f + print('write', locale_file) + print(' adding', f) if os.path.exists(site_locale): with open(site_locale) as fdl: - print ' adding', site_locale + print(' adding', site_locale) locale.update(json.load(fdl)) with codecs.open(locale_file, "w", "utf-8") as fd: json.dump(locale, fd, ensure_ascii=False) @@ -311,7 +311,7 @@ def update_geoip(force=False): path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat') if not os.path.exists(path) or force: url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz' - print 'download', url + print('download', url) ox.net.save_url(url, "%s.gz"%path) if os.path.exists(path): os.unlink(path) @@ -319,7 +319,7 @@ def update_geoip(force=False): path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCityv6.dat') if not os.path.exists(path) or force: url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz' - print 'download', url + print('download', url) ox.net.save_url(url, "%s.gz"%path) if os.path.exists(path): os.unlink(path) diff --git a/pandora/app/management/commands/init_db.py b/pandora/app/management/commands/init_db.py index 1ef901091..571ae957b 100644 --- a/pandora/app/management/commands/init_db.py +++ b/pandora/app/management/commands/init_db.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from django.core.management.base import BaseCommand from django.conf import settings import os @@ -11,7 +13,7 @@ def run(cmd): stdout, stderr = p.communicate() if p.returncode != 0: - print stderr + print(stderr) sys.exit(1) class Command(BaseCommand): @@ -21,7 +23,7 @@ class Command(BaseCommand): args = '' def handle(self, **options): - print 'initializing database...' + print('initializing database...') manage_py = sys.argv[0] for cmd in [ [manage_py, 'syncdb', '--noinput'], diff --git a/pandora/app/management/commands/south_installed.py b/pandora/app/management/commands/south_installed.py index 38d226b73..b62d6edd8 100644 --- a/pandora/app/management/commands/south_installed.py +++ b/pandora/app/management/commands/south_installed.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from django.core.management.base import BaseCommand from django.db import connection @@ -16,6 +18,6 @@ class Command(BaseCommand): table_name = south.models.MigrationHistory._meta.db_table cursor = connection.cursor() db_rows = connection.introspection.get_table_description(cursor, table_name) - print "yes" + print("yes") except: - print "no" + print("no") diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index d383995ed..6b9bef42c 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import division, with_statement +from __future__ import division, with_statement, print_function import os from os.path import exists @@ -272,7 +272,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}): else: cmd += [enc_target] - #print cmd + #print(cmd) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -289,7 +289,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}): return False, stdout if format == 'mp4': cmd = ['qt-faststart', "%s.mp4" % enc_target, enc_target] - #print cmd + #print(cmd) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT, @@ -311,7 +311,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}): def run_command(cmd, timeout=10): - #print cmd + #print(cmd) p = subprocess.Popen(cmd, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT, close_fds=True) @@ -425,7 +425,7 @@ def timeline(video, prefix, modes=None, size=None): p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) - #print cmd + #print(cmd) #p = subprocess.Popen(cmd) p.wait() @@ -535,7 +535,7 @@ def timeline_strip(item, cuts, info, prefix): widths = divide(duration, frames) frame = frame if _debug: - print widths, duration, frames, cuts[c], cuts[c + 1] + print(widths, duration, frames, cuts[c], cuts[c + 1]) for s in range(int(frames)): frame_ratio = widths[s] / timeline_height if video_ratio > frame_ratio: @@ -547,7 +547,7 @@ def timeline_strip(item, cuts, info, prefix): top = int((video_height - height) / 2) box = (0, top, video_width, top + height) if _debug: - print frame, 'cut', c, 'frame', s, frame, 'width', widths[s], box + print(frame, 'cut', c, 'frame', s, frame, 'width', widths[s], box) #FIXME: why does this have to be frame+1? frame_image = Image.open(item.frame((frame+1)/fps)) frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.ANTIALIAS) @@ -559,7 +559,7 @@ def timeline_strip(item, cuts, info, prefix): if x == timeline_width - 1: timeline_file = '%sStrip64p%04d.png' % (prefix, i) if _debug: - print 'writing', timeline_file + print('writing', timeline_file) timeline_image.save(timeline_file) diff --git a/pandora/archive/management/commands/import_streams.py b/pandora/archive/management/commands/import_streams.py index ad69da6e4..bbc823a5f 100644 --- a/pandora/archive/management/commands/import_streams.py +++ b/pandora/archive/management/commands/import_streams.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from django.core.management.base import BaseCommand from django.conf import settings import os @@ -28,8 +30,8 @@ class Command(BaseCommand): resolution = int(profile) qs = models.Stream.objects.filter(file__oshash=oshash, format=format, resolution=resolution) if qs.count() == 0: - print 'add', f - print oshash, resolution, format + print('add', f) + print(oshash, resolution, format) qs = models.File.objects.filter(oshash=oshash) if qs.count() == 1: stream = models.Stream() @@ -48,6 +50,6 @@ class Command(BaseCommand): for s in models.Stream.objects.exclude(format=format, resolution=resolution).filter(source=None): s.source = models.Stream.objects.get(file=s.file, resolution=resolution, format=format) s.save() - print "update streams" + print("update streams") for s in models.Stream.objects.filter(source=None): update_stream.delay(s.id) diff --git a/pandora/archive/management/commands/migrate_timelines.py b/pandora/archive/management/commands/migrate_timelines.py index f3bfee843..d1fa9b4e6 100644 --- a/pandora/archive/management/commands/migrate_timelines.py +++ b/pandora/archive/management/commands/migrate_timelines.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + import os import re @@ -22,19 +24,19 @@ class Command(BaseCommand): base, ext = os.path.splitext(os.path.basename(f)) if base.startswith('timeline') and ext == '.png': if base in ('timeline.overview', 'timeline.overview.8'): - print 'delete', f + print('delete', f) os.unlink(f) else: n = re.compile('timeline(\d+)p(\d+)').findall(base) if not n: n = re.compile('timeline(\d+)p').findall(base) target = 'timelineantialias%sp.jpg' % n[0] - print f, target + print(f, target) target = os.path.join(os.path.dirname(f), target) os.rename(f, target) else: n = tuple(map(int, n[0])) target = 'timelineantialias%dp%d.jpg' % n - print f, target + print(f, target) target = os.path.join(os.path.dirname(f), target) os.rename(f, target) diff --git a/pandora/archive/management/commands/orphaned_media.py b/pandora/archive/management/commands/orphaned_media.py index 97c573373..df4fcaf40 100644 --- a/pandora/archive/management/commands/orphaned_media.py +++ b/pandora/archive/management/commands/orphaned_media.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from django.core.management.base import BaseCommand from django.conf import settings import os @@ -18,4 +20,4 @@ class Command(BaseCommand): for f in glob(os.path.join(settings.MEDIA_ROOT, 'media', '*', '*', '*', '*')): oshash = f[-19:].replace('/', '') if models.File.objects.filter(oshash=oshash).count() == 0: - print f + print(f) diff --git a/pandora/archive/queue.py b/pandora/archive/queue.py index f28732266..9cafee1b9 100644 --- a/pandora/archive/queue.py +++ b/pandora/archive/queue.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import division +from __future__ import division, print_function from datetime import datetime import time @@ -52,7 +52,7 @@ def fill_queue(): elif f.data: f.extract_stream() else: - print 'not sure what to do with' ,f + print('not sure what to do with' ,f) check.append(f) in_queue.append(f.oshash) for f in File.objects.filter(encoding=True).exclude(oshash__in=in_queue): @@ -61,7 +61,7 @@ def fill_queue(): elif f.data: f.extract_stream() else: - print 'not sure what to do with' ,f + print('not sure what to do with' ,f) check.append(f) return check diff --git a/pandora/changelog/recover.py b/pandora/changelog/recover.py index 3be12cc27..425af0f9b 100644 --- a/pandora/changelog/recover.py +++ b/pandora/changelog/recover.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import models import item.models import user.models @@ -52,7 +54,7 @@ def recover_item(id): i.save() i.update_sort() i.update_find() - print 'created', i, i.id + print('created', i, i.id) for a in models.Changelog.objects.filter(value__contains='id": "%s/' % id).order_by('created'): qs = i.annotations.filter(public_id=a.value['id']) diff --git a/pandora/item/management/commands/get_frame.py b/pandora/item/management/commands/get_frame.py index 293f4754c..823a66969 100644 --- a/pandora/item/management/commands/get_frame.py +++ b/pandora/item/management/commands/get_frame.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from django.core.management.base import BaseCommand from django.conf import settings from django.db import transaction @@ -19,4 +21,4 @@ class Command(BaseCommand): i = models.Item.objects.get(public_id=id) path = i.frame(position, height) if path: - print path + print(path) diff --git a/pandora/item/management/commands/rebuild_filter.py b/pandora/item/management/commands/rebuild_filter.py index 05cf0ecca..b50c1bdca 100644 --- a/pandora/item/management/commands/rebuild_filter.py +++ b/pandora/item/management/commands/rebuild_filter.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from optparse import make_option from django.core.management.base import BaseCommand @@ -26,7 +28,7 @@ class Command(BaseCommand): try: i = models.Item.objects.get(pk=id) if options['debug']: - print i + print(i) i.update_facets() except: pass diff --git a/pandora/item/management/commands/rebuild_find.py b/pandora/item/management/commands/rebuild_find.py index 4dca7c149..8d03b96e6 100644 --- a/pandora/item/management/commands/rebuild_find.py +++ b/pandora/item/management/commands/rebuild_find.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function from optparse import make_option from django.core.management.base import BaseCommand @@ -25,7 +26,7 @@ class Command(BaseCommand): for id in ids: try: i = models.Item.objects.get(pk=id) - print i + print(i) i.update_find() except: pass diff --git a/pandora/item/management/commands/rebuild_indexes.py b/pandora/item/management/commands/rebuild_indexes.py index 9651f4c02..8f27e28b5 100644 --- a/pandora/item/management/commands/rebuild_indexes.py +++ b/pandora/item/management/commands/rebuild_indexes.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from optparse import make_option from django.core.management.base import BaseCommand @@ -26,7 +28,7 @@ class Command(BaseCommand): try: i = models.Item.objects.get(pk=id) if options['debug']: - print i + print(i) i.update_facets() i.update_sort() i.update_find() diff --git a/pandora/item/management/commands/rebuild_sort.py b/pandora/item/management/commands/rebuild_sort.py index b167d3802..b8e89992b 100644 --- a/pandora/item/management/commands/rebuild_sort.py +++ b/pandora/item/management/commands/rebuild_sort.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from optparse import make_option from django.core.management.base import BaseCommand @@ -25,7 +27,7 @@ class Command(BaseCommand): try: i = models.Item.objects.get(pk=id) if options['debug']: - print i + print(i) i.update_sort() except: pass diff --git a/pandora/item/management/commands/rebuild_timelines.py b/pandora/item/management/commands/rebuild_timelines.py index 1aaebd520..f0aad16af 100644 --- a/pandora/item/management/commands/rebuild_timelines.py +++ b/pandora/item/management/commands/rebuild_timelines.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function import os from glob import glob @@ -25,6 +26,6 @@ class Command(BaseCommand): for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]: if not os.path.exists(os.path.join(i.timeline_prefix, 'cuts.json')) or \ not glob('%s/timelinekeyframes16p0.jpg'%i.timeline_prefix): - print i.public_id + print(i.public_id) tasks.rebuild_timeline.delay(i.public_id) offset += chunk diff --git a/pandora/item/management/commands/sqlfindindex.py b/pandora/item/management/commands/sqlfindindex.py index 7672721a1..d9fe3b55c 100644 --- a/pandora/item/management/commands/sqlfindindex.py +++ b/pandora/item/management/commands/sqlfindindex.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from optparse import make_option from django.core.management.base import BaseCommand @@ -27,7 +29,7 @@ class Command(BaseCommand): def create_index(index, table, key): sql = 'CREATE INDEX "%s" ON "%s" USING gin ("%s" gin_trgm_ops)' % (index, table, key) if options['debug']: - print sql + print(sql) cursor.execute(sql) if settings.DB_GIN_TRGM: diff --git a/pandora/item/management/commands/sync_itemsort.py b/pandora/item/management/commands/sync_itemsort.py index b8cb20859..0d176070b 100644 --- a/pandora/item/management/commands/sync_itemsort.py +++ b/pandora/item/management/commands/sync_itemsort.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function from optparse import make_option from django.core.management.base import BaseCommand @@ -102,17 +103,17 @@ class Command(BaseCommand): sql = 'BEGIN' changes.append(sql) if changes: - print "Updating database schema..." + print("Updating database schema...") for sql in changes: if options['debug']: - print sql + print(sql) cursor.execute(sql) transaction.commit_unless_managed() if rebuild: - print "Updating sort values..." + print("Updating sort values...") ids = [i['id'] for i in models.Item.objects.all().values('id')] for id in ids: i = models.Item.objects.get(pk=id) if options['debug']: - print i + print(i) i.update_sort() diff --git a/pandora/item/management/commands/update_external.py b/pandora/item/management/commands/update_external.py index 810dafdd2..da5057d71 100644 --- a/pandora/item/management/commands/update_external.py +++ b/pandora/item/management/commands/update_external.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from __future__ import print_function + from optparse import make_option from django.core.management.base import BaseCommand @@ -27,9 +29,9 @@ class Command(BaseCommand): qs = models.Item.objects.exclude(public_id__startswith='0x') count = pos = qs.count() while (options['all'] and offset <= count) or offset < options['items']: - print offset, pos, count + print(offset, pos, count) for i in qs.order_by('modified')[:chunk]: - print pos, i.public_id, i.modified + print(pos, i.public_id, i.modified) i.update_external() pos -= 1 offset += chunk diff --git a/pandora/item/timelines.py b/pandora/item/timelines.py index 7492f7b69..7526cdff0 100644 --- a/pandora/item/timelines.py +++ b/pandora/item/timelines.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 - -from __future__ import division, with_statement +from __future__ import division, with_statement, print_function import math import os @@ -57,7 +56,7 @@ def join_tiles(source_paths, target_path): target_path, mode, large_tile_h, large_tile_i ) data['target_images']['large'].save(image_file) - #print image_file + #print(image_file) if mode != 'keyframes': # open small tile small_tile_i = int(large_tile_i / 60) @@ -82,7 +81,7 @@ def join_tiles(source_paths, target_path): target_path, small_mode, small_tile_h, small_tile_i ) data['target_images']['small'].save(image_file) - #print image_file + #print(image_file) if mode == full_tile_mode: # render full tile resized = data['target_images']['large'].resize(( @@ -171,12 +170,12 @@ def join_tiles(source_paths, target_path): # save full timelines image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, large_tile_h) data['target_images']['full'].save(image_file) - #print image_file + #print(image_file) image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, small_tile_h) data['target_images']['full'].resize( (full_tile_w, small_tile_h), Image.ANTIALIAS ).save(image_file) - #print image_file + #print(image_file) # join cuts cuts = [] @@ -187,7 +186,7 @@ def join_tiles(source_paths, target_path): with open(p, 'r') as f: path_cuts = json.load(f) else: - print p, 'missing' + print(p, 'missing') path_cuts = [] if i > 0: cuts.append(offset) @@ -207,7 +206,7 @@ def split_tiles(path, paths, durations): tiles = {} for file_name in file_names: mode = re.split('\d+', file_name[8:])[0] - print file_name, mode + print(file_name, mode) split = re.split('[a-z]+', file_name[8 + len(mode):-4]) height, index = map(lambda x: int(x) if len(x) else -1, split) if not mode in tiles: @@ -216,7 +215,7 @@ def split_tiles(path, paths, durations): tiles[mode][height] = 0 if index + 1 > tiles[mode][height]: tiles[mode][height] = index + 1 - print tiles + print(tiles) # for each mode for mode in tiles: @@ -264,5 +263,5 @@ def split_tiles(path, paths, durations): paths[target_data[i]['item']], mode, height, target_data[i]['tile'] ) # target_image.save(file_name) - print file_name, target_image.size + print(file_name, target_image.size) diff --git a/pandora/item/views.py b/pandora/item/views.py index 62d33d220..2fd50100e 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import division +from __future__ import division, print_function import os.path import mimetypes import random @@ -168,7 +168,7 @@ def find(request, data): see: add, edit, get, lookup, remove, upload ''' if settings.JSON_DEBUG: - print json.dumps(data, indent=2) + print(json.dumps(data, indent=2)) query = parse_query(data, request.user) response = json_response({}) diff --git a/update.py b/update.py index 5d340195c..62a31f91d 100755 --- a/update.py +++ b/update.py @@ -1,4 +1,5 @@ #!/usr/bin/python +from __future__ import print_function import os base = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) @@ -37,7 +38,7 @@ def get_release(): try: return get_json(url) except: - print "Failed to load %s check your internet connection." % url + print("Failed to load %s check your internet connection." % url) sys.exit(1) repos = { @@ -60,7 +61,7 @@ repos = { } def reload_notice(base): - print '\nPlease restart pan.do/ra to finish the update:\n\tsudo %s/ctl reload\n' % base + print('\nPlease restart pan.do/ra to finish the update:\n\tsudo %s/ctl reload\n' % base) def check_services(base): services = "pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd".split() @@ -69,13 +70,13 @@ def check_services(base): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() if p.returncode != 0: - print 'Please install init script for "%s" service:' % service + print('Please install init script for "%s" service:' % service) if os.path.exists('/etc/init'): - print '\tsudo cp %s/etc/init/%s.conf /etc/init/' % (base, service) + print('\tsudo cp %s/etc/init/%s.conf /etc/init/' % (base, service)) if os.path.exists('/lib/systemd/system'): - print '\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service) - print '\tsudo service %s start' % service - print '' + print('\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service)) + print('\tsudo service %s start' % service) + print('') def run_git(path, *args): cmd = ['git'] + list(args) @@ -90,19 +91,19 @@ if __name__ == "__main__": os.chdir(join(base, 'pandora')) if get('./manage.py', 'south_installed').strip() == 'yes': run('./manage.py', 'syncdb') - print '\nRunning "./manage.py migrate"\n' + print('\nRunning "./manage.py migrate"\n') run('./manage.py', 'migrate') run('./manage.py', 'sqlfindindex') run('./manage.py', 'sync_itemsort') reload_notice(base) else: - print "You are upgrading from an older version of pan.do/ra." - print "Please use ./manage.py sqldiff -a to check for updates" - print "and apply required changes. You might have to set defaults too." - print "Once done run:" - print "\tcd %s" % os.path.abspath(os.curdir) - print "\t./manage.py migrate --all --fake" - print "Check http://wiki.0x2620.org/wiki/pandora/DatabaseUpdate for more information" + print("You are upgrading from an older version of pan.do/ra.") + print("Please use ./manage.py sqldiff -a to check for updates") + print("and apply required changes. You might have to set defaults too.") + print("Once done run:") + print("\tcd %s" % os.path.abspath(os.curdir)) + print("\t./manage.py migrate --all --fake") + print("Check http://wiki.0x2620.org/wiki/pandora/DatabaseUpdate for more information") elif len(sys.argv) == 2 and sys.argv[1] == 'static': os.chdir(join(base, 'pandora')) run('./manage.py', 'update_static') @@ -114,7 +115,7 @@ if __name__ == "__main__": old = int(old) if new.isdigit(): new = int(new) - print 'Post Update from %s to %s' % (old, new) + print('Post Update from %s to %s' % (old, new)) if old < 3111: run('bzr', 'resolved', 'pandora/monkey_patch', 'pandora/monkey_patch/migrations') if os.path.exists('pandora/monkey_patch'): @@ -201,7 +202,7 @@ if __name__ == "__main__": run('git', 'fetch') run('git', 'checkout', repos[repo]['commit']) else: - print 'Checking', repo + print('Checking', repo) run('git', 'checkout', 'master', '-q') run('git', 'pull') revno = get_version(path) @@ -229,8 +230,8 @@ if __name__ == "__main__": os.chdir(join(base, 'pandora')) diff = get('./manage.py', 'sqldiff', '-a').strip() if diff != '-- No differences': - print 'Database has changed, please make a backup and run %s db' % sys.argv[0] + print('Database has changed, please make a backup and run %s db' % sys.argv[0]) elif not development: - print 'pan.do/ra is at the latest release,\nyou can run "%s dev" to update to the development version' % sys.argv[0] + print('pan.do/ra is at the latest release,\nyou can run "%s dev" to update to the development version' % sys.argv[0]) elif current != new: reload_notice(base)