Exemple #1
0
    def create_manager(self, project, manager_type=None, parent=None):
        """Creates a new manager, owned by the current user.

        :rtype: pillarsdk.Node
        """

        from pillar.web.jinja import format_undertitle

        api = pillar_api()
        node_type = project.get_node_type(node_type_manager['name'])
        if not node_type:
            raise ValueError('Project %s not set up for Flamenco' %
                             project._id)

        node_props = dict(
            name='New manager',
            project=project['_id'],
            user=flask_login.current_user.objectid,
            node_type=node_type['name'],
            properties={
                'status': node_type['dyn_schema']['status']['default'],
            },
        )

        if manager_type:
            node_props['name'] = format_undertitle(manager_type)
            node_props['properties']['manager_type'] = manager_type
        if parent:
            node_props['parent'] = parent

        manager = pillarsdk.Node(node_props)
        manager.create(api=api)
        return manager
Exemple #2
0
    def test_create_asset(self):
        with self.app.test_request_context():
            asset = pillarsdk.Node({
                'description': '',
                'project': str(self.project_id),
                'node_type': 'asset',
                'user': str(self.user_id),
                'properties': {
                    'status': 'published',
                    'content_type': 'je moeder'
                },
                'name': 'Test asset'
            })
            created_ok = asset.create(api=self.sdk_api)
            self.assertTrue(created_ok)
            self.assertTrue(asset._id)

        with self.app.test_request_context():
            # Check the asset in MongoDB
            resp = self.get(url_for('nodes|item_lookup', _id=asset._id),
                            auth_token='token')
            db_asset = resp.json()
            self.assertEqual('Test asset', db_asset['name'])

        return asset
    async def thumbnail_strip(self, context, strip):
        atc_object_id = getattr(strip, 'atc_object_id', None)
        if not atc_object_id:
            self.report({'ERROR'}, 'Strip %s not set up for Attract' % strip.name)
            self.quit()
            return

        with self.thumbnail_render_settings(context):
            bpy.ops.render.render()
        file_id = await self.upload_via_tempdir(bpy.data.images['Render Result'],
                                                'attract_shot_thumbnail.jpg')

        if file_id is None:
            self.quit()
            return

        # Update the shot to include this file as the picture.
        node = pillarsdk.Node({'_id': atc_object_id})
        await pillar.pillar_call(
            node.patch,
            {
                'op': 'from-blender',
                '$set': {
                    'picture': file_id,
                }
            })
    def submit_update(self, strip):
        import pillarsdk
        from .. import pillar

        patch = {
            'op': 'from-blender',
            '$set': {
                'name': strip.atc_name,
                'properties.trim_start_in_frames': strip.frame_offset_start,
                'properties.trim_end_in_frames': strip.frame_offset_end,
                'properties.duration_in_edit_in_frames': strip.frame_final_duration,
                'properties.cut_in_timeline_in_frames': strip.frame_final_start,
                'properties.status': strip.atc_status,
                'properties.used_in_edit': True,
            }
        }

        node = pillarsdk.Node({'_id': strip.atc_object_id})
        result = pillar.sync_call(node.patch, patch)
        log.info('PATCH result: %s', result)
Exemple #5
0
    def delete_manager(self, manager_id, etag):
        api = pillar_api()

        self._log.info('Deleting manager %s', manager_id)
        manager = pillarsdk.Node({'_id': manager_id, '_etag': etag})
        manager.delete(api=api)
Exemple #6
0
    def delete_job(self, job_id, etag):
        api = pillar_api()

        self._log.info('Deleting job %s', job_id)
        job = pillarsdk.Node({'_id': job_id, '_etag': etag})
        job.delete(api=api)
Exemple #7
0
def process_node_form(form, node_id=None, node_type=None, user=None):
    """Generic function used to process new nodes, as well as edits
    """
    if not user:
        log.warning(
            'process_node_form(node_id=%s) called while user not logged in',
            node_id)
        return False

    api = system_util.pillar_api()
    node_schema = node_type['dyn_schema'].to_dict()
    form_schema = node_type['form_schema'].to_dict()

    if node_id:
        # Update existing node
        node = pillarsdk.Node.find(node_id, api=api)
        node.name = form.name.data
        node.description = form.description.data
        if 'picture' in form:
            node.picture = form.picture.data
            if node.picture == 'None' or node.picture == '':
                node.picture = None
        if 'parent' in form:
            if form.parent.data != "":
                node.parent = form.parent.data

        for prop_name, schema_prop, form_prop in iter_node_properties(
                node_type):
            data = form[prop_name].data
            if schema_prop['type'] == 'dict':
                data = attachments.attachment_form_parse_post_data(data)
            elif schema_prop['type'] == 'integer':
                if not data:
                    data = None
                else:
                    data = int(form[prop_name].data)
            elif schema_prop['type'] == 'float':
                if not data:
                    data = None
                else:
                    data = float(form[prop_name].data)
            elif schema_prop['type'] == 'datetime':
                data = datetime.strftime(
                    data, current_app.config['RFC1123_DATE_FORMAT'])
            elif schema_prop['type'] == 'list':
                if prop_name == 'files':
                    # Only keep those items that actually refer to a file.
                    data = [
                        file_item for file_item in data
                        if file_item.get('file')
                    ]
                else:
                    log.warning('Ignoring property %s of type %s', prop_name,
                                schema_prop['type'])
                # elif pr == 'tags':
                #     data = [tag.strip() for tag in data.split(',')]
            elif schema_prop['type'] == 'objectid':
                if data == '':
                    # Set empty object to None so it gets removed by the
                    # SDK before node.update()
                    data = None
            else:
                if prop_name in form:
                    data = form[prop_name].data
            path = prop_name.split('__')
            assert len(path) == 1
            if len(path) > 1:
                recursive_prop = recursive(path, node.properties.to_dict(),
                                           data)
                node.properties = recursive_prop
            else:
                node.properties[prop_name] = data

        ok = node.update(api=api)
        if not ok:
            log.warning('Unable to update node: %s', node.error)
        # if form.picture.data:
        #     image_data = request.files[form.picture.name].read()
        #     post = node.replace_picture(image_data, api=api)
        return ok
    else:
        # Create a new node
        node = pillarsdk.Node()
        prop = {}
        files = {}
        prop['name'] = form.name.data
        prop['description'] = form.description.data
        prop['user'] = user
        if 'picture' in form:
            prop['picture'] = form.picture.data
            if prop['picture'] == 'None' or prop['picture'] == '':
                prop['picture'] = None
        if 'parent' in form:
            prop['parent'] = form.parent.data
        prop['properties'] = {}

        def get_data(node_schema, form_schema, prefix=""):
            for pr in node_schema:
                schema_prop = node_schema[pr]
                form_prop = form_schema.get(pr, {})
                if pr == 'items':
                    continue
                if 'visible' in form_prop and not form_prop['visible']:
                    continue
                prop_name = "{0}{1}".format(prefix, pr)
                if schema_prop['type'] == 'dict':
                    get_data(schema_prop['schema'], form_prop['schema'],
                             "{0}__".format(prop_name))
                    continue
                data = form[prop_name].data
                if schema_prop['type'] == 'media':
                    tmpfile = '/tmp/binary_data'
                    data.save(tmpfile)
                    binfile = open(tmpfile, 'rb')
                    files[pr] = binfile
                    continue
                if schema_prop['type'] == 'integer':
                    if data == '':
                        data = 0
                if schema_prop['type'] == 'list':
                    if data == '':
                        data = []
                if schema_prop['type'] == 'datetime':
                    data = datetime.strftime(data,
                                             app.config['RFC1123_DATE_FORMAT'])
                if schema_prop['type'] == 'objectid':
                    if data == '':
                        data = None
                path = prop_name.split('__')
                if len(path) > 1:
                    prop['properties'] = recursive(path, prop['properties'],
                                                   data)
                else:
                    prop['properties'][prop_name] = data

        get_data(node_schema, form_schema)

        prop['node_type'] = form.node_type_id.data
        post = node.post(prop, api=api)

        return post
Exemple #8
0
def process_node_form(form, node_id=None, node_type=None, user=None):
    """Generic function used to process new nodes, as well as edits
    """
    if not user:
        print("User is None")
        return False
    api = SystemUtility.attract_api()
    node_schema = node_type['dyn_schema'].to_dict()
    form_schema = node_type['form_schema'].to_dict()

    if node_id:
        # Update existing node
        node = pillarsdk.Node.find(node_id, api=api)
        node.name = form.name.data
        node.description = form.description.data
        if 'picture' in form:
            node.picture = form.picture.data
            if node.picture == "None":
                node.picture = None
        if 'parent' in form:
            node.parent = form.parent.data

        def update_data(node_schema, form_schema, prefix=""):
            for pr in node_schema:
                schema_prop = node_schema[pr]
                form_prop = form_schema[pr]
                if pr == 'items':
                    continue
                if 'visible' in form_prop and not form_prop['visible']:
                    continue
                prop_name = "{0}{1}".format(prefix, pr)
                if schema_prop['type'] == 'dict':
                    update_data(schema_prop['schema'], form_prop['schema'],
                                "{0}__".format(prop_name))
                    continue
                data = form[prop_name].data
                if schema_prop['type'] == 'dict':
                    if data == 'None':
                        continue
                if schema_prop['type'] == 'integer':
                    if data == '':
                        data = 0
                    else:
                        data = int(form[prop_name].data)
                if schema_prop['type'] == 'datetime':
                    data = datetime.strftime(data, RFC1123_DATE_FORMAT)
                else:
                    if pr in form:
                        data = form[prop_name].data
                path = prop_name.split('__')
                if len(path) > 1:
                    recursive_prop = recursive(path, node.properties.to_dict(),
                                               data)
                    node.properties = recursive_prop
                else:
                    node.properties[prop_name] = data

        update_data(node_schema, form_schema)
        # send_file(form, node, user)
        update = node.update(api=api)
        # if form.picture.data:
        #     image_data = request.files[form.picture.name].read()
        #     post = node.replace_picture(image_data, api=api)
        return update
    else:
        # Create a new node
        node = pillarsdk.Node()
        prop = {}
        files = {}
        prop['name'] = form.name.data
        prop['description'] = form.description.data
        prop['user'] = user
        if 'picture' in form:
            prop['picture'] = form.picture.data
            if prop['picture'] == 'None':
                prop['picture'] = None
        if 'parent' in form:
            prop['parent'] = form.parent.data
        prop['properties'] = {}

        def get_data(node_schema, form_schema, prefix=""):
            for pr in node_schema:
                schema_prop = node_schema[pr]
                form_prop = form_schema[pr]
                if pr == 'items':
                    continue
                if 'visible' in form_prop and not form_prop['visible']:
                    continue
                prop_name = "{0}{1}".format(prefix, pr)
                if schema_prop['type'] == 'dict':
                    get_data(schema_prop['schema'], form_prop['schema'],
                             "{0}__".format(prop_name))
                    continue
                data = form[prop_name].data
                if schema_prop['type'] == 'media':
                    tmpfile = '/tmp/binary_data'
                    data.save(tmpfile)
                    binfile = open(tmpfile, 'rb')
                    files[pr] = binfile
                    continue
                if schema_prop['type'] == 'integer':
                    if data == '':
                        data = 0
                if schema_prop['type'] == 'list':
                    if data == '':
                        data = []
                if schema_prop['type'] == 'datetime':
                    data = datetime.strftime(data, RFC1123_DATE_FORMAT)
                if schema_prop['type'] == 'objectid':
                    if data == '':
                        data = None
                path = prop_name.split('__')
                if len(path) > 1:
                    prop['properties'] = recursive(path, prop['properties'],
                                                   data)
                else:
                    prop['properties'][prop_name] = data

        get_data(node_schema, form_schema)

        prop['node_type'] = form.node_type_id.data
        post = node.post(prop, api=api)

        return post
Exemple #9
0
    def delete_task(self, task_id, etag):
        api = pillar_api()

        self._log.info('Deleting task %s', task_id)
        task = pillarsdk.Node({'_id': task_id, '_etag': etag})
        task.delete(api=api)