How to use codalab - 10 common examples

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 / worksheet_util.py View on Github external
if isinstance(arg, tuple):
        # tuples are (bundle_uuid, genpath) which have not been fleshed out
        return arg + (func,)
    try:
        if func is None:
            return arg
        # String encoding of a function: size s/a/b
        for f in func.split(FUNC_DELIM):
            if f == 'str':
                arg = str(arg)
            elif f == 'date':
                arg = formatting.date_str(float(arg)) if arg is not None else None
            elif f == 'duration':
                arg = formatting.duration_str(float(arg)) if arg is not None else None
            elif f == 'size':
                arg = formatting.size_str(float(arg)) if arg is not None else None
            elif f.startswith('%'):
                arg = (f % float(arg)) if arg is not None else None
            elif f.startswith('s/'):  # regular expression: s//
                esc_slash = '_ESC_SLASH_'  # Assume this doesn't occur in s
                # Preserve escaped characters: \/
                tokens = f.replace('\\/', esc_slash).split('/')
                if len(tokens) != 3:
                    return '' % f
                s = tokens[1].replace(esc_slash, '/')
                t = tokens[2].replace(esc_slash, '/')
                arg = re.sub(s, t, arg)
            elif f.startswith('['):  # substring
                m = re.match('\[(.*):(.*)\]', f)
                if m:
                    start = int(m.group(1) or 0)
                    end = int(m.group(2) or len(arg))
github codalab / codalab-worksheets / codalab / lib / bundle_cli.py View on Github external
    @Commands.command(
        'bs-ls-partitions',
        help='List available partitions (MultiDiskBundleStore only)',
        arguments=(),
    )
    def do_ls_partitions_command(self, args):
        self._fail_if_headless(args)
        self._fail_if_not_local(args)
        if not isinstance(self.manager.bundle_store(), MultiDiskBundleStore):
            print >> sys.stderr, "This command can only be run when MultiDiskBundleStore is in use."
            sys.exit(1)
        self.manager.bundle_store().ls_partitions()
github codalab / codalab-worksheets / codalab / lib / bundle_cli.py View on Github external
    @Commands.command(
        'bs-rm-partition',
        help='Remove a partition by its number (MultiDiskBundleStore only)',
        arguments=(
            Commands.Argument('partition', help='The partition you want to remove.'),
        ),
    )
    def do_rm_partition_command(self, args):
        self._fail_if_headless(args)
        self._fail_if_not_local(args)
        if not isinstance(self.manager.bundle_store(), MultiDiskBundleStore):
            print >> sys.stderr, "This command can only be run when MultiDiskBundleStore is in use."
            sys.exit(1)
        self.manager.bundle_store().rm_partition(args.partition)
github codalab / codalab-worksheets / build / lib / codalab / lib / bundle_cli.py View on Github external
stats.append('Size:    %s' % (self.size_str(metadata['data_size']),))
        fields['stats'] = 'Stats:\n  %s\n' % ('\n  '.join(stats),) if stats else ''
        # Compute a nicely-formatted list of hard dependencies. Since this type of
        # dependency is realized within this bundle as a symlink to another bundle,
        # label these dependencies as 'references' in the UI.
        fields['hard_dependencies'] = ''
        if info['hard_dependencies']:
            deps = info['hard_dependencies']
            if len(deps) == 1 and not deps[0]['child_path']:
                fields['hard_dependencies'] = 'Reference:\n  %s\n' % (
                  path_util.safe_join(deps[0]['parent_uuid'], deps[0]['parent_path']),)
            else:
                fields['hard_dependencies'] = 'References:\n%s\n' % ('\n'.join(
                  '  %s:%s' % (
                    dep['child_path'],
                    path_util.safe_join(dep['parent_uuid'], dep['parent_path']),
                  ) for dep in sorted(deps, key=lambda dep: dep['child_path'])
                ))
        # Compute a nicely-formatted failure message, if this bundle failed.
        # It is possible for bundles that are not failed to have failure messages:
        # for example, if a bundle is killed in the database after running for too
        # long then succeeds afterwards, it will be in this state.
        fields['failure_message'] = ''
        if info['state'] == State.FAILED and metadata['failure_message']:
            fields['failure_message'] = 'Failure message:\n  %s\n' % ('\n  '.join(
              metadata['failure_message'].split('\n')
            ))
        # Return the formatted summary of the bundle info.
        return '''
    {bundle_type}: {name}
    {description}
      UUID:  {uuid}
github codalab / codalab-worksheets / codalab / lib / bundle_cli.py View on Github external
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)

        # Headless client should fire OpenBundle UI action if no special flags used
github codalab / codalab-worksheets / codalab / bin / cl.py View on Github external
def main():
    cli = BundleCLI(CodaLabManager())
    try:
        cli.do_command(sys.argv[1:])
    except KeyboardInterrupt:
        print('Terminated by Ctrl-C')
        sys.exit(130)
github codalab / codalab-worksheets / codalab / model / bundle_model.py View on Github external
clause = cl_bundle_dependency.c.child_uuid == cl_bundle.c.uuid
                else:  # embedded
                    clause = cl_bundle.c.uuid.in_(
                        alias(select([cl_bundle_dependency.c.child_uuid]).where(condition))
                    )
            elif key.startswith('dependency/'):
                _, name = key.split('/', 1)
                condition = make_condition(key, cl_bundle_dependency.c.parent_uuid, value)
                if condition is None:  # top-level
                    clause = and_(
                        cl_bundle_dependency.c.child_uuid == cl_bundle.c.uuid,  # Join constraint
                        cl_bundle_dependency.c.child_path
                        == name,  # Match the 'type' of dependent (child_path)
                    )
                else:  # embedded
                    clause = cl_bundle.c.uuid.in_(
                        alias(
                            select([cl_bundle_dependency.c.child_uuid]).where(
                                and_(
                                    cl_bundle_dependency.c.child_path
                                    == name,  # Match the 'type' of dependent (child_path)
                                    condition,
                                )
                            )
                        )
                    )
            elif key == 'host_worksheet':
                condition = make_condition(key, cl_worksheet_item.c.worksheet_uuid, value)
                if condition is None:  # top-level
                    clause = cl_worksheet_item.c.bundle_uuid == cl_bundle.c.uuid  # Join constraint
                else:
                    clause = cl_bundle.c.uuid.in_(
github codalab / codalab-worksheets / build / lib / codalab / lib / bundle_cli.py View on Github external
if len(deps) == 1 and not deps[0]['child_path']:
                fields['hard_dependencies'] = 'Reference:\n  %s\n' % (
                  path_util.safe_join(deps[0]['parent_uuid'], deps[0]['parent_path']),)
            else:
                fields['hard_dependencies'] = 'References:\n%s\n' % ('\n'.join(
                  '  %s:%s' % (
                    dep['child_path'],
                    path_util.safe_join(dep['parent_uuid'], dep['parent_path']),
                  ) for dep in sorted(deps, key=lambda dep: dep['child_path'])
                ))
        # Compute a nicely-formatted failure message, if this bundle failed.
        # It is possible for bundles that are not failed to have failure messages:
        # for example, if a bundle is killed in the database after running for too
        # long then succeeds afterwards, it will be in this state.
        fields['failure_message'] = ''
        if info['state'] == State.FAILED and metadata['failure_message']:
            fields['failure_message'] = 'Failure message:\n  %s\n' % ('\n  '.join(
              metadata['failure_message'].split('\n')
            ))
        # Return the formatted summary of the bundle info.
        return '''
    {bundle_type}: {name}
    {description}
      UUID:  {uuid}
      Hash:  {data_hash}
      State: {state}
    {stats}{hard_dependencies}{failure_message}
        '''.format(**fields).strip()