def add_node_asset(file_id): """Creates a node of type asset, starting from an existing file id. :param file_id: the file id to use :param picture_id: the picture id to use :param group_id: the parent folder """ picture_id = None parent_id = None from bson.objectid import ObjectId from pymongo import MongoClient client = MongoClient(MONGO_HOST, 27017) db = client.eve file_object = db.files.find_one({"_id": ObjectId(file_id)}) node_type = db.node_types.find_one({"name": "asset"}) print file_object['content_type'].split('/')[0] node = { 'name': file_object['name'], 'description': file_object['description'], #'picture': picture_id, #'parent': parent_id, 'user': file_object['user'], 'node_type': node_type['_id'], 'properties': { 'status': 'published', 'content_type': file_object['content_type'].split('/')[0], 'file': file_id } } r = post_item('nodes', node) return r
def upgrade(node_type, old_ids): print("Node {0}".format(node_type['name'])) node_name = node_type['name'] if node_name in old_ids: node_type = mix_node_type(old_ids[node_name], node_type) node_id = node_type['_id'] # Removed internal fields that would cause validation error internal_fields = ['_id', '_etag', '_updated', '_created'] for field in internal_fields: node_type.pop(field, None) p = put_internal('node_types', node_type, **{'_id': node_id}) print p else: print("Making the node") print(node_type) post_item('node_types', node_type)
def build_thumbnails(file_path=None, file_id=None): files_collection = app.data.driver.db['files'] if file_path: # Search file with backend "pillar" and path=file_path file_ = files_collection.find({"path": "{0}".format(file_path)}) file_ = file_[0] if file_id: file_ = files_collection.find_one({"_id": ObjectId(file_id)}) file_path = file_['name'] user = file_['user'] file_full_path = os.path.join(app.config['SHARED_DIR'], file_path) # Does the original file exist? if not os.path.isfile(file_full_path): return "", 404 else: thumbnails = generate_local_thumbnails(file_full_path, return_image_stats=True) for size, thumbnail in thumbnails.iteritems(): if thumbnail.get('exists'): # If a thumbnail was already made, we just continue continue basename = os.path.basename(thumbnail['path']) root, ext = os.path.splitext(basename) path = os.path.join(basename[:2], basename) file_object = dict( name=root, #description="Preview of file {0}".format(file_['name']), user=user, parent=file_['_id'], size=size, format=ext[1:], width=thumbnail['width'], height=thumbnail['height'], content_type=thumbnail['content_type'], length=thumbnail['length'], md5=thumbnail['md5'], filename=basename, backend=file_['backend'], path=path) # Commit to database r = post_item('files', file_object) if r[0]['_status'] == 'ERR': return "", r[3] # The error code from the request return "", 200
def commit_object(collection, f, parent=None): variation_id = f.get('variation_id') if variation_id: del f['variation_id'] asset_id = f.get('asset_id') if asset_id: del f['asset_id'] node_id = f.get('node_id') if node_id: del f['node_id'] if parent: f['parent'] = parent else: if f.get('parent'): del f['parent'] #r = [{'_status': 'OK', '_id': 'DRY-ID'}] r = post_item(collection, f) if r[0]['_status'] == 'ERR': print r[0]['_issues'] print "Tried to commit the following object" pprint.pprint(f) # Assign the Mongo ObjectID f['_id'] = str(r[0]['_id']) # Restore variation_id if variation_id: f['variation_id'] = variation_id if asset_id: f['asset_id'] = asset_id if node_id: f['node_id'] = node_id try: print "{0} {1}".format(f['_id'], f['name']) except UnicodeEncodeError: print "{0}".format(f['_id']) return f
def add_file_video(): from datetime import datetime RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' video = { 'name': 'Video test', 'description': 'Video test description', # 'parent': 'objectid', 'content_type': 'video/mp4', # Duration in seconds, only if it's a video 'duration': 50, 'size': '720p', 'format': 'mp4', 'width': 1280, 'height': 720, 'user': '******', 'length': 15000, 'md5': 'md5', 'filename': 'The file name', 'backend': 'pillar', 'path': '0000.mp4', } r = post_item('files', video) return r
def add_groups(): """Add permisions """ admin_group = { 'name': 'admin', 'permissions': [ {'node_type': get_id('node_types', 'shot'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'task'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'scene'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'act'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, ] } post_item('groups', admin_group) owner_group = { 'name': 'owner', 'permissions': [ {'node_type': get_id('node_types', 'shot'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'task'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'scene'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'act'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, {'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, ] } post_item('groups', owner_group) world_group = { 'name': 'world', 'permissions': [ {'node_type': get_id('node_types', 'shot'), 'permissions': ['GET'] }, {'node_type': get_id('node_types', 'task'), 'permissions': ['GET'] }, {'node_type': get_id('node_types', 'scene'), 'permissions': ['GET'] }, {'node_type': get_id('node_types', 'act'), 'permissions': ['GET'] }, {'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'POST'] }, ] } post_item('groups', world_group)
def add_groups(): """Add permisions """ admin_group = { 'name': 'admin', 'permissions': [ { 'node_type': get_id('node_types', 'shot'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'task'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'scene'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'act'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'POST', 'UPDATE', 'DELETE'] }, ] } post_item('groups', admin_group) owner_group = { 'name': 'owner', 'permissions': [ { 'node_type': get_id('node_types', 'shot'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'task'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'scene'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'act'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, { 'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'UPDATE', 'DELETE'] }, ] } post_item('groups', owner_group) world_group = { 'name': 'world', 'permissions': [ { 'node_type': get_id('node_types', 'shot'), 'permissions': ['GET'] }, { 'node_type': get_id('node_types', 'task'), 'permissions': ['GET'] }, { 'node_type': get_id('node_types', 'scene'), 'permissions': ['GET'] }, { 'node_type': get_id('node_types', 'act'), 'permissions': ['GET'] }, { 'node_type': get_id('node_types', 'comment'), 'permissions': ['GET', 'POST'] }, ] } post_item('groups', world_group)