#!/usr/bin/env python # -*- coding: utf-8 -*- # vi:si:et:sw=2:sts=2:ts=2 # GPL written 2008 by j@pad.ma import pkg_resources pkg_resources.require("TurboGears") from turbogears import config, update_config, start_server import cherrypy cherrypy.lowercase_api = True from os.path import * import sys # first look on the command line for a desired config file, # if it's not on the command line, then # look for setup.py in this directory. If it's not there, this script is # probably installed if len(sys.argv) > 1: update_config(configfile=sys.argv[1], modulename="padma.config") elif exists(join(dirname(__file__), "setup.py")): update_config(configfile="dev.cfg",modulename="padma.config") else: update_config(configfile="prod.cfg",modulename="padma.config") config.update(dict(package="padma")) from padma.model import * import os import ox import simplejson as json prefix = '/tmp/padma' os.makedirs(prefix) data = {} for v in Video.select(): data[v.hid] = v.jsondump() with open(os.path.join(prefix, 'padma_data.json'), 'w') as f: json.dump(data, f) users = [] for u in User.select().orderBy('id'): users.append({ 'id': u.id, 'username': u.user_name.strip(), 'email': u.email_address, 'password': 'sha1$$' + u.password, 'created': u.created.strftime('%Y-%m-%dT%H:%M:%SZ'), 'groups': [g.name for g in u.groups], }) with open(os.path.join(prefix, 'users.json'), 'w') as f: json.dump(users, f, indent=2) files = [] for v in Video.select().orderBy('id'): f = { 'sha1sum': v.source_hash, 'ogg': v.filename, 'id': v.hid, 'created': int(v.created.strftime('%s')) } info = ox.avinfo(v.filename) f['oshash'] = info.get('metadata', {}).get('SOURCE_OSHASH', '') f['ogg_oshash'] = info['oshash'] files.append(f) with open(os.path.join(prefix, 'padma_files.json'), 'w') as f: json.dump(files, f, indent=2)