def request_missing_metadata(bundle_subclass, initial_metadata): ''' Pop up an editor and request data from the user. ''' # Construct a form template with the required keys, prefilled with the # command-line metadata options. template_lines = [] bundle_type = bundle_subclass.BUNDLE_TYPE template_lines.append( os.linesep.join([ '// Enter metadata for the new %s bundle, then save and quit.' % (bundle_type, ), '// To cancel the upload, delete the name.', ])) for spec in bundle_subclass.get_user_defined_metadata(): initial_value = initial_metadata.get(spec.key) or '' if spec.type == list: initial_value = ' '.join(initial_value or []) template_lines.append('') template_lines.append('// %s' % spec.description) template_lines.append('%s: %s' % (spec.key, initial_value)) template = os.linesep.join(template_lines) # Show the form to the user in their editor of choice and parse the result. form_result = editor_util.open_and_edit(suffix='.c', template=template) return parse_metadata_form(bundle_subclass, form_result)
def request_missing_metadata(bundle_subclass, initial_metadata): ''' Pop up an editor and request data from the user. ''' # Construct a form template with the required keys, prefilled with the # command-line metadata options. template_lines = [] bundle_type = bundle_subclass.BUNDLE_TYPE template_lines.append( os.linesep.join( [ '// Enter metadata for the new %s bundle, then save and quit.' % (bundle_type,), '// To cancel the upload, delete the name.', ] ) ) for spec in bundle_subclass.get_user_defined_metadata(): initial_value = initial_metadata.get(spec.key) or '' if spec.type == list: initial_value = ' '.join(initial_value or []) template_lines.append('') template_lines.append('// %s' % spec.description) template_lines.append('%s: %s' % (spec.key, initial_value)) template = os.linesep.join(template_lines) # Show the form to the user in their editor of choice and parse the result. form_result = editor_util.open_and_edit(suffix='.c', template=template) return parse_metadata_form(bundle_subclass, form_result)
def request_lines(worksheet_info): """ Input: worksheet_info Popup an editor, populated with the current worksheet contents. Return a list of new items (bundle_uuid, value, type) that the user typed into the editor. """ # Construct a form template with the current value of the worksheet. template_lines = get_worksheet_lines(worksheet_info) template = ''.join([line + os.linesep for line in template_lines]) lines = editor_util.open_and_edit(suffix='.md', template=template) # Process the result form_result = [line.rstrip('\n') for line in lines] if form_result == template_lines: raise UsageError('No change made; aborting') return form_result
def request_lines(worksheet_info, client): """ Input: worksheet_info, client (which is used to get bundle_infos) Popup an editor, populated with the current worksheet contents. Return a list of new items (bundle_uuid, value, type) that the user typed into the editor. """ # Construct a form template with the current value of the worksheet. template_lines = get_worksheet_lines(worksheet_info) template = ''.join([line + os.linesep for line in template_lines]) lines = editor_util.open_and_edit(suffix='.md', template=template) # Process the result form_result = [line.rstrip() for line in lines] if form_result == template_lines: raise UsageError('No change made; aborting') return form_result
def request_missing_metadata(bundle_subclass, args, initial_metadata=None): ''' For any metadata arguments that were not supplied through the command line, pop up an editor and request that data from the user. ''' if not initial_metadata: initial_metadata = { spec.key: getattr(args, metadata_key_to_argument(spec.key,)) for spec in bundle_subclass.get_user_defined_metadata() } # Fill in default values for all unsupplied metadata keys. new_initial_metadata = {} for spec in bundle_subclass.get_user_defined_metadata(): new_initial_metadata[spec.key] = initial_metadata.get(spec.key) if not new_initial_metadata[spec.key]: default = MetadataDefaults.get_default(spec, bundle_subclass, args) new_initial_metadata[spec.key] = default initial_metadata = new_initial_metadata # If args.edit doesn't exist (when doing 'cl edit'), then we want to show # the editor. if not getattr(args, 'edit', True): return initial_metadata # Construct a form template with the required keys, prefilled with the # command-line metadata options. template_lines = [] bundle_type = bundle_subclass.BUNDLE_TYPE template_lines.append(os.linesep.join([ '// Enter metadata for the new %s bundle, then save and quit.' % (bundle_type,), '// To cancel the upload, delete the name.', ])) for spec in bundle_subclass.get_user_defined_metadata(): initial_value = initial_metadata.get(spec.key) or '' if spec.type == list: initial_value = ' '.join(initial_value or []) template_lines.append('') template_lines.append('// %s' % spec.description) template_lines.append('%s: %s' % (spec.key, initial_value)) template = os.linesep.join(template_lines) # Show the form to the user in their editor of choice and parse the result. form_result = editor_util.open_and_edit(suffix='.c', template=template) return parse_metadata_form(bundle_subclass, form_result)
def request_lines(worksheet_info, client): ''' Input: worksheet_info, client (which is used to get bundle_infos) Popup an editor, populated with the current worksheet contents. Return a list of new items (bundle_uuid, value, type) that the user typed into the editor. ''' # Construct a form template with the current value of the worksheet. template_lines = get_worksheet_lines(worksheet_info) template = os.linesep.join(template_lines) + os.linesep lines = editor_util.open_and_edit(suffix='.md', template=template) if not lines: lines = template_lines # Process the result form_result = [line.rstrip() for line in lines] if form_result == template_lines: raise UsageError('No change made; aborting') return form_result