Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_project(project_name):
'''Try to find the project with the given name or id.'''
# First, see if the project is a project-id.
try:
project = dxpy.DXProject(project_name)
return project
except dxpy.DXError:
pass
project = dxpy.find_projects(name=project_name, return_handler=True, level="VIEW")
project = [p for p in project]
if len(project) == 0:
print('Did not find project {0}'.format(project_name))
return None
elif len(project) == 1:
return project[0]
else:
raise Exception('Found more than 1 project matching {0}'.format(project_name))
def resolve_project(project_name, level=None):
try:
project = dxpy.find_one_project(name=project_name, name_mode='exact',
level=level, return_handler=False)
except:
print 'Could not find 1 and only 1 project named {0}.'.format(project_name)
sys.exit(1)
return dxpy.DXProject(project['id'])
sys.exit(3)
else:
raise e
dxpy.DXJob(job_id).wait_on_done(interval=1)
if mode == 'applet':
applet_id, _ = dxpy.get_dxlink_ids(dxpy.api.job_describe(job_id)['output']['output_applet'])
return applet_id
else:
# TODO: determine and return the app ID, to allow
# running the app if args.run is specified
return None
finally:
if not using_temp_project_for_remote_build:
dxpy.DXProject(build_project_id).remove_objects([remote_file.get_id()])
finally:
if using_temp_project_for_remote_build:
dxpy.api.project_destroy(build_project_id, {"terminateJobs": True})
shutil.rmtree(temp_dir)
"Project {} exists but was expected not to exist".format(project_desc)
)
else:
return project
elif exists is True:
raise dxpy.DXSearchError("Project {} does not exist".format(project_desc))
elif create:
LOG.info(
"Creating project %s in %s region", project_desc, region or ""
)
create_args = dict(kwargs)
create_args["name"] = project_desc
if region:
create_args["region"] = region
project_id = dxpy.api.project_new(create_args)["id"]
return dxpy.DXProject(project_id)
or to root folder of destination, the tree is moved under project name.
Args:
dest (Path): The destination directory path in a different project
Raises:
TargetExistsError: When all possible destinations for source directory already exist
DNAnexusError: When cloning within same project
"""
if dest.canonical_project == self.canonical_project:
raise DNAnexusError('Cannot clonetree within same project')
if dest == (self.drive+dest.project): # need to convert dx://proj to dx://proj:
dest = dest + ':'
target_dest, should_rename, moved_folder_path = self._prep_for_copytree(dest)
project_handler = dxpy.DXProject(self.canonical_project)
with _wrap_dx_calls():
project_handler.clone(
container=dest.canonical_project,
destination=('/' + (target_dest.parent.resource or '')
) if self.resource else '/' + target_dest.resource,
folders=['/' + (self.resource or '')]
)
if self.resource and should_rename:
dxpy.api.project_rename_folder(
dest.canonical_project,
input_params={
'folder': '/' + moved_folder_path.resource,
'name': target_dest.name
}
Returns:
List[DXPath]: Iterates over listed files directly within the resource
Raises:
NotFoundError: When resource folder is not present on DX platform
"""
proj_id = self.canonical_project
proj_name = self.virtual_project
ans_list = []
kwargs = {
'only': only,
'describe': {'fields': {'name': True, 'folder': True}},
'folder': '/' + (self.resource or '')
}
with _wrap_dx_calls():
obj_dict = dxpy.DXProject(dxid=proj_id).list_folder(**kwargs)
for key, values in obj_dict.items():
for entry in values:
if canonicalize:
ans_list.append(DXCanonicalPath('dx://{}:/{}'.format(
proj_id, (entry.lstrip('/') if key == 'folders' else entry['id']))))
else:
if key == 'folders':
ans_list.append(DXVirtualPath('{drive}{proj_name}:{folder}'.format(
drive=self.drive, proj_name=proj_name, folder=entry)))
else:
ans_list.append(DXVirtualPath('{drive}{proj_name}:{folder}/{name}'.format(
drive=self.drive,
proj_name=proj_name,
folder=entry['describe']['folder'].rstrip('/'),
name=entry['describe']['name']))
)