Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Commands.command(
'wedit',
aliases=('we',),
help=[
'Edit the contents of a worksheet.',
'See https://github.com/codalab/codalab-worksheets/wiki/User_Worksheet-Markdown for the markdown syntax.',
' wedit -n : Change the name of the worksheet.',
' wedit -T ... : Set the tags of the worksheet (e.g., paper).',
' wedit -o : Set the owner of the worksheet to .',
],
arguments=(
Commands.Argument('worksheet_spec', help=WORKSHEET_SPEC_FORMAT, nargs='?', completer=WorksheetsCompleter),
Commands.Argument('-n', '--name', help='Changes the name of the worksheet (%s).' % spec_util.NAME_REGEX.pattern),
Commands.Argument('-t', '--title', help='Change title of worksheet.'),
Commands.Argument('-T', '--tags', help='Change tags (must appear after worksheet_spec).', nargs='*'),
Commands.Argument('-o', '--owner-spec', help='Change owner of worksheet.'),
Commands.Argument('--freeze', help='Freeze worksheet to prevent future modification (PERMANENT!).', action='store_true'),
Commands.Argument('--anonymous', help='Set worksheet to be anonymous (identity of the owner will NOT \n'
'be visible to users without \'all\' permission on the worksheet).',
dest='anonymous', action='store_true', default=None),
Commands.Argument('--not-anonymous', help='Set bundle to be NOT anonymous.', dest='anonymous', action='store_false'),
Commands.Argument('-f', '--file', help='Replace the contents of the current worksheet with this file.', completer=require_not_headless(FilesCompleter(directories=False))),
),
)
def do_wedit_command(self, args):
client, worksheet_uuid = self.parse_client_worksheet_uuid(args.worksheet_spec)
worksheet_info = client.fetch('worksheets', worksheet_uuid, params={
'include': ['items', 'items.bundle', 'items.subworksheet']
})
if args.freeze or any(arg is not None for arg in (args.name, args.title, args.tags, args.owner_spec, args.anonymous)):
@Commands.command(
'docker',
help='Beta feature. Simulate a run bundle locally, producing bundle contents in the local environment and mounting local dependencies.',
arguments=(
Commands.Argument('target_spec', help=ALIASED_TARGET_SPEC_FORMAT, nargs='*', completer=TargetsCompleter),
Commands.Argument('command', metavar='[---] command', help='Arbitrary Linux command to execute.', completer=NullCompleter),
Commands.Argument('-w', '--worksheet-spec', help='Operate on this worksheet (%s).' % WORKSHEET_SPEC_FORMAT, completer=WorksheetsCompleter),
) + Commands.metadata_arguments([RunBundle]) + EDIT_ARGUMENTS + WAIT_ARGUMENTS,
)
def do_docker_command(self, args):
self._fail_if_headless(args) # Disable on headless systems
client, worksheet_uuid = self.parse_client_worksheet_uuid(args.worksheet_spec)
args.target_spec, args.command = desugar_command(args.target_spec, args.command)
metadata = self.get_missing_metadata(RunBundle, args)
docker_image = metadata.get('request_docker_image', None)
if not docker_image:
raise UsageError('--request-docker-image [docker-image] must be specified')
uuid = generate_uuid()
bundle_path = os.path.join(self.manager.codalab_home, 'local_bundles', uuid)
request_network = None
@Commands.command(
'events',
help='Print the history of commands on this CodaLab instance (local only).',
arguments=(
Commands.Argument('-u', '--user', help='Filter by user id or username.'),
Commands.Argument('-c', '--command', dest='match_command', help='Filter by command.'),
Commands.Argument('-a', '--args', help='Filter by arguments.'),
Commands.Argument('--uuid', help='Filter by bundle or worksheet uuid.'),
Commands.Argument('-o', '--offset', help='Offset in the result list.', type=int, default=0),
Commands.Argument('-l', '--limit', help='Limit in the result list.', type=int, default=20),
Commands.Argument('-n', '--count', help='Just count.', action='store_true'),
Commands.Argument('-g', '--group-by', help='Group by this field (e.g., date).'),
),
)
def do_events_command(self, args):
self._fail_if_headless(args)
self._fail_if_not_local(args)
# Build query
query_info = {
'user': args.user, 'command': args.match_command, 'args': args.args, 'uuid': args.uuid,
'count': args.count, 'group_by': args.group_by
}
info = self.manager.model().get_events_log_info(query_info, args.offset, args.limit)
if 'counts' in info:
for row in info['counts']:
print >>self.stdout, '\t'.join(map(str, list(row)))
if 'events' in info:
@Commands.command(
'macro',
help=[
'Use mimicry to simulate macros.',
' macro M A B :C :D <=> mimic M-in1 M-in2 M-in-name1 M-in-name2 M-out A B C D'
],
arguments=(
Commands.Argument('macro_name', help='Name of the macro (look for -in1, -in-, ..., and -out bundles).'),
Commands.Argument('bundles', help='Bundles: new_input_1 ... new_input_n named_input_name:named_input_bundle other_named_input_name:other_named_input_bundle (%s)' % BUNDLE_SPEC_FORMAT, nargs='+', completer=BundlesCompleter),
) + Commands.metadata_arguments([MakeBundle, RunBundle]) + MIMIC_ARGUMENTS,
)
def do_macro_command(self, args):
"""
Just like do_mimic_command.
"""
# For a macro, it's important that the name be not-null, so that we
# don't create bundles called '-out', which would clash
# next time we try to use the macro.
if not getattr(args, metadata_util.metadata_key_to_argument('name')):
setattr(args, metadata_util.metadata_key_to_argument('name'), 'new')
# Reduce to the mimic case
named_user_inputs, named_macro_inputs, numbered_user_inputs = [], [], []
for bundle in args.bundles:
@Commands.command(
'edit',
aliases=('e',),
help=[
'Edit an existing bundle\'s metadata.',
' edit : Popup an editor.',
' edit -n : Edit the name metadata field (same for other fields).',
' edit -T ... : Set the tags of the bundle (e.g., training-dataset).',
],
arguments=(
Commands.Argument('bundle_spec', help=BUNDLE_SPEC_FORMAT, completer=BundlesCompleter),
Commands.Argument('-n', '--name', help='Change the bundle name (format: %s).' % spec_util.NAME_REGEX.pattern),
Commands.Argument('-T', '--tags', help='Change tags (must appear after worksheet_spec).', nargs='*'),
Commands.Argument('-d', '--description', help='New bundle description.'),
Commands.Argument('--anonymous', help='Set bundle to be anonymous (identity of the owner will NOT \n'
'be visible to users without \'all\' permission on the bundle).',
dest='anonymous', action='store_true', default=None),
Commands.Argument('--not-anonymous', help='Set bundle to be NOT anonymous.', dest='anonymous', action='store_false'),
Commands.Argument('-w', '--worksheet-spec', help='Operate on this worksheet (%s).' % WORKSHEET_SPEC_FORMAT, completer=WorksheetsCompleter),
),
)
def do_edit_command(self, args):
client, worksheet_uuid = self.parse_client_worksheet_uuid(args.worksheet_spec)
info = client.fetch_one('bundles', params={
'specs': args.bundle_spec,
'worksheet': worksheet_uuid,
@Commands.command(
'upload',
aliases=('up',),
help=[
'Create a bundle by uploading an existing file/directory.',
' upload
@Commands.command(
'wrm',
help=[
'Delete a worksheet.',
'To be safe, you can only delete a worksheet if it has no items and is not frozen.',
],
arguments=(
Commands.Argument('worksheet_spec', help=WORKSHEET_SPEC_FORMAT, nargs='+', completer=WorksheetsCompleter),
Commands.Argument('--force', action='store_true', help='Delete worksheet even if it is non-empty and frozen.'),
),
)
def do_wrm_command(self, args):
delete_current = False
client, current_worksheet = self.manager.get_current_worksheet_uuid()
for worksheet_spec in args.worksheet_spec:
client, worksheet_uuid = self.parse_client_worksheet_uuid(worksheet_spec)
if (client, worksheet_uuid) == (client, current_worksheet):
delete_current = True
client.delete('worksheets', worksheet_uuid, params={'force': args.force})
if delete_current:
# Go to home worksheet
return self.change_current_worksheet(client, None, verbose=True)
@Commands.command(
'events',
help='Print the history of commands on this CodaLab instance (local only).',
arguments=(
Commands.Argument('-u', '--user', help='Filter by user id or username.'),
Commands.Argument('-c', '--command', dest='match_command', help='Filter by command.'),
Commands.Argument('-a', '--args', help='Filter by arguments.'),
Commands.Argument('--uuid', help='Filter by bundle or worksheet uuid.'),
Commands.Argument('-o', '--offset', help='Offset in the result list.', type=int, default=0),
Commands.Argument('-l', '--limit', help='Limit in the result list.', type=int, default=20),
Commands.Argument('-n', '--count', help='Just count.', action='store_true'),
Commands.Argument('-g', '--group-by', help='Group by this field (e.g., date).'),
),
)
def do_events_command(self, args):
self._fail_if_headless(args)
self._fail_if_not_local(args)
# Build query
query_info = {
'user': args.user, 'command': args.match_command, 'args': args.args, 'uuid': args.uuid,
'count': args.count, 'group_by': args.group_by
}
info = self.manager.model().get_events_log_info(query_info, args.offset, args.limit)
if 'counts' in info:
@Commands.command(
'wls',
aliases=('wsearch', 'ws'),
help=[
'List worksheets on the current instance matching the given keywords.',
' wls tag=paper : List worksheets tagged as "paper".',
' wls .mine : List my worksheets.',
],
arguments=(
Commands.Argument('keywords', help='Keywords to search for.', nargs='*'),
Commands.Argument('-a', '--address', help=ADDRESS_SPEC_FORMAT, completer=AddressesCompleter),
Commands.Argument('-u', '--uuid-only', help='Print only uuids.', action='store_true'),
),
)
def do_wls_command(self, args):
if args.address:
address = self.manager.apply_alias(args.address)
client = self.manager.client(address)
else:
client = self.manager.current_client()
worksheet_dicts = client.fetch('worksheets', params={
'keywords': args.keywords,
'include': ['owner', 'group_permissions'],
})
if args.uuid_only:
@Commands.command(
'info',
aliases=('i',),
help='Show detailed information for a bundle.',
arguments=(
Commands.Argument('bundle_spec', help=BUNDLE_SPEC_FORMAT, nargs='+', completer=BundlesCompleter),
Commands.Argument('-f', '--field', help='Print out these comma-separated fields.'),
Commands.Argument('-r', '--raw', action='store_true', help='Print out raw information (no rendering of numbers/times).'),
Commands.Argument('-v', '--verbose', action='store_true', help='Print top-level contents of bundle, children bundles, and host worksheets.'),
Commands.Argument('-w', '--worksheet-spec', help='Operate on this worksheet (%s).' % WORKSHEET_SPEC_FORMAT, completer=WorksheetsCompleter),
),
)
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 []),
})