Commit 5264d84f authored by oggei's avatar oggei

<TAB>busters strikes again

parent ace9be3d
......@@ -74,7 +74,7 @@ class VideoController(BaseController):
c.videos = h.Page(
res.query, item_count=res.count,
page=page_num, items_per_page=10)
c.title = res.title
c.title = res.title
c.what = what
c.arg = arg
c.page_num = page_num
......@@ -85,7 +85,7 @@ class VideoController(BaseController):
strategy is also simpler."""
res = model.VideoQuery.query([(what, arg)])
c.videos = res.query.order_by([desc(model.Video.publication_date)]).limit(15).all()
c.title = res.title
c.title = res.title
etag = md5.md5(u''.join([x.title for x in c.videos]).encode('utf-8')).hexdigest()
etag_cache(etag)
response.headers['Expires'] = h.httpdate(datetime.now() + timedelta(1))
......@@ -205,8 +205,8 @@ class VideoController(BaseController):
async_http = True
token = request.params.get('token')
upload = model.AsyncUpload.query.filter_by(token=token).first()
if not upload:
log.error("Could not retrieve async upload %s" % token)
if not upload:
log.error("Could not retrieve async upload %s" % token)
abort(404)
file_size = upload.size
local_file_path = upload.path()
......
......@@ -13,20 +13,20 @@ from archive import Archive
### sql tables
authors_table = Table('authors', metadata,
Column('author_id', Integer, primary_key=True),
Column('author_id', Integer, primary_key=True),
Column('archive_id', Integer, ForeignKey('archives.archive_id')),
Column('name', Unicode(128)),
Column('username', String(64), unique=True),
Column('password', String(64)),
Column('description', Unicode),
Column('email', String(64)),
Column('website', String(255)),
Column('status', String(1), index=True),
Column('name', Unicode(128)),
Column('username', String(64), unique=True),
Column('password', String(64)),
Column('description', Unicode),
Column('email', String(64)),
Column('website', String(255)),
Column('status', String(1), index=True),
Column('preferred_language', String(2), default='en'),
Column('last_login', DateTime),
Column('created_at', DateTime, default=func.current_timestamp()),
Column('modified_at', DateTime, default=func.current_timestamp())
)
Column('created_at', DateTime, default=func.current_timestamp()),
Column('modified_at', DateTime, default=func.current_timestamp())
)
authors_groups_membership_table = Table(
......@@ -61,13 +61,13 @@ class Author(object):
def __init__(self, name, username=None, password=None,
group=None, groups=None, **args):
self.name = name
if not username:
username = self.create_username(name)
self.username = username
if not password:
password = self.encrypt(self.generate_password())
self.password = password
self.name = name
if not username:
username = self.create_username(name)
self.username = username
if not password:
password = self.encrypt(self.generate_password())
self.password = password
if group:
self.groups.append(AuthorGroup.get(group))
elif groups:
......@@ -77,7 +77,7 @@ class Author(object):
setattr(self, k, v)
def __repr__(self):
return '<Author: %s (%s)>' % (self.name, self.username)
return '<Author: %s (%s)>' % (self.name, self.username)
def to_dict(self):
return nonone({
......@@ -88,8 +88,8 @@ class Author(object):
})
def modify(self):
self.modified_at = datetime.now()
Session.save_or_update(self)
self.modified_at = datetime.now()
Session.save_or_update(self)
def is_admin(self):
return (self.status == 'S')
......
......@@ -20,7 +20,7 @@ categories_table = Table('categories', metadata,
class Category(object):
def __repr__(self):
return '<Category: %s>' % self.name
return '<Category: %s>' % self.name
@classmethod
def by_archive(cls, archive):
......
......@@ -37,7 +37,7 @@ class Feed(object):
if response.bozo:
logging.error('error downloading %s: %s' % (
url, str(response.bozo_exception)))
return f.data
return f.data
logging.debug('downloaded %s, status=%d' % (url, response.status))
if response.status == 304:
return f.data
......
......@@ -83,7 +83,7 @@ class File(object):
self.name = self.guess_filename()
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.name)
return '<%s: %s>' % (self.__class__.__name__, self.name)
def to_dict(self):
file_info = {
......@@ -112,7 +112,7 @@ class File(object):
Session.save_or_update(self)
Session.commit()
Session.refresh(self)
return str(self.file_id)
return str(self.file_id)
def upload(self, local_file_name, storage):
return storage.put(self.key(), local_file_name)
......@@ -121,15 +121,15 @@ class File(object):
return storage.get(self.key())
def open(self, storage):
return storage.open(self.key())
return storage.open(self.key())
def get_url(self, storage):
"""Return an URL to download this file."""
# first search for a direct link
if self.direct_links:
n = random.randint(0, len(self.direct_links) - 1)
return str(self.direct_links[n].url)
return storage.get_url(self.key())
# first search for a direct link
if self.direct_links:
n = random.randint(0, len(self.direct_links) - 1)
return str(self.direct_links[n].url)
return storage.get_url(self.key())
def guess_filename(self):
if self.video:
......@@ -272,12 +272,12 @@ class FileRoles:
### object-relational mappings
files_join = polymorphic_union({
'video': files_table.join(files_video_table),
'subtitle': files_table.join(files_subtitle_table),
'video': files_table.join(files_video_table),
'subtitle': files_table.join(files_subtitle_table),
'screenshot': files_table.join(files_screenshots_table),
'p2p': files_table.join(files_p2p_table),
'file': files_table.select(files_table.c.ftype=='file')
}, None, 'fjoin')
'p2p': files_table.join(files_p2p_table),
'file': files_table.select(files_table.c.ftype=='file')
}, None, 'fjoin')
files_mapper = Session.mapper(
File, files_table,
......
......@@ -22,7 +22,7 @@ class UniqueAuthor(validators.FancyValidator):
class CommaSeparatedList(validators.FancyValidator):
def _to_python(self, value, state):
value = [ x.strip() for x in value.split(',') ]
return value
return value
class UniqueGroup(validators.FancyValidator):
def _to_python(self, value, state):
......
......@@ -372,7 +372,7 @@ class SmartStorage(object):
## Use compound files to avoid opening zillions of files hitting a bug
## in Python (and select limits, if we were using select).
writer.setUseCompoundFile(True)
writer.setWriteLockTimeout(10000L)
writer.setWriteLockTimeout(10000L)
if self.enable_bulk_writes:
self.configureBulkWriter(writer)
......
......@@ -6,22 +6,22 @@ from meta import *
synopsis_table = Table('synopsis', metadata,
Column('synopsis_id', Integer, primary_key=True),
Column('video_id', Integer, ForeignKey('videos.video_id'), index=True),
Column('lang', String(2), index=True),
Column('description', Unicode),
Column('short_description', Unicode),
)
Column('synopsis_id', Integer, primary_key=True),
Column('video_id', Integer, ForeignKey('videos.video_id'), index=True),
Column('lang', String(2), index=True),
Column('description', Unicode),
Column('short_description', Unicode),
)
### classes
class Synopsis(object):
def __repr__(self):
return '<Synopsis[%s] of video %s>' % (
return '<Synopsis[%s] of video %s>' % (
self.lang, str(self.video_id) )
def modify(self):
self.video.modify()
self.video.modify()
def to_dict(self):
return {'lang': self.lang,
'description': self.description,
......
......@@ -7,7 +7,7 @@ from meta import *
tags_table = Table('tags', metadata,
Column('tag_id', Integer, primary_key=True),
Column('tag', Unicode(64), unique=True)
Column('tag', Unicode(64), unique=True)
)
......@@ -16,7 +16,7 @@ tags_table = Table('tags', metadata,
class Tag(object):
def __repr__(self):
return '<Tag: %s>' % self.tag
return '<Tag: %s>' % self.tag
@classmethod
def all(cls):
......
......@@ -116,7 +116,7 @@ class Video(object):
).rstrip('=')
def __repr__(self):
return '<Video: %s>' % self.title
return '<Video: %s>' % self.title
def to_dict(self):
video_info = {
......@@ -142,8 +142,8 @@ class Video(object):
return nonone(video_info)
def get_synopsis(self, lang=None, strict=False):
"""Returns a synopsis in the specified language, if exists,
otherwise simply the first one found."""
"""Returns a synopsis in the specified language, if exists,
otherwise simply the first one found."""
if lang:
for s in self.synopsis:
if s.lang == lang:
......@@ -152,14 +152,14 @@ class Video(object):
return None
elif len(self.synopsis) > 0:
return self.synopsis[0]
else:
return None
else:
return None
def get_files_by_role(self, *roles):
"""Returns just files with a certain role (like, 'screenshot')."""
def _is_of_role(f):
return (f.role in roles)
return filter(_is_of_role, self.files)
"""Returns just files with a certain role (like, 'screenshot')."""
def _is_of_role(f):
return (f.role in roles)
return filter(_is_of_role, self.files)
def get_files_by_type(self, *types):
def _is_of_type(f):
......@@ -180,9 +180,9 @@ class Video(object):
return None
def modify(self):
self.modified_at = datetime.now()
self.modified_at = datetime.now()
lucene_api().update(self)
Session.update(self)
Session.update(self)
def set_status(self, new_status, username=None):
if self.status == new_status:
......@@ -265,23 +265,23 @@ class Video(object):
self.set_status(args.get('status'), args.get('username'))
# keywords
self.tags = []
for kw in args.get('tags'):
tag_objs = Tag.query.filter_by(tag=kw).all()
if not tag_objs:
tag_obj = Tag(tag=kw)
self.tags = []
for kw in args.get('tags'):
tag_objs = Tag.query.filter_by(tag=kw).all()
if not tag_objs:
tag_obj = Tag(tag=kw)
self.tags.append(tag_obj)
sess.save(tag_obj)
sess.save(tag_obj)
else:
self.tags.append(tag_objs[0])
# categories
self.categories = []
for cat_id in args.get('categories'):
self.categories = []
for cat_id in args.get('categories'):
cat = Category.query.get(int(cat_id))
self.categories.append(cat)
self.categories.append(cat)
# authors
# authors
self.authors = []
for author_id in args.get('authors'):
author = Author.query.get(int(author_id))
......@@ -291,10 +291,10 @@ class Video(object):
self.authors.append(author)
# synopsis
for lang in g.languages.keys():
descr = args.get('syn_' + lang)
descr_s = args.get('syn_short_' + lang)
if descr or descr_s:
for lang in g.languages.keys():
descr = args.get('syn_' + lang)
descr_s = args.get('syn_short_' + lang)
if descr or descr_s:
sy = self.get_synopsis(lang, strict=True)
if sy:
sy.description = descr
......@@ -318,18 +318,18 @@ class Video(object):
Session.mapper(Video, videos_table, properties = dict(
archive = relation(Archive, cascade="none"),
categories = relation(Category, secondary=category_videos_table, lazy=False,
#backref=backref('videos', cascade='none'),
order_by=[ asc(Category.name) ]),
authors = relation(Author, secondary=authors_videos_table, lazy=False,
backref=backref('videos', cascade="all"),
categories = relation(Category, secondary=category_videos_table, lazy=False,
#backref=backref('videos', cascade='none'),
order_by=[ asc(Category.name) ]),
authors = relation(Author, secondary=authors_videos_table, lazy=False,
backref=backref('videos', cascade="all"),
order_by=[ asc(Author.name) ]),
groups = relation(Group, secondary=groups_videos_table, lazy=True,
backref=backref('videos'), cascade='none'),
tags = relation(Tag, secondary=tags_videos_table, lazy=False,
tags = relation(Tag, secondary=tags_videos_table, lazy=False,
backref=backref('videos', lazy=True),
order_by=[ asc(Tag.tag) ]),
synopsis = relation(Synopsis, cascade="all, delete-orphan", lazy=True),
order_by=[ asc(Tag.tag) ]),
synopsis = relation(Synopsis, cascade="all, delete-orphan", lazy=True),
comments = relation(Comment, cascade="all, delete-orphan", lazy=True,
primaryjoin=
and_(videos_table.c.video_id==comments_table.c.video_id,
......@@ -339,5 +339,5 @@ Session.mapper(Video, videos_table, properties = dict(
and_(videos_table.c.video_id==comments_table.c.video_id,
comments_table.c.type==Comment.Type.REVIEW)),
)
)
)
......@@ -74,7 +74,7 @@ def add_favicon(model, archive):
def main(args):
if len(args) < 1:
print "Usage: ngv-migrate <CONFIG-FILE>"
sys.exit(1)
sys.exit(1)
conf = appconfig('config:' + args[0])
load_environment(conf.global_conf, conf.local_conf)
import ngv_frontend.model as model
......
......@@ -219,7 +219,7 @@ def create_video(model, info, author):
def main(args):
if len(args) < 1:
print "Usage: ngv-migrate <CONFIG-FILE> [<VIDEO-ID>]"
sys.exit(1)
sys.exit(1)
conf = appconfig('config:' + args[0])
load_environment(conf.global_conf, conf.local_conf)
import ngv_frontend.model as model
......@@ -247,7 +247,7 @@ def main(args):
model.Session.update(video)
model.Session.commit()
shots = create_screenshots(model, i, video, storage)
old_id_map[i] = video.video_id
old_id_map[i] = video.video_id
model.Audit.log(
'Imported from http://ngvision.org/mediabase/%d' % i,
username='admin', video_id=video.video_id
......
......@@ -12,7 +12,7 @@ from ngv_frontend.config.environment import load_environment
def main(args):
if len(args) < 1:
print "Usage: ngv-unlock-lucene <CONFIG-FILE>"
sys.exit(1)
sys.exit(1)
conf = appconfig('config:' + args[0])
load_environment(conf.global_conf, conf.local_conf)
import ngv_frontend.model as model
......@@ -22,9 +22,9 @@ def main(args):
def rmlock(l):
lock_file_name = l.collection.storage.writer.WRITE_LOCK_NAME
lock_file_path = os.path.join(config['lucene_index_path'], lock_file_name)
if os.path.exists(lock_file_path):
print "removing lockfile %s" % lock_file_path
os.remove(lock_file_path)
if os.path.exists(lock_file_path):
print "removing lockfile %s" % lock_file_path
os.remove(lock_file_path)
rmlock(l)
print "optimizing..."
l.collection.storage.optimize()
......
......@@ -25,7 +25,7 @@ def get_files(model, args):
raise Exception("Video id not found!")
query = query.filter_by(video=video)
else:
query = query.filter_by(file_id=int(clause))
query = query.filter_by(file_id=int(clause))
return query
......@@ -43,9 +43,9 @@ def do_files(model, group, action, args, job_args):
def main(args):
if len(args) < 1:
print "Usage: ngv-process-files <CONFIG-FILE> <FILEID>..."
print "Example:"
print " ngv-process-files $PWD/development.ini incoming incoming 1733 \"local_file_path='/srv/ngvision/ngv_frontend/data/storage/1/1733'\""
sys.exit(1)
print "Example:"
print " ngv-process-files $PWD/development.ini incoming incoming 1733 \"local_file_path='/srv/ngvision/ngv_frontend/data/storage/1/1733'\""
sys.exit(1)
conf = appconfig('config:' + args[0])
load_environment(conf.global_conf, conf.local_conf)
import ngv_frontend.model as model
......
......@@ -76,7 +76,7 @@ def update_archive_with_rss(model, archive):
def main(args):
if len(args) < 1:
print "Usage: ngv-migrate <CONFIG-FILE>"
sys.exit(1)
sys.exit(1)
conf = appconfig('config:' + args[0])
load_environment(conf.global_conf, conf.local_conf)
import ngv_frontend.model as model
......
......@@ -65,30 +65,30 @@ def setup_config(command, filename, section, vars):
# predefined categories
print "+ categories"
categories = [ u'mediascape',
u'war and global crisis',
u'global demos',
u'corpwatch',
u'biowar',
u'hacking, digital rights, net-art',
u'surveillance and control',
u'income and work',
u'migrants, citizenship, noborder',
u'antiproibizionismo',
u'jail and repression',
u'antifascism',
u'antimafia',
u'identity, gender, sexuality',
u'knowledge, documents, formation',
u'religion',
u'direct action',
u'history and memory',
u'ecology, health',
u'music, theatre, dance, art',
u'squatting, csa',
u'global demos italy',
u'fiction, short movies',
u'genoa g8'
]
u'war and global crisis',
u'global demos',
u'corpwatch',
u'biowar',
u'hacking, digital rights, net-art',
u'surveillance and control',
u'income and work',
u'migrants, citizenship, noborder',
u'antiproibizionismo',
u'jail and repression',
u'antifascism',
u'antimafia',
u'identity, gender, sexuality',
u'knowledge, documents, formation',
u'religion',
u'direct action',
u'history and memory',
u'ecology, health',
u'music, theatre, dance, art',
u'squatting, csa',
u'global demos italy',
u'fiction, short movies',
u'genoa g8'
]
for cname in categories:
c = model.Category(name=cname, archive=archive)
model.Session.add(c)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment