from __future__ import print_function

This commit is contained in:
j 2016-02-18 16:19:26 +05:30
parent 47d8d67c3d
commit 6b1ce30eb2
22 changed files with 109 additions and 81 deletions

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import transaction from django.db import transaction
@ -25,7 +26,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 4: if len(args) != 4:
print self.usage('import_srt') print(self.usage('import_srt'))
return return
username, public_id, layer_id, filename = args username, public_id, layer_id, filename = args
user = User.objects.get(username=username) 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] layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0]
annotations = ox.srt.load(filename) 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): for i in range(len(annotations)-1):
if annotations[i]['out'] == annotations[i+1]['in']: if annotations[i]['out'] == annotations[i+1]['in']:
annotations[i]['out'] = annotations[i]['out'] - 0.001 annotations[i]['out'] = annotations[i]['out'] - 0.001

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # 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 os
import sys import sys
@ -50,7 +50,7 @@ def load_config(init=False):
except ValueError as e: except ValueError as e:
if init: if init:
print("Failed to parse %s:\n" % settings.SITE_CONFIG) print("Failed to parse %s:\n" % settings.SITE_CONFIG)
print (e) print(e)
sys.exit(1) sys.exit(1)
else: else:
config = None config = None
@ -61,7 +61,7 @@ def load_config(init=False):
except ValueError as e: except ValueError as e:
if init: if init:
print("Failed to default config %s:\n" % settings.DEFAULT_CONFIG) print("Failed to default config %s:\n" % settings.DEFAULT_CONFIG)
print (e) print(e)
sys.exit(1) sys.exit(1)
else: else:
default = None default = None
@ -102,7 +102,7 @@ def load_config(init=False):
'menuExtras', 'languages' 'menuExtras', 'languages'
)): )):
parts = map(lambda p: p.replace('\0', '\\.'), section.replace('\\.', '\0').split('.')) parts = map(lambda p: p.replace('\0', '\\.'), section.replace('\\.', '\0').split('.'))
#print 'checking', section #print('checking', section)
c = config c = config
d = default d = default
while len(parts): while len(parts):
@ -225,7 +225,7 @@ def reloader_thread():
def update_static(): def update_static():
oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py') oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py')
if os.path.exists(oxjs_build): if os.path.exists(oxjs_build):
print 'update oxjs' print('update oxjs')
os.system('%s >/dev/null' % oxjs_build) os.system('%s >/dev/null' % oxjs_build)
data = '' data = ''
@ -250,12 +250,12 @@ def update_static():
js += [ js += [
'png/icon.png', 'png/icon.png',
] ]
print 'write', pandora_js print('write', pandora_js)
data = ox.js.minify(data) data = ox.js.minify(data)
with open(pandora_js, 'w') as f: with open(pandora_js, 'w') as f:
f.write(data) f.write(data)
print 'write', pandora_json print('write', pandora_json)
with open(pandora_json, 'w') as f: with open(pandora_json, 'w') as f:
json.dump(sorted(js), f, indent=2) json.dump(sorted(js), f, indent=2)
@ -283,11 +283,11 @@ def update_static():
locale = json.load(fd) locale = json.load(fd)
site_locale = f.replace('locale.pandora', 'locale.' + settings.CONFIG['site']['id']) site_locale = f.replace('locale.pandora', 'locale.' + settings.CONFIG['site']['id'])
locale_file = f.replace('locale.pandora', 'locale') locale_file = f.replace('locale.pandora', 'locale')
print 'write', locale_file print('write', locale_file)
print ' adding', f print(' adding', f)
if os.path.exists(site_locale): if os.path.exists(site_locale):
with open(site_locale) as fdl: with open(site_locale) as fdl:
print ' adding', site_locale print(' adding', site_locale)
locale.update(json.load(fdl)) locale.update(json.load(fdl))
with codecs.open(locale_file, "w", "utf-8") as fd: with codecs.open(locale_file, "w", "utf-8") as fd:
json.dump(locale, fd, ensure_ascii=False) 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') path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat')
if not os.path.exists(path) or force: if not os.path.exists(path) or force:
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz' 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) ox.net.save_url(url, "%s.gz"%path)
if os.path.exists(path): if os.path.exists(path):
os.unlink(path) os.unlink(path)
@ -319,7 +319,7 @@ def update_geoip(force=False):
path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCityv6.dat') path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCityv6.dat')
if not os.path.exists(path) or force: if not os.path.exists(path) or force:
url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz' 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) ox.net.save_url(url, "%s.gz"%path)
if os.path.exists(path): if os.path.exists(path):
os.unlink(path) os.unlink(path)

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
import os import os
@ -11,7 +13,7 @@ def run(cmd):
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode != 0:
print stderr print(stderr)
sys.exit(1) sys.exit(1)
class Command(BaseCommand): class Command(BaseCommand):
@ -21,7 +23,7 @@ class Command(BaseCommand):
args = '' args = ''
def handle(self, **options): def handle(self, **options):
print 'initializing database...' print('initializing database...')
manage_py = sys.argv[0] manage_py = sys.argv[0]
for cmd in [ for cmd in [
[manage_py, 'syncdb', '--noinput'], [manage_py, 'syncdb', '--noinput'],

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import connection from django.db import connection
@ -16,6 +18,6 @@ class Command(BaseCommand):
table_name = south.models.MigrationHistory._meta.db_table table_name = south.models.MigrationHistory._meta.db_table
cursor = connection.cursor() cursor = connection.cursor()
db_rows = connection.introspection.get_table_description(cursor, table_name) db_rows = connection.introspection.get_table_description(cursor, table_name)
print "yes" print("yes")
except: except:
print "no" print("no")

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # 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 os
from os.path import exists from os.path import exists
@ -272,7 +272,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}):
else: else:
cmd += [enc_target] cmd += [enc_target]
#print cmd #print(cmd)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -289,7 +289,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}):
return False, stdout return False, stdout
if format == 'mp4': if format == 'mp4':
cmd = ['qt-faststart', "%s.mp4" % enc_target, enc_target] cmd = ['qt-faststart', "%s.mp4" % enc_target, enc_target]
#print cmd #print(cmd)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=open('/dev/null', 'w'), stdout=open('/dev/null', 'w'),
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -311,7 +311,7 @@ def stream(video, target, profile, info, audio_track=0, flags={}):
def run_command(cmd, timeout=10): def run_command(cmd, timeout=10):
#print cmd #print(cmd)
p = subprocess.Popen(cmd, stdout=open('/dev/null', 'w'), p = subprocess.Popen(cmd, stdout=open('/dev/null', 'w'),
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
close_fds=True) close_fds=True)
@ -425,7 +425,7 @@ def timeline(video, prefix, modes=None, size=None):
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True) close_fds=True)
#print cmd #print(cmd)
#p = subprocess.Popen(cmd) #p = subprocess.Popen(cmd)
p.wait() p.wait()
@ -535,7 +535,7 @@ def timeline_strip(item, cuts, info, prefix):
widths = divide(duration, frames) widths = divide(duration, frames)
frame = frame frame = frame
if _debug: 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)): for s in range(int(frames)):
frame_ratio = widths[s] / timeline_height frame_ratio = widths[s] / timeline_height
if video_ratio > frame_ratio: if video_ratio > frame_ratio:
@ -547,7 +547,7 @@ def timeline_strip(item, cuts, info, prefix):
top = int((video_height - height) / 2) top = int((video_height - height) / 2)
box = (0, top, video_width, top + height) box = (0, top, video_width, top + height)
if _debug: 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? #FIXME: why does this have to be frame+1?
frame_image = Image.open(item.frame((frame+1)/fps)) frame_image = Image.open(item.frame((frame+1)/fps))
frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.ANTIALIAS) 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: if x == timeline_width - 1:
timeline_file = '%sStrip64p%04d.png' % (prefix, i) timeline_file = '%sStrip64p%04d.png' % (prefix, i)
if _debug: if _debug:
print 'writing', timeline_file print('writing', timeline_file)
timeline_image.save(timeline_file) timeline_image.save(timeline_file)

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
import os import os
@ -28,8 +30,8 @@ class Command(BaseCommand):
resolution = int(profile) resolution = int(profile)
qs = models.Stream.objects.filter(file__oshash=oshash, format=format, resolution=resolution) qs = models.Stream.objects.filter(file__oshash=oshash, format=format, resolution=resolution)
if qs.count() == 0: if qs.count() == 0:
print 'add', f print('add', f)
print oshash, resolution, format print(oshash, resolution, format)
qs = models.File.objects.filter(oshash=oshash) qs = models.File.objects.filter(oshash=oshash)
if qs.count() == 1: if qs.count() == 1:
stream = models.Stream() stream = models.Stream()
@ -48,6 +50,6 @@ class Command(BaseCommand):
for s in models.Stream.objects.exclude(format=format, resolution=resolution).filter(source=None): 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.source = models.Stream.objects.get(file=s.file, resolution=resolution, format=format)
s.save() s.save()
print "update streams" print("update streams")
for s in models.Stream.objects.filter(source=None): for s in models.Stream.objects.filter(source=None):
update_stream.delay(s.id) update_stream.delay(s.id)

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
import os import os
import re import re
@ -22,19 +24,19 @@ class Command(BaseCommand):
base, ext = os.path.splitext(os.path.basename(f)) base, ext = os.path.splitext(os.path.basename(f))
if base.startswith('timeline') and ext == '.png': if base.startswith('timeline') and ext == '.png':
if base in ('timeline.overview', 'timeline.overview.8'): if base in ('timeline.overview', 'timeline.overview.8'):
print 'delete', f print('delete', f)
os.unlink(f) os.unlink(f)
else: else:
n = re.compile('timeline(\d+)p(\d+)').findall(base) n = re.compile('timeline(\d+)p(\d+)').findall(base)
if not n: if not n:
n = re.compile('timeline(\d+)p').findall(base) n = re.compile('timeline(\d+)p').findall(base)
target = 'timelineantialias%sp.jpg' % n[0] target = 'timelineantialias%sp.jpg' % n[0]
print f, target print(f, target)
target = os.path.join(os.path.dirname(f), target) target = os.path.join(os.path.dirname(f), target)
os.rename(f, target) os.rename(f, target)
else: else:
n = tuple(map(int, n[0])) n = tuple(map(int, n[0]))
target = 'timelineantialias%dp%d.jpg' % n target = 'timelineantialias%dp%d.jpg' % n
print f, target print(f, target)
target = os.path.join(os.path.dirname(f), target) target = os.path.join(os.path.dirname(f), target)
os.rename(f, target) os.rename(f, target)

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
import os import os
@ -18,4 +20,4 @@ class Command(BaseCommand):
for f in glob(os.path.join(settings.MEDIA_ROOT, 'media', '*', '*', '*', '*')): for f in glob(os.path.join(settings.MEDIA_ROOT, 'media', '*', '*', '*', '*')):
oshash = f[-19:].replace('/', '') oshash = f[-19:].replace('/', '')
if models.File.objects.filter(oshash=oshash).count() == 0: if models.File.objects.filter(oshash=oshash).count() == 0:
print f print(f)

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division from __future__ import division, print_function
from datetime import datetime from datetime import datetime
import time import time
@ -52,7 +52,7 @@ def fill_queue():
elif f.data: elif f.data:
f.extract_stream() f.extract_stream()
else: else:
print 'not sure what to do with' ,f print('not sure what to do with' ,f)
check.append(f) check.append(f)
in_queue.append(f.oshash) in_queue.append(f.oshash)
for f in File.objects.filter(encoding=True).exclude(oshash__in=in_queue): for f in File.objects.filter(encoding=True).exclude(oshash__in=in_queue):
@ -61,7 +61,7 @@ def fill_queue():
elif f.data: elif f.data:
f.extract_stream() f.extract_stream()
else: else:
print 'not sure what to do with' ,f print('not sure what to do with' ,f)
check.append(f) check.append(f)
return check return check

View file

@ -1,3 +1,5 @@
from __future__ import print_function
import models import models
import item.models import item.models
import user.models import user.models
@ -52,7 +54,7 @@ def recover_item(id):
i.save() i.save()
i.update_sort() i.update_sort()
i.update_find() 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'): for a in models.Changelog.objects.filter(value__contains='id": "%s/' % id).order_by('created'):
qs = i.annotations.filter(public_id=a.value['id']) qs = i.annotations.filter(public_id=a.value['id'])

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from django.db import transaction from django.db import transaction
@ -19,4 +21,4 @@ class Command(BaseCommand):
i = models.Item.objects.get(public_id=id) i = models.Item.objects.get(public_id=id)
path = i.frame(position, height) path = i.frame(position, height)
if path: if path:
print path print(path)

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -26,7 +28,7 @@ class Command(BaseCommand):
try: try:
i = models.Item.objects.get(pk=id) i = models.Item.objects.get(pk=id)
if options['debug']: if options['debug']:
print i print(i)
i.update_facets() i.update_facets()
except: except:
pass pass

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -25,7 +26,7 @@ class Command(BaseCommand):
for id in ids: for id in ids:
try: try:
i = models.Item.objects.get(pk=id) i = models.Item.objects.get(pk=id)
print i print(i)
i.update_find() i.update_find()
except: except:
pass pass

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -26,7 +28,7 @@ class Command(BaseCommand):
try: try:
i = models.Item.objects.get(pk=id) i = models.Item.objects.get(pk=id)
if options['debug']: if options['debug']:
print i print(i)
i.update_facets() i.update_facets()
i.update_sort() i.update_sort()
i.update_find() i.update_find()

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -25,7 +27,7 @@ class Command(BaseCommand):
try: try:
i = models.Item.objects.get(pk=id) i = models.Item.objects.get(pk=id)
if options['debug']: if options['debug']:
print i print(i)
i.update_sort() i.update_sort()
except: except:
pass pass

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
import os import os
from glob import glob from glob import glob
@ -25,6 +26,6 @@ class Command(BaseCommand):
for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]: 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 \ if not os.path.exists(os.path.join(i.timeline_prefix, 'cuts.json')) or \
not glob('%s/timelinekeyframes16p0.jpg'%i.timeline_prefix): not glob('%s/timelinekeyframes16p0.jpg'%i.timeline_prefix):
print i.public_id print(i.public_id)
tasks.rebuild_timeline.delay(i.public_id) tasks.rebuild_timeline.delay(i.public_id)
offset += chunk offset += chunk

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -27,7 +29,7 @@ class Command(BaseCommand):
def create_index(index, table, key): def create_index(index, table, key):
sql = 'CREATE INDEX "%s" ON "%s" USING gin ("%s" gin_trgm_ops)' % (index, table, key) sql = 'CREATE INDEX "%s" ON "%s" USING gin ("%s" gin_trgm_ops)' % (index, table, key)
if options['debug']: if options['debug']:
print sql print(sql)
cursor.execute(sql) cursor.execute(sql)
if settings.DB_GIN_TRGM: if settings.DB_GIN_TRGM:

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -102,17 +103,17 @@ class Command(BaseCommand):
sql = 'BEGIN' sql = 'BEGIN'
changes.append(sql) changes.append(sql)
if changes: if changes:
print "Updating database schema..." print("Updating database schema...")
for sql in changes: for sql in changes:
if options['debug']: if options['debug']:
print sql print(sql)
cursor.execute(sql) cursor.execute(sql)
transaction.commit_unless_managed() transaction.commit_unless_managed()
if rebuild: if rebuild:
print "Updating sort values..." print("Updating sort values...")
ids = [i['id'] for i in models.Item.objects.all().values('id')] ids = [i['id'] for i in models.Item.objects.all().values('id')]
for id in ids: for id in ids:
i = models.Item.objects.get(pk=id) i = models.Item.objects.get(pk=id)
if options['debug']: if options['debug']:
print i print(i)
i.update_sort() i.update_sort()

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -27,9 +29,9 @@ class Command(BaseCommand):
qs = models.Item.objects.exclude(public_id__startswith='0x') qs = models.Item.objects.exclude(public_id__startswith='0x')
count = pos = qs.count() count = pos = qs.count()
while (options['all'] and offset <= count) or offset < options['items']: 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]: 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() i.update_external()
pos -= 1 pos -= 1
offset += chunk offset += chunk

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, with_statement, print_function
from __future__ import division, with_statement
import math import math
import os import os
@ -57,7 +56,7 @@ def join_tiles(source_paths, target_path):
target_path, mode, large_tile_h, large_tile_i target_path, mode, large_tile_h, large_tile_i
) )
data['target_images']['large'].save(image_file) data['target_images']['large'].save(image_file)
#print image_file #print(image_file)
if mode != 'keyframes': if mode != 'keyframes':
# open small tile # open small tile
small_tile_i = int(large_tile_i / 60) 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 target_path, small_mode, small_tile_h, small_tile_i
) )
data['target_images']['small'].save(image_file) data['target_images']['small'].save(image_file)
#print image_file #print(image_file)
if mode == full_tile_mode: if mode == full_tile_mode:
# render full tile # render full tile
resized = data['target_images']['large'].resize(( resized = data['target_images']['large'].resize((
@ -171,12 +170,12 @@ def join_tiles(source_paths, target_path):
# save full timelines # save full timelines
image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, large_tile_h) image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, large_tile_h)
data['target_images']['full'].save(image_file) 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) image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, small_tile_h)
data['target_images']['full'].resize( data['target_images']['full'].resize(
(full_tile_w, small_tile_h), Image.ANTIALIAS (full_tile_w, small_tile_h), Image.ANTIALIAS
).save(image_file) ).save(image_file)
#print image_file #print(image_file)
# join cuts # join cuts
cuts = [] cuts = []
@ -187,7 +186,7 @@ def join_tiles(source_paths, target_path):
with open(p, 'r') as f: with open(p, 'r') as f:
path_cuts = json.load(f) path_cuts = json.load(f)
else: else:
print p, 'missing' print(p, 'missing')
path_cuts = [] path_cuts = []
if i > 0: if i > 0:
cuts.append(offset) cuts.append(offset)
@ -207,7 +206,7 @@ def split_tiles(path, paths, durations):
tiles = {} tiles = {}
for file_name in file_names: for file_name in file_names:
mode = re.split('\d+', file_name[8:])[0] 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]) split = re.split('[a-z]+', file_name[8 + len(mode):-4])
height, index = map(lambda x: int(x) if len(x) else -1, split) height, index = map(lambda x: int(x) if len(x) else -1, split)
if not mode in tiles: if not mode in tiles:
@ -216,7 +215,7 @@ def split_tiles(path, paths, durations):
tiles[mode][height] = 0 tiles[mode][height] = 0
if index + 1 > tiles[mode][height]: if index + 1 > tiles[mode][height]:
tiles[mode][height] = index + 1 tiles[mode][height] = index + 1
print tiles print(tiles)
# for each mode # for each mode
for mode in tiles: 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'] paths[target_data[i]['item']], mode, height, target_data[i]['tile']
) )
# target_image.save(file_name) # target_image.save(file_name)
print file_name, target_image.size print(file_name, target_image.size)

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division from __future__ import division, print_function
import os.path import os.path
import mimetypes import mimetypes
import random import random
@ -168,7 +168,7 @@ def find(request, data):
see: add, edit, get, lookup, remove, upload see: add, edit, get, lookup, remove, upload
''' '''
if settings.JSON_DEBUG: if settings.JSON_DEBUG:
print json.dumps(data, indent=2) print(json.dumps(data, indent=2))
query = parse_query(data, request.user) query = parse_query(data, request.user)
response = json_response({}) response = json_response({})

View file

@ -1,4 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
import os import os
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
@ -37,7 +38,7 @@ def get_release():
try: try:
return get_json(url) return get_json(url)
except: except:
print "Failed to load %s check your internet connection." % url print("Failed to load %s check your internet connection." % url)
sys.exit(1) sys.exit(1)
repos = { repos = {
@ -60,7 +61,7 @@ repos = {
} }
def reload_notice(base): 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): def check_services(base):
services = "pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd".split() 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 = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait() p.wait()
if p.returncode != 0: 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'): 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'): if os.path.exists('/lib/systemd/system'):
print '\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service) print('\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service))
print '\tsudo service %s start' % service print('\tsudo service %s start' % service)
print '' print('')
def run_git(path, *args): def run_git(path, *args):
cmd = ['git'] + list(args) cmd = ['git'] + list(args)
@ -90,19 +91,19 @@ if __name__ == "__main__":
os.chdir(join(base, 'pandora')) os.chdir(join(base, 'pandora'))
if get('./manage.py', 'south_installed').strip() == 'yes': if get('./manage.py', 'south_installed').strip() == 'yes':
run('./manage.py', 'syncdb') run('./manage.py', 'syncdb')
print '\nRunning "./manage.py migrate"\n' print('\nRunning "./manage.py migrate"\n')
run('./manage.py', 'migrate') run('./manage.py', 'migrate')
run('./manage.py', 'sqlfindindex') run('./manage.py', 'sqlfindindex')
run('./manage.py', 'sync_itemsort') run('./manage.py', 'sync_itemsort')
reload_notice(base) reload_notice(base)
else: else:
print "You are upgrading from an older version of pan.do/ra." print("You are upgrading from an older version of pan.do/ra.")
print "Please use ./manage.py sqldiff -a to check for updates" print("Please use ./manage.py sqldiff -a to check for updates")
print "and apply required changes. You might have to set defaults too." print("and apply required changes. You might have to set defaults too.")
print "Once done run:" print("Once done run:")
print "\tcd %s" % os.path.abspath(os.curdir) print("\tcd %s" % os.path.abspath(os.curdir))
print "\t./manage.py migrate --all --fake" print("\t./manage.py migrate --all --fake")
print "Check http://wiki.0x2620.org/wiki/pandora/DatabaseUpdate for more information" print("Check http://wiki.0x2620.org/wiki/pandora/DatabaseUpdate for more information")
elif len(sys.argv) == 2 and sys.argv[1] == 'static': elif len(sys.argv) == 2 and sys.argv[1] == 'static':
os.chdir(join(base, 'pandora')) os.chdir(join(base, 'pandora'))
run('./manage.py', 'update_static') run('./manage.py', 'update_static')
@ -114,7 +115,7 @@ if __name__ == "__main__":
old = int(old) old = int(old)
if new.isdigit(): if new.isdigit():
new = int(new) new = int(new)
print 'Post Update from %s to %s' % (old, new) print('Post Update from %s to %s' % (old, new))
if old < 3111: if old < 3111:
run('bzr', 'resolved', 'pandora/monkey_patch', 'pandora/monkey_patch/migrations') run('bzr', 'resolved', 'pandora/monkey_patch', 'pandora/monkey_patch/migrations')
if os.path.exists('pandora/monkey_patch'): if os.path.exists('pandora/monkey_patch'):
@ -201,7 +202,7 @@ if __name__ == "__main__":
run('git', 'fetch') run('git', 'fetch')
run('git', 'checkout', repos[repo]['commit']) run('git', 'checkout', repos[repo]['commit'])
else: else:
print 'Checking', repo print('Checking', repo)
run('git', 'checkout', 'master', '-q') run('git', 'checkout', 'master', '-q')
run('git', 'pull') run('git', 'pull')
revno = get_version(path) revno = get_version(path)
@ -229,8 +230,8 @@ if __name__ == "__main__":
os.chdir(join(base, 'pandora')) os.chdir(join(base, 'pandora'))
diff = get('./manage.py', 'sqldiff', '-a').strip() diff = get('./manage.py', 'sqldiff', '-a').strip()
if diff != '-- No differences': 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: 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: elif current != new:
reload_notice(base) reload_notice(base)