How to use the codalab.lib.worksheet_util function in codalab

To help you get started, we’ve selected a few codalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codalab / codalab-worksheets / codalab / lib / bundle_cli.py View on Github external
def do_info_command(self, args):
        args.bundle_spec = spec_util.expand_specs(args.bundle_spec)
        client, worksheet_uuid = self.parse_client_worksheet_uuid(args.worksheet_spec)

        bundles = client.fetch('bundles', params={
            'specs': args.bundle_spec,
            'worksheet': worksheet_uuid,
            'include': ['owner'] + (['children', 'group_permissions', 'host_worksheets'] if args.verbose else []),
        })

        for i, info in enumerate(bundles):
            if args.field:
                # Display individual fields (arbitrary genpath)
                values = []
                for genpath in args.field.split(','):
                    if worksheet_util.is_file_genpath(genpath):
                        value = contents_str(client.interpret_file_genpaths([(info['id'], genpath, None)])[0])
                    else:
                        value = worksheet_util.interpret_genpath(info, genpath)
                    values.append(value)
                print >>self.stdout, '\t'.join(map(str, values))
            else:
                # Display all the fields
                if i > 0:
                    print
                self.print_basic_info(client, info, args.raw)
                if args.verbose:
                    self.print_children(info)
                    self.print_host_worksheets(info)
                    self.print_permissions(info)
                    self.print_contents(client, info)
github codalab / codalab-worksheets / codalab / model / bundle_model.py View on Github external
.where(clause)
                .offset(offset)
                .limit(limit)
            )

        # Sort
        if sort_key[0] is not None:
            query = query.order_by(sort_key[0])

        # Count
        if count:
            query = alias(query).count()

        result = self._execute_query(query)
        if count or sum_key[0] is not None:  # Just returning a single number
            result = worksheet_util.apply_func(format_func, result[0])
            return {'result': result, 'is_aggregate': True}
        return {'result': result, 'is_aggregate': False}
github codalab / codalab-worksheets / codalab / lib / bundle_util.py View on Github external
)
                                    client.create('worksheet-items', data=item2)

                            # Add the bundle item
                            client.create(
                                'worksheet-items',
                                data={
                                    'type': worksheet_util.TYPE_BUNDLE,
                                    'worksheet': JsonApiRelationship('worksheets', worksheet_uuid),
                                    'bundle': JsonApiRelationship('bundles', new_bundle_uuid),
                                },
                            )
                            new_bundle_uuids_added.add(new_bundle_uuid)
                            just_added = True

                if (item['type'] == worksheet_util.TYPE_MARKUP and item['value'] != '') or item[
                    'type'
                ] == worksheet_util.TYPE_DIRECTIVE:
                    prelude_items.append(item)  # Include in prelude
                else:
                    prelude_items = []  # Reset

        # Add the bundles that haven't been added yet
        for info, new_info in plan:
            new_bundle_uuid = new_info['uuid']
            if new_bundle_uuid not in new_bundle_uuids_added:
                print('adding: ' + new_bundle_uuid)
                client.create(
                    'worksheet-items',
                    data={
                        'type': worksheet_util.TYPE_BUNDLE,
                        'worksheet': JsonApiRelationship('worksheets', worksheet_uuid),
github codalab / codalab-worksheets / codalab / rest / legacy.py View on Github external
def get_bundle_info(uuid):
        bundle_info = get_bundle_info(uuid, True, True, True)

        if bundle_info is None:
            return None
        # Set permissions
        bundle_info['edit_permission'] = (bundle_info['permission'] == GROUP_OBJECT_PERMISSION_ALL)
        # Format permissions into strings
        bundle_info['permission_str'] = permission_str(bundle_info['permission'])
        for group_permission in bundle_info['group_permissions']:
            group_permission['permission_str'] = permission_str(group_permission['permission'])

        metadata = bundle_info['metadata']

        cls = get_bundle_subclass(bundle_info['bundle_type'])
        for key, value in worksheet_util.get_formatted_metadata(cls, metadata):
            metadata[key] = value

        bundle_info['metadata'] = metadata
        bundle_info['editable_metadata_fields'] = worksheet_util.get_editable_metadata_fields(cls)

        return bundle_info
github codalab / codalab-worksheets / codalab / rest / legacy.py View on Github external
return None
        # Set permissions
        bundle_info['edit_permission'] = (bundle_info['permission'] == GROUP_OBJECT_PERMISSION_ALL)
        # Format permissions into strings
        bundle_info['permission_str'] = permission_str(bundle_info['permission'])
        for group_permission in bundle_info['group_permissions']:
            group_permission['permission_str'] = permission_str(group_permission['permission'])

        metadata = bundle_info['metadata']

        cls = get_bundle_subclass(bundle_info['bundle_type'])
        for key, value in worksheet_util.get_formatted_metadata(cls, metadata):
            metadata[key] = value

        bundle_info['metadata'] = metadata
        bundle_info['editable_metadata_fields'] = worksheet_util.get_editable_metadata_fields(cls)

        return bundle_info
github codalab / codalab-worksheets / codalab / client / local_bundle_client.py View on Github external
def derive_bundle(self, bundle_type, targets, command, metadata, worksheet_uuid):
        '''
        For both make and run bundles.
        Add the resulting bundle to the given worksheet_uuid (optional).
        '''
        bundle_subclass = get_bundle_subclass(bundle_type)
        self.validate_user_metadata(bundle_subclass, metadata)
        owner_id = self._current_user_id()
        bundle = bundle_subclass.construct(targets=targets, command=command, metadata=metadata, owner_id=owner_id)
        self.model.save_bundle(bundle)
        if worksheet_uuid:
            self.add_worksheet_item(worksheet_uuid, worksheet_util.bundle_item(bundle.uuid))
        return bundle.uuid
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
def update_worksheet_items(worksheet_info, new_items, convert_items=True):
    """
    Set the worksheet to have items |new_items|.
    """
    worksheet_uuid = worksheet_info['uuid']
    last_item_id = worksheet_info['last_item_id']
    length = len(worksheet_info['items'])
    worksheet = local.model.get_worksheet(worksheet_uuid, fetch_items=False)
    check_worksheet_has_all_permission(local.model, request.user, worksheet)
    worksheet_util.check_worksheet_not_frozen(worksheet)
    try:
        if convert_items:
            new_items = [worksheet_util.convert_item_to_db(item) for item in new_items]
        local.model.update_worksheet_items(worksheet_uuid, last_item_id, length, new_items)
    except UsageError:
        # Turn the model error into a more readable one using the object.
        raise UsageError('%s was updated concurrently!' % (worksheet,))
github codalab / codalab-worksheets / codalab / client / local_bundle_client.py View on Github external
# Upload the data and save the bundle.
        if sources is not None:
            self.upload_manager.upload_to_bundle_store(
                bundle, sources, follow_symlinks, exclude_patterns, remove_sources,
                git, unpack, simplify_archives=True)
            self.upload_manager.update_metadata_and_save(bundle, new_bundle=True)
        else:
            self.model.save_bundle(bundle)

        # Inherit properties of worksheet
        self._bundle_inherit_workheet_permissions(bundle.uuid, worksheet_uuid)

        # Add to worksheet
        if add_to_worksheet:
            self.add_worksheet_item(worksheet_uuid, worksheet_util.bundle_item(bundle.uuid))

        return bundle.uuid
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
)

    # Create list of bundles in original order
    bundles = [bundles_dict[uuid] for uuid in bundle_uuids]

    # Build response document
    document = BundleSchema(many=True).dump(bundles).data

    # Shim in display metadata used by the front-end application
    if query_get_bool('include_display_metadata', default=False):
        for bundle, data in izip(bundles, document['data']):
            bundle_class = get_bundle_subclass(bundle['bundle_type'])
            json_api_meta(
                data,
                {
                    'editable_metadata_keys': worksheet_util.get_editable_metadata_fields(
                        bundle_class
                    ),
                    'metadata_type': worksheet_util.get_metadata_types(bundle_class),
                },
            )

    if 'owner' in include_set:
        owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )