Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def print_table(self, columns, row_dicts, post_funcs={}, justify={}, show_header=True, indent=''):
"""
Pretty-print a list of columns from each row in the given list of dicts.
"""
# Get the contents of the table
rows = [columns]
for row_dict in row_dicts:
row = []
for col in columns:
cell = row_dict.get(col)
func = post_funcs.get(col)
if func:
cell = worksheet_util.apply_func(func, cell)
if cell is None:
cell = contents_str(cell)
row.append(cell)
rows.append(row)
# Display the table
lengths = [max(len(str(value)) for value in col) for col in zip(*rows)]
for (i, row) in enumerate(rows):
row_strs = []
for (j, value) in enumerate(row):
length = lengths[j]
padding = (length - len(str(value))) * ' '
if justify.get(columns[j], -1) < 0:
row_strs.append(str(value) + padding)
else:
row_strs.append(padding + str(value))
if show_header or i > 0:
print >>self.stdout, indent + ' '.join(row_strs)
def decode_lines(interpreted):
# interpreted is None or list of base64 encoded lines
if interpreted is None:
return formatting.contents_str(None)
else:
return map(base64.b64decode, interpreted)
def display_dependencies(label, deps):
lines.append(label + ':')
for dep in deps:
child = dep['child_path']
parent = path_util.safe_join(contents_str(dep['parent_name']) + '(' + dep['parent_uuid'] + ')', dep['parent_path'])
lines.append(' %s: %s' % (child, parent))
if info['dependencies']:
if interpreted is None:
return formatting.contents_str(None)
else:
return map(base64.b64decode, interpreted)
# Currently, only certain fields are base64 encoded.
for item in worksheet_info['items']:
if item is None:
continue
if item['mode'] in ['html', 'contents']:
item['interpreted'] = decode_lines(item['interpreted'])
elif item['mode'] == 'table':
for row_map in item['interpreted'][1]:
for k, v in row_map.iteritems():
if v is None:
row_map[k] = formatting.contents_str(v)
if 'bundle_info' in item:
infos = []
if isinstance(item['bundle_info'], list):
infos = item['bundle_info']
elif isinstance(item['bundle_info'], dict):
infos = [item['bundle_info']]
for bundle_info in infos:
if bundle_info is None:
continue
if 'bundle_type' not in bundle_info:
continue # empty info: invalid bundle reference
if isinstance(bundle_info, dict):
worksheet_util.format_metadata(bundle_info.get('metadata'))
if bundle_uuids:
return {'items': worksheet_info['items']}
return worksheet_info