towards supporting python 2 and 3
- use absolute_imports - make use of six.moves - use exec instead of execfile - use list(dict) instead if dict.keys()
This commit is contained in:
parent
728ed14499
commit
1468ddbecb
89 changed files with 400 additions and 265 deletions
|
|
@ -1,9 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
import models
|
||||
from . import models
|
||||
|
||||
|
||||
class FileAdmin(admin.ModelAdmin):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, print_function
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
|
|
@ -14,7 +14,7 @@ from django.conf import settings
|
|||
from item.models import Item
|
||||
from item.tasks import load_subtitles
|
||||
|
||||
import models
|
||||
from . import models
|
||||
|
||||
info_keys = [
|
||||
'title',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, with_statement, print_function
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
import os
|
||||
from os.path import exists
|
||||
|
|
@ -14,6 +14,7 @@ import shutil
|
|||
from distutils.spawn import find_executable
|
||||
from glob import glob
|
||||
|
||||
from six import string_types
|
||||
import numpy as np
|
||||
import ox
|
||||
import ox.image
|
||||
|
|
@ -54,6 +55,7 @@ def supported_formats():
|
|||
p = subprocess.Popen([settings.FFMPEG, '-codecs'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
stdout = stdout.decode('utf-8')
|
||||
return {
|
||||
'ogg': 'libtheora' in stdout and 'libvorbis' in stdout,
|
||||
'webm': 'libvpx' in stdout and 'libvorbis' in stdout,
|
||||
|
|
@ -453,7 +455,7 @@ def timeline(video, prefix, modes=None, size=None):
|
|||
modes = ['antialias', 'slitscan', 'keyframes', 'audio', 'data']
|
||||
if size is None:
|
||||
size = [64, 16]
|
||||
if isinstance(video, basestring):
|
||||
if isinstance(video, string_types):
|
||||
video = [video]
|
||||
cmd = ['../bin/oxtimelines',
|
||||
'-s', ','.join(map(str, reversed(sorted(size)))),
|
||||
|
|
@ -621,7 +623,7 @@ def chop(video, start, end):
|
|||
stderr=open('/dev/null', 'w'),
|
||||
close_fds=True)
|
||||
p.wait()
|
||||
f = open(choped_video, 'r')
|
||||
f = open(choped_video, 'rb')
|
||||
os.unlink(choped_video)
|
||||
os.rmdir(tmp)
|
||||
return f
|
||||
|
|
|
|||
|
|
@ -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, print_function, absolute_import
|
||||
|
||||
import json
|
||||
import os.path
|
||||
|
|
@ -8,6 +8,7 @@ import shutil
|
|||
import tempfile
|
||||
import time
|
||||
|
||||
from six import string_types, PY2
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
|
@ -22,8 +23,11 @@ import item.models
|
|||
from person.models import get_name_sort
|
||||
from taskqueue.models import Task
|
||||
|
||||
from chunk import save_chunk
|
||||
import extract
|
||||
from .chunk import save_chunk
|
||||
from . import extract
|
||||
|
||||
if not PY2:
|
||||
unicode = str
|
||||
|
||||
def data_path(f, x):
|
||||
return f.get_path('data.bin')
|
||||
|
|
@ -155,7 +159,7 @@ class File(models.Model):
|
|||
if self.item:
|
||||
for key in self.ITEM_INFO:
|
||||
data[key] = self.item.get(key)
|
||||
if isinstance(data[key], basestring):
|
||||
if isinstance(data[key], string_types):
|
||||
data[key] = ox.decode_html(data[key])
|
||||
elif isinstance(data[key], list):
|
||||
data[key] = [ox.decode_html(e) for e in data[key]]
|
||||
|
|
@ -351,7 +355,7 @@ class File(models.Model):
|
|||
stream.available = True
|
||||
stream.info = {}
|
||||
stream.save()
|
||||
if self.info.keys() == ['extension']:
|
||||
if list(self.info) == ['extension']:
|
||||
self.info.update(stream.info)
|
||||
self.parse_info()
|
||||
self.save()
|
||||
|
|
@ -416,7 +420,7 @@ class File(models.Model):
|
|||
data['users'] = list(set([i['user'] for i in data['instances']]))
|
||||
data['item'] = self.item.public_id
|
||||
if keys:
|
||||
for k in data.keys():
|
||||
for k in list(data):
|
||||
if k not in keys:
|
||||
del data[k]
|
||||
return data
|
||||
|
|
@ -450,14 +454,14 @@ class File(models.Model):
|
|||
'''
|
||||
extract stream from direct upload
|
||||
'''
|
||||
import tasks
|
||||
from . import tasks
|
||||
return tasks.extract_stream.delay(self.id)
|
||||
|
||||
def process_stream(self):
|
||||
'''
|
||||
extract derivatives from webm upload
|
||||
'''
|
||||
import tasks
|
||||
from . import tasks
|
||||
return tasks.process_stream.delay(self.id)
|
||||
|
||||
def extract_tracks(self):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
from glob import glob
|
||||
|
||||
from celery.task import task
|
||||
|
|
@ -11,9 +13,9 @@ from item.models import Item
|
|||
from item.tasks import update_poster
|
||||
from taskqueue.models import Task
|
||||
|
||||
import models
|
||||
import extract
|
||||
import external
|
||||
from . import models
|
||||
from . import extract
|
||||
from . import external
|
||||
|
||||
_INSTANCE_KEYS = ('mtime', 'path')
|
||||
|
||||
|
|
@ -104,7 +106,7 @@ def update_files(user, volume, files):
|
|||
@task(ignore_results=True, queue='default')
|
||||
def update_info(user, info):
|
||||
user = models.User.objects.get(username=user)
|
||||
files = models.File.objects.filter(oshash__in=info.keys())
|
||||
files = models.File.objects.filter(oshash__in=list(info))
|
||||
for f in files:
|
||||
f.update_info(info[f.oshash], user)
|
||||
f.save()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
import os.path
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
|||
from django.conf import settings
|
||||
from django.db.models import Count, Q
|
||||
|
||||
from six import string_types
|
||||
from celery.utils import get_full_cls_name
|
||||
from celery.backends import default_backend
|
||||
import ox
|
||||
|
|
@ -404,7 +406,7 @@ def moveMedia(request, data):
|
|||
data['public_id'] = data.pop('item').strip()
|
||||
if len(data['public_id']) != 7:
|
||||
del data['public_id']
|
||||
if 'director' in data and isinstance(data['director'], basestring):
|
||||
if 'director' in data and isinstance(data['director'], string_types):
|
||||
if data['director'] == '':
|
||||
data['director'] = []
|
||||
else:
|
||||
|
|
@ -556,7 +558,7 @@ def getPath(request, data):
|
|||
'''
|
||||
response = json_response()
|
||||
ids = data['id']
|
||||
if isinstance(ids, basestring):
|
||||
if isinstance(ids, string_types):
|
||||
ids = [ids]
|
||||
for f in models.File.objects.filter(oshash__in=ids).values('path', 'oshash').order_by('sort_path'):
|
||||
response['data'][f['oshash']] = f['path']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue