Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download_one_database_file(project, database_desc, dest_filename, src_filename, file_status, args):
do_debug("download.py#download_one_database_file - src_filename = {}".format(src_filename));
if file_status is not None:
do_debug("download.py#download_one_database_file - file_status = {}".format(file_status));
if not args.overwrite:
if os.path.exists(dest_filename):
err_exit(fill('Error: path "' + dest_filename + '" already exists but -f/--overwrite was not set'))
if database_desc['class'] != 'database':
print("Skipping non-database data object {name} ({id})".format(**database_desc), file=sys.stderr)
return
try:
show_progress = args.show_progress
except AttributeError:
show_progress = False
try:
dxpy.download_dxdatabasefile(
database_desc['id'],
dest_filename,
src_filename,
file_status,
filenames.extend(f["describe"]["name"] for f in matching_files)
foldernames.extend(f[len(strip_prefix):].lstrip('/') for f in matching_folders)
if len(filenames) > 0 and len(foldernames) > 0:
name_conflicts = set(filenames) & set(foldernames)
if len(name_conflicts) > 0:
msg = "Error: The following paths are both file and folder names, and " \
"cannot be downloaded to the same destination: "
msg += ", ".join(sorted(name_conflicts))
err_exit(fill(msg))
if args.output is None:
destdir, dest_filename = os.getcwd(), None
elif count > 1:
if not os.path.exists(args.output):
err_exit(fill("Error: When downloading multiple objects, --output must be an existing directory"))
destdir, dest_filename = args.output, None
elif os.path.isdir(args.output):
destdir, dest_filename = args.output, None
elif args.output.endswith('/'):
err_exit(fill("Error: {path} could not be found".format(path=args.output)))
else:
destdir, dest_filename = os.getcwd(), args.output
_download_folders(folders_to_get, destdir, args)
_download_files(files_to_get, destdir, args, dest_filename=dest_filename)
"project": dest_proj,
"destination": dest_path})['exists']
if len(exists) > 0:
print(fill('The following objects already existed in the destination ' +
'container and were not copied:') + '\n ' + '\n '.join(exists))
return
except:
err_exit()
else:
try:
exists = dxpy.api.project_clone(src_proj,
{"objects": [result['id'] for result in src_results],
"project": dest_proj,
"destination": dest_folder})['exists']
if len(exists) > 0:
print(fill('The following objects already existed in the destination ' +
'container and were not copied:') + '\n ' + '\n '.join(exists))
for result in src_results:
if result['id'] not in exists:
dxpy.DXHTTPRequest('/' + result['id'] + '/rename',
{"project": dest_proj,
"name": dest_name})
return
except:
err_exit()
with open(all_job_outputs_path, 'r') as fd:
all_job_outputs = json.load(fd, object_pairs_hook=collections.OrderedDict)
if isinstance(name, basestring):
name += ' (' + job_id + ':' + function + ')'
else:
name = job_id + ':' + function
job_name = BLUE() + BOLD() + name + ENDC()
print(job_name)
# Resolve local job-based object references
try:
resolve_job_references(input_hash, all_job_outputs)
except Exception as e:
exit_with_error(job_name + ' ' + JOB_STATES('failed') + ' when resolving input:\n' + fill(str(e)))
# Get list of non-closed data objects in the input that appear as
# DNAnexus links; append to depends_on
if depends_on is None:
depends_on = []
get_implicit_depends_on(input_hash, depends_on)
try:
wait_for_depends_on(depends_on, all_job_outputs)
except Exception as e:
exit_with_error(job_name + ' ' + JOB_STATES('failed') + ' when processing depends_on:\n' + fill(str(e)))
# Save job input to job_input.json
with open(os.path.join(job_homedir, 'job_input.json'), 'wb') as fd:
json.dump(input_hash, fd, indent=4)
fd.write(b'\n')
def wait_for_depends_on(depends_on, all_job_outputs):
# Wait for depends_on and any data objects in the input to close
if len(depends_on) > 0:
print(fill('Processing dependsOn and any DNAnexus links to closing objects in the input'))
for an_id in depends_on:
try:
print(' Waiting for ' + an_id + '...')
if an_id.startswith('localjob'):
if all_job_outputs.get(an_id) is None:
raise Exception('Job ' + an_id + ' could not be found in local finished jobs')
elif an_id.startswith('job'):
dxjob = dxpy.DXJob(an_id)
dxjob.wait_on_done()
else:
handler = dxpy.get_handler(an_id)
desc = handler.describe()
handler._wait_on_close()
except Exception as e:
raise Exception('Could not wait for ' + an_id + ': ' + str(e))
use_completer(class_completer)
if not printed_classes:
print('Your input parameter must be of one of the following classes:')
print('''applet array:file array:record file int
array:applet array:float array:string float record
array:boolean array:int boolean hash string
''')
printed_classes = True
while True:
input_class = prompt_for_var('Choose a class ( twice for choices)')
if input_class in class_completer.choices:
break
else:
print(fill('Not a recognized class; please choose again.'))
use_completer()
optional = prompt_for_yn('This is an optional parameter')
default_val = None
if optional and input_class in ['int', 'float', 'string', 'boolean']:
default_val = prompt_for_yn('A default value should be provided')
if default_val:
while True:
if input_class == 'boolean':
use_completer(bool_completer)
default_val = prompt_for_var(' Default value', choices=['true', 'false'])
use_completer()
elif input_class == 'string':
default_val = prompt_for_var(' Default value', allow_empty=True)
# Fill in patterns and blank help string
if input_class == 'file' or input_class == 'array:file':
parameter_json["patterns"] = ["*"]
parameter_json["help"] = ""
app_json['inputSpec'].append(parameter_json)
print('')
print(BOLD() + 'Output Specification' + ENDC())
print('')
output_spec = True
output_names = []
if output_spec:
app_json['outputSpec'] = []
print(fill('You will now be prompted for each output parameter of your app. Each parameter should have a unique name that uses only the underscore "_" and alphanumeric characters, and does not start with a number.'))
while True:
print('')
ordinal = get_ordinal_str(len(app_json['outputSpec']) + 1)
output_name = prompt_for_var(ordinal + ' output name ( to finish)', allow_empty=True)
if output_name == '':
break
if output_name in output_names:
print(fill('Error: Cannot use the same output parameter name twice. Please choose again.'))
continue
if not IO_NAME_PATTERN.match(output_name):
print(fill('Error: Parameter names may use only underscore "_", ASCII letters, and digits; and may not start with a digit. Please choose again.'))
continue
output_names.append(output_name)
output_label = prompt_for_var('Label (optional human-readable name)', '')
'array:int', 'array:float', 'array:string', 'array:boolean',
'record', 'file', 'applet',
'array:record', 'array:file', 'array:applet'])
bool_completer = Completer(['true', 'false'])
print('')
print(BOLD() + 'Input Specification' + ENDC())
print('')
input_spec = True
input_names = []
printed_classes = False
if input_spec:
app_json['inputSpec'] = []
print(fill('You will now be prompted for each input parameter to your app. Each parameter should have a unique name that uses only the underscore "_" and alphanumeric characters, and does not start with a number.'))
while True:
print('')
ordinal = get_ordinal_str(len(app_json['inputSpec']) + 1)
input_name = prompt_for_var(ordinal + ' input name ( to finish)', allow_empty=True)
if input_name == '':
break
if input_name in input_names:
print(fill('Error: Cannot use the same input parameter name twice. Please choose again.'))
continue
if not IO_NAME_PATTERN.match(input_name):
print(fill('Error: Parameter names may use only underscore "_", ASCII letters, and digits; and may not start with a digit. Please choose again.'))
continue
input_names.append(input_name)
input_label = prompt_for_var('Label (optional human-readable name)', '')
def gen_text_line_and_name_collision(key, val):
''' In the absence of a name collision, create a line describing a bash variable.
'''
if check_name_collision:
if key not in environ and key not in var_defs_hash:
var_defs_hash[key] = val
else:
sys.stderr.write(dxpy.utils.printing.fill(
"Creating environment variable ({}) would cause a name collision".format(key)
) + "\n")
else:
var_defs_hash[key] = val