2015-04-24 11:57:40 +02:00
|
|
|
import os
|
2015-02-04 02:02:21 +01:00
|
|
|
from application import app
|
2015-04-10 13:08:45 -03:00
|
|
|
from application import post_item
|
2015-02-04 02:02:21 +01:00
|
|
|
from flask.ext.script import Manager
|
|
|
|
|
|
|
|
manager = Manager(app)
|
2015-04-07 14:31:41 +02:00
|
|
|
|
2015-04-01 10:10:26 -03:00
|
|
|
@manager.command
|
|
|
|
def runserver():
|
|
|
|
try:
|
2015-04-24 11:57:40 +02:00
|
|
|
import config
|
|
|
|
PORT = config.Development.PORT
|
|
|
|
HOST = config.Development.HOST
|
|
|
|
DEBUG = config.Development.DEBUG
|
|
|
|
app.config['FILE_STORAGE'] = config.Development.FILE_STORAGE
|
2015-04-01 10:10:26 -03:00
|
|
|
except ImportError:
|
2015-04-24 11:57:40 +02:00
|
|
|
# Default settings
|
|
|
|
PORT = 5000
|
|
|
|
HOST = '0.0.0.0'
|
|
|
|
DEBUG = True
|
|
|
|
app.config['FILE_STORAGE'] = '{0}/application/static/storage'.format(
|
2015-05-11 14:08:58 +02:00
|
|
|
os.path.dirname(os.path.realpath(__file__)))
|
2015-04-24 11:57:40 +02:00
|
|
|
|
|
|
|
# Automatic creation of FILE_STORAGE path if it's missing
|
|
|
|
if not os.path.exists(app.config['FILE_STORAGE']):
|
2015-05-11 14:08:58 +02:00
|
|
|
os.makedirs(app.config['FILE_STORAGE'])
|
2015-04-01 10:10:26 -03:00
|
|
|
|
|
|
|
app.run(
|
|
|
|
port=PORT,
|
|
|
|
host=HOST,
|
|
|
|
debug=DEBUG)
|
|
|
|
|
2015-04-07 14:40:39 +02:00
|
|
|
|
2015-04-08 18:09:04 +02:00
|
|
|
@manager.command
|
|
|
|
def clear_db():
|
|
|
|
"""Wipes the database
|
|
|
|
"""
|
|
|
|
from pymongo import MongoClient
|
|
|
|
|
|
|
|
client = MongoClient()
|
|
|
|
db = client.eve
|
|
|
|
db.drop_collection('nodes')
|
|
|
|
db.drop_collection('node_types')
|
|
|
|
db.drop_collection('tokens')
|
|
|
|
db.drop_collection('users')
|
|
|
|
|
|
|
|
|
2015-04-13 15:08:44 -03:00
|
|
|
@manager.command
|
|
|
|
def upgrade_node_types():
|
|
|
|
"""Wipes node_types collection
|
|
|
|
and populates it again
|
|
|
|
"""
|
|
|
|
from pymongo import MongoClient
|
|
|
|
|
|
|
|
client = MongoClient()
|
|
|
|
db = client.eve
|
|
|
|
node_types = db.node_types.find({})
|
|
|
|
old_ids = {}
|
|
|
|
for nt in node_types:
|
|
|
|
old_ids[nt['name']] = nt['_id']
|
|
|
|
populate_node_types(old_ids)
|
|
|
|
|
|
|
|
|
2015-04-07 14:40:39 +02:00
|
|
|
@manager.command
|
|
|
|
def populate_db_test():
|
|
|
|
"""Populate the db with sample data
|
|
|
|
"""
|
2015-04-13 15:08:44 -03:00
|
|
|
populate_node_types()
|
|
|
|
|
2015-04-07 14:40:39 +02:00
|
|
|
|
2015-04-13 15:08:44 -03:00
|
|
|
def populate_node_types(old_ids={}):
|
2015-04-07 14:40:39 +02:00
|
|
|
shot_node_type = {
|
|
|
|
"name": "shot",
|
|
|
|
"description": "Shot Node Type, for shots",
|
|
|
|
"dyn_schema": {
|
|
|
|
"url": {
|
|
|
|
"type": "string",
|
|
|
|
},
|
|
|
|
"cut_in": {
|
|
|
|
"type": "integer"
|
|
|
|
},
|
|
|
|
"cut_out": {
|
|
|
|
"type": "integer"
|
|
|
|
},
|
|
|
|
"status": {
|
|
|
|
"type": "string",
|
2015-05-27 01:13:14 +02:00
|
|
|
"allowed": [
|
|
|
|
"on_hold",
|
|
|
|
"todo",
|
|
|
|
"in_progress",
|
2015-05-28 15:30:26 +02:00
|
|
|
"review",
|
2015-05-27 01:13:14 +02:00
|
|
|
"final"
|
|
|
|
],
|
2015-04-07 14:40:39 +02:00
|
|
|
},
|
|
|
|
"notes": {
|
|
|
|
"type": "string",
|
|
|
|
"maxlength": 256,
|
|
|
|
},
|
|
|
|
"shot_group": {
|
|
|
|
"type": "string",
|
|
|
|
#"data_relation": {
|
|
|
|
# "resource": "nodes",
|
|
|
|
# "field": "_id",
|
|
|
|
#},
|
2015-05-28 15:30:26 +02:00
|
|
|
},
|
|
|
|
"order": {
|
|
|
|
"type": "integer",
|
2015-04-07 14:40:39 +02:00
|
|
|
}
|
|
|
|
},
|
2015-04-13 15:08:44 -03:00
|
|
|
"form_schema": {
|
|
|
|
"url": {},
|
|
|
|
"cut_in": {},
|
|
|
|
"cut_out": {},
|
|
|
|
"status": {},
|
|
|
|
"notes": {},
|
|
|
|
"order": {},
|
|
|
|
"shot_group": {}
|
|
|
|
},
|
|
|
|
"parent": {
|
2015-04-20 19:21:35 -03:00
|
|
|
"node_types": ["scene"]
|
2015-04-13 15:08:44 -03:00
|
|
|
}
|
2015-04-10 13:08:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
task_node_type = {
|
|
|
|
"name": "task",
|
|
|
|
"description": "Task Node Type, for tasks",
|
|
|
|
"dyn_schema": {
|
|
|
|
"status": {
|
|
|
|
"type": "string",
|
|
|
|
"allowed": [
|
|
|
|
"todo",
|
2015-05-27 01:13:14 +02:00
|
|
|
"in_progress",
|
2015-05-27 01:34:28 +02:00
|
|
|
"on_hold",
|
|
|
|
"approved",
|
2015-04-10 13:08:45 -03:00
|
|
|
"cbb",
|
2015-05-27 01:13:14 +02:00
|
|
|
"final",
|
2015-05-28 15:30:26 +02:00
|
|
|
"review"
|
2015-04-10 13:08:45 -03:00
|
|
|
],
|
|
|
|
"required": True,
|
|
|
|
},
|
2015-05-27 01:13:14 +02:00
|
|
|
"filepath": {
|
|
|
|
"type": "string",
|
|
|
|
},
|
|
|
|
"revision": {
|
|
|
|
"type": "integer",
|
|
|
|
},
|
2015-04-10 13:08:45 -03:00
|
|
|
"owners": {
|
|
|
|
"type": "dict",
|
|
|
|
"schema": {
|
|
|
|
"users": {
|
|
|
|
"type": "list",
|
2015-04-14 12:04:50 -03:00
|
|
|
"schema": {
|
2015-04-15 10:25:31 -03:00
|
|
|
"type": "objectid",
|
2015-04-14 12:04:50 -03:00
|
|
|
}
|
2015-04-10 13:08:45 -03:00
|
|
|
},
|
|
|
|
"groups": {
|
|
|
|
"type": "list",
|
2015-04-14 12:04:50 -03:00
|
|
|
"schema": {
|
2015-04-15 10:25:31 -03:00
|
|
|
"type": "objectid",
|
2015-04-14 12:04:50 -03:00
|
|
|
}
|
2015-04-10 13:08:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"time": {
|
|
|
|
"type": "dict",
|
|
|
|
"schema": {
|
|
|
|
"start": {
|
|
|
|
"type": "datetime"
|
|
|
|
},
|
|
|
|
"duration": {
|
|
|
|
"type": "integer"
|
|
|
|
},
|
|
|
|
"chunks": {
|
|
|
|
"type": "list",
|
2015-04-13 15:08:44 -03:00
|
|
|
"schema": {
|
|
|
|
"type": "dict",
|
|
|
|
"schema": {
|
|
|
|
"start": {
|
|
|
|
"type": "datetime",
|
|
|
|
},
|
|
|
|
"duration": {
|
|
|
|
"type": "integer",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2015-05-28 15:30:26 +02:00
|
|
|
},
|
|
|
|
"is_conflicting" : {
|
|
|
|
"type": "boolean"
|
|
|
|
},
|
|
|
|
"is_processing" : {
|
|
|
|
"type": "boolean"
|
|
|
|
},
|
|
|
|
"is_open" : {
|
|
|
|
"type": "boolean"
|
2015-04-13 15:08:44 -03:00
|
|
|
}
|
2015-05-28 15:30:26 +02:00
|
|
|
|
2015-04-13 15:08:44 -03:00
|
|
|
},
|
|
|
|
"form_schema": {
|
|
|
|
"status": {},
|
2015-05-27 01:13:14 +02:00
|
|
|
"filepath": {},
|
|
|
|
"revision": {},
|
2015-04-13 15:08:44 -03:00
|
|
|
"owners": {
|
|
|
|
"schema": {
|
2015-04-15 10:25:31 -03:00
|
|
|
"users":{
|
2015-05-27 01:34:28 +02:00
|
|
|
"items": [('User', 'first_name')],
|
2015-04-15 10:25:31 -03:00
|
|
|
},
|
2015-05-27 01:13:14 +02:00
|
|
|
"groups": {}
|
2015-04-13 15:08:44 -03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"time": {
|
|
|
|
"schema": {
|
|
|
|
"start": {},
|
|
|
|
"duration": {},
|
|
|
|
"chunks": {
|
|
|
|
"visible": False,
|
|
|
|
"schema": {
|
2015-04-20 19:21:35 -03:00
|
|
|
"start": {},
|
|
|
|
"duration": {}
|
2015-04-13 15:08:44 -03:00
|
|
|
}
|
2015-04-10 13:08:45 -03:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:30:26 +02:00
|
|
|
},
|
|
|
|
"is_conflicting": {},
|
|
|
|
"is_open": {},
|
|
|
|
"is_processing": {},
|
2015-04-10 13:08:45 -03:00
|
|
|
},
|
2015-04-13 15:08:44 -03:00
|
|
|
"parent": {
|
|
|
|
"node_types": ["shot"],
|
2015-04-07 14:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 19:21:35 -03:00
|
|
|
scene_node_type = {
|
|
|
|
'name': 'scene',
|
|
|
|
'description': 'Scene node type',
|
|
|
|
'dyn_schema': {
|
|
|
|
'order': {
|
|
|
|
'type': 'integer',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'form_schema': {
|
|
|
|
'order': {},
|
|
|
|
},
|
|
|
|
'parent': {
|
|
|
|
"node_types": ["act"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
act_node_type = {
|
|
|
|
'name': 'act',
|
|
|
|
'description': 'Act node type',
|
|
|
|
'dyn_schema': {
|
|
|
|
'order': {
|
|
|
|
'type': 'integer',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'form_schema': {
|
|
|
|
'order': {},
|
|
|
|
},
|
|
|
|
'parent': {}
|
|
|
|
}
|
2015-04-13 15:08:44 -03:00
|
|
|
|
2015-04-22 12:01:50 -03:00
|
|
|
comment_node_type = {
|
|
|
|
'name': 'comment',
|
|
|
|
'description': 'Comment node type',
|
|
|
|
'dyn_schema': {
|
|
|
|
'text': {
|
|
|
|
'type': 'string',
|
|
|
|
'maxlength': 256
|
|
|
|
},
|
|
|
|
'attachments': {
|
|
|
|
'type': 'list',
|
|
|
|
'schema': {
|
2015-05-01 11:32:42 -03:00
|
|
|
'type': 'objectid',
|
|
|
|
'data_relation': {
|
|
|
|
'resource': 'files',
|
|
|
|
'field': '_id',
|
|
|
|
'embeddable': True
|
|
|
|
}
|
2015-04-22 12:01:50 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'form_schema': {
|
|
|
|
'text': {},
|
|
|
|
'attachments': {
|
|
|
|
'items': [("File", "name")]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'parent': {
|
|
|
|
"node_types": ["shot", "task"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 15:08:44 -03:00
|
|
|
from pymongo import MongoClient
|
|
|
|
|
|
|
|
client = MongoClient()
|
|
|
|
db = client.eve
|
|
|
|
|
|
|
|
def mix_node_type(old_id, node_type_dict):
|
|
|
|
# Take eve parameters
|
|
|
|
node_type = db.node_types.find({'_id':old_id})
|
|
|
|
node_type = node_type[0]
|
|
|
|
for attr in node_type:
|
|
|
|
if attr[0]=='_':
|
|
|
|
# Mix with node type attributes
|
|
|
|
node_type_dict[attr]=node_type[attr]
|
|
|
|
return node_type_dict
|
|
|
|
|
2015-04-20 19:21:35 -03:00
|
|
|
def upgrade(node_type, old_ids):
|
|
|
|
node_name = node_type['name']
|
|
|
|
if node_name in old_ids:
|
|
|
|
node_type = mix_node_type(old_ids[node_name], node_type)
|
|
|
|
# Remove old node_type
|
|
|
|
db.node_types.remove({'_id': old_ids[node_name]})
|
|
|
|
# Insert new node_type
|
|
|
|
db.node_types.insert(node_type)
|
|
|
|
else:
|
|
|
|
post_item('node_types', node_type)
|
2015-04-13 15:08:44 -03:00
|
|
|
|
2015-04-20 19:21:35 -03:00
|
|
|
upgrade(shot_node_type, old_ids)
|
|
|
|
upgrade(task_node_type, old_ids)
|
|
|
|
upgrade(scene_node_type, old_ids)
|
|
|
|
upgrade(act_node_type, old_ids)
|
2015-04-22 12:01:50 -03:00
|
|
|
upgrade(comment_node_type, old_ids)
|
2015-04-07 14:40:39 +02:00
|
|
|
|
|
|
|
|
2015-03-12 15:05:10 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
manager.run()
|