Remove outdated manage.py commands

This commit is contained in:
Francesco Siddi 2016-05-18 14:54:52 +02:00
parent e35b7711a3
commit f448dce9fc

View File

@ -253,140 +253,6 @@ def clear_db():
db.drop_collection('users')
@manager.command
def upgrade_node_types():
"""Wipes node_types collection and populates it again"""
node_types_collection = app.data.driver.db['node_types']
node_types = node_types_collection.find({})
old_ids = {}
for node_type in node_types:
old_ids[node_type['name']] = node_type['_id']
populate_node_types(old_ids)
@manager.command
def manage_groups():
"""Take user email and group name,
and add or remove the user from that group.
"""
from pymongo import MongoClient
client = MongoClient(MONGO_HOST, 27017)
db = client.eve
print("")
print("Add or Remove user from group")
print("leave empty to cancel")
print("")
# Select Action
print("Do you want to Add or Remove the user from the group?")
retry = True
while retry:
action = raw_input('add/remove: ')
if action == '':
return
elif action.lower() in ['add', 'a', 'insert']:
action = 'add'
retry = False
elif action.lower() in ['remove', 'r', 'rmv', 'rem', 'delete', 'del']:
action = 'remove'
retry = False
else:
print("Incorrect action, press type 'add' or 'remove'")
# Select User
retry = True
while retry:
user_email = raw_input('User email: ')
if user_email == '':
return
user = db.users.find_one({'email': user_email})
if user:
retry = False
else:
print("Incorrect user email, try again, or leave empty to cancel")
# Select group
retry = True
while retry:
group_name = raw_input('Group name: ')
if group_name == '':
return
group = db.groups.find_one({'name': group_name})
if group:
retry = False
else:
print("Incorrect group name, try again, or leave empty to cancel")
# Do
current_groups = user.get('groups', [])
if action == 'add':
if group['_id'] in current_groups:
print("User {0} is already in group {1}".format(
user_email, group_name))
else:
current_groups.append(group['_id'])
db.users.update({'_id': user['_id']},
{"$set": {'groups': current_groups}})
print("User {0} added to group {1}".format(user_email, group_name))
elif action == 'remove':
if group['_id'] not in current_groups:
print("User {0} is not in group {1}".format(user_email, group_name))
else:
current_groups.remove(group['_id'])
db.users.update({'_id': user['_id']},
{"$set": {'groups': current_groups}})
print("User {0} removed from group {1}".format(
user_email, group_name))
def populate_node_types(old_ids={}):
node_types_collection = app.data.driver.db['node_types']
def mix_node_type(old_id, node_type_dict):
# Take eve parameters
node_type = node_types_collection.find_one({'_id': old_id})
for attr in node_type:
if attr[0] == '_':
# Mix with node eve attributes. This is really not needed since
# the attributes are stripped before doing a put_internal.
node_type_dict[attr] = node_type[attr]
elif attr == 'permissions':
node_type_dict['permissions'] = node_type['permissions']
return node_type_dict
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_id = old_ids[node_name]
node_type = mix_node_type(node_id, node_type)
# 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})
else:
print("Making the node")
print(node_type)
post_item('node_types', node_type)
# upgrade(shot_node_type, old_ids)
# upgrade(task_node_type, old_ids)
# upgrade(scene_node_type, old_ids)
# upgrade(act_node_type, old_ids)
upgrade(node_type_project, old_ids)
upgrade(node_type_group, old_ids)
upgrade(node_type_asset, old_ids)
upgrade(node_type_storage, old_ids)
upgrade(node_type_comment, old_ids)
upgrade(node_type_blog, old_ids)
upgrade(node_type_post, old_ids)
upgrade(node_type_texture, old_ids)
upgrade(node_type_group_texture, old_ids)
@manager.command
def add_parent_to_nodes():
"""Find the parent of any node in the nodes collection"""
@ -429,18 +295,6 @@ def add_parent_to_nodes():
print("Orphan {0} nodes".format(nodes_orphan))
@manager.command
def remove_children_files():
"""Remove any file object with a parent field"""
files_collection = app.data.driver.db['files']
for f in files_collection.find():
if 'parent' in f:
file_id = f['_id']
# Delete child object
files_collection.remove({'_id': file_id})
print("deleted {0}".format(file_id))
@manager.command
def make_project_public(project_id):
"""Convert every node of a project from pending to public"""
@ -454,127 +308,12 @@ def make_project_public(project_id):
put_item('nodes', n)
@manager.command
def convert_assets_to_textures(project_id):
"""Get any node of type asset in a certain project and convert it to a
node_type texture.
"""
DRY_RUN = False
node_types_collection = app.data.driver.db['node_types']
files_collection = app.data.driver.db['files']
nodes_collection = app.data.driver.db['nodes']
def parse_name(name):
"""Parse a texture name to infer properties"""
variation = 'col'
is_tileable = False
variations = ['_bump', '_spec', '_nor', '_col', '_translucency']
for v in variations:
if v in name:
variation = v[1:]
break
if '_tileable' in name:
is_tileable = True
return dict(variation=variation, is_tileable=is_tileable)
def make_texture_node(base_node, files, parent_id=None):
texture_node_type = node_types_collection.find_one({'name': 'texture'})
files_list = []
is_tileable = False
if parent_id is None:
parent_id = base_node['parent']
else:
print("Using provided parent {0}".format(parent_id))
# Create a list with all the file fariations for the texture
for f in files:
print("Processing {1} {0}".format(f['name'], f['_id']))
attributes = parse_name(f['name'])
if attributes['is_tileable']:
is_tileable = True
file_entry = dict(
file=f['properties']['file'],
is_tileable=attributes['is_tileable'],
map_type=attributes['variation'])
files_list.append(file_entry)
# Get the first file from the files list and use it as base for some
# node properties
first_file = files_collection.find_one({'_id': files[0]['properties']['file']})
if 'picture' in base_node and base_node['picture'] != None:
picture = base_node['picture']
else:
picture = first_file['_id']
if 'height' in first_file:
node = dict(
name=base_node['name'],
picture=picture,
parent=parent_id,
project=base_node['project'],
user=base_node['user'],
node_type=texture_node_type['_id'],
properties=dict(
status=base_node['properties']['status'],
files=files_list,
resolution="{0}x{1}".format(first_file['height'], first_file['width']),
is_tileable=is_tileable,
is_landscape=(first_file['height'] < first_file['width']),
aspect_ratio=round(
(first_file['width'] / first_file['height']), 2)
)
)
print("Making {0}".format(node['name']))
if not DRY_RUN:
p = post_internal('nodes', node)
if p[0]['_status'] == 'ERR':
import pprint
pprint.pprint(node)
nodes_collection = app.data.driver.db['nodes']
for n in nodes_collection.find({'project': ObjectId(project_id)}):
n_type = node_types_collection.find_one({'_id': n['node_type']})
processed_nodes = []
if n_type['name'] == 'group' and n['name'].startswith('_'):
print("Processing {0}".format(n['name']))
# Get the content of the group
children = [c for c in nodes_collection.find({'parent': n['_id']})]
make_texture_node(children[0], children, parent_id=n['parent'])
processed_nodes += children
processed_nodes.append(n)
elif n_type['name'] == 'group':
# Change group type to texture group
node_type_texture = node_types_collection.find_one(
{'name': 'group_texture'})
n['node_type'] = node_type_texture['_id']
n['properties'].pop('notes', None)
print("Updating {0}".format(n['name']))
if not DRY_RUN:
put_item('nodes', n)
# Delete processed nodes
for node in processed_nodes:
print("Removing {0} {1}".format(node['_id'], node['name']))
if not DRY_RUN:
nodes_collection.remove({'_id': node['_id']})
# Make texture out of single image
for n in nodes_collection.find({'project': ObjectId(project_id)}):
n_type = node_types_collection.find_one({'_id': n['node_type']})
if n_type['name'] == 'asset':
make_texture_node(n, [n])
# Delete processed nodes
print("Removing {0} {1}".format(n['_id'], n['name']))
if not DRY_RUN:
nodes_collection.remove({'_id': n['_id']})
@manager.command
def set_attachment_names():
"""Loop through all existing nodes and assign proper ContentDisposition
metadata to referenced files that are using GCS.
"""
from application import update_file_name
from application.utils.gcs import update_file_name
nodes_collection = app.data.driver.db['nodes']
for n in nodes_collection.find():
print("Updating node {0}".format(n['_id']))