Пример #1
0
class GSGeneLabClient:
    myGeneLabClient = None

    def testMethod(self):
        print("GSGetFile test called")

    # create the client which we need to have cache the user/pass
    def GeneLabLogin(self, username, password):
        self.myGeneLabClient = GenomeSpaceClient(username, password)
        return self.myGeneLabClient

    def downloadFile(self, genelabUrl, localFileName):
        self.myGeneLabClient._download_file(genelabUrl, localFileName)
Пример #2
0
def download_from_genomespace_importer(json_parameter_file, root, data_conf,
                                       custom_token):
    with open(json_parameter_file, 'r') as param_file:
        json_params = json.load(param_file)

    # Add in missing job config properties that could not be set in the exec_before_job hook
    json_params['job_config']['GALAXY_ROOT_DIR'] = root
    json_params['job_config']['GALAXY_DATATYPES_CONF_FILE'] = data_conf

    # Extract input_urls and token  (format is input_urls^token). If a custom_token is
    # provided, use that instead.
    url_with_token = json_params.get('param_dict', {}).get("URL", "")
    if custom_token:
        input_urls = url_with_token.split('^')[0]
        token = custom_token
    else:
        input_urls, token = url_with_token.split('^')
    input_url_list = input_urls.split(",")

    gs_client = GenomeSpaceClient(token=token)

    for idx, input_url in enumerate(input_url_list):
        download_single_file(gs_client,
                             input_url,
                             json_params,
                             primary_dataset=(idx == 0))
Пример #3
0
def target_selector(request):
    # if the user has no files selected for upload, select them first
    if not request.session.get(S_CHOSEN_FILES, None):
        messages.add_message(request, messages.INFO,
                             'Please choose the files you want to upload')
        return HttpResponseRedirect('/files')
    # the user has files selected, has selected a genomespace, and the
    # directories the files are to go to, so move the files...
    if request.method == 'POST' and request.session[S_TARGETS]:
        target_directories = request.session[S_TARGETS]
        targets = tuple((s['path'], s['name']) for s in target_directories)
        form = TargetChooserForm(targets, request.POST)
        if form.is_valid():
            selected_dir = form.cleaned_data['target_directories']
            return _move_files_to_gs(target_directories, selected_dir, request)
        # else just show them the form again, populated with their choices
    else:
        # the user has files selected, has selected a genomespace, but we
        # don't know what their target directory will be, so ask them...
        client = GenomeSpaceClient(token=request.session[S_GS_TOKEN])
        xrd_location = request.session[S_LOCATION]
        dm_server = AgrfFeedConfig.get_dm_server(xrd_location)
        home_dir = dm_server + '/v1.0/file/Home/'
        try:
            target_directories = _list_directories(
                client, home_dir, request.session[S_GS_USERNAME])
            request.session[S_TARGETS] = target_directories
            targets = tuple((s['path'], s['path']) for s in target_directories)
            if not len(targets):
                messages.add_message(
                    request, messages.ERROR,
                    'No writeable GenomeSpace directory '
                    'has been found? Please check your '
                    'GenomeSpace account.')
                return HttpResponseRedirect('/files')
        except HTTPError as e:
            status_code = e.response.status_code
            if status_code == 403:
                messages.add_message(
                    request, messages.ERROR,
                    'The GenomeSpace has forbidden access! '
                    'You may be able to fix this by '
                    're-entering your cloud '
                    'credentials in the GenomeSpace.')
                return HttpResponseRedirect('/files')
            elif status_code == 500:
                messages.add_message(
                    request, messages.ERROR,
                    'The GenomeSpace has experienced an '
                    'internal server error! '
                    'Please report this to '
                    '*****@*****.**')
                return HttpResponseRedirect('/files')
            else:
                raise
        form = TargetChooserForm(targets)
    return render(request, 'agrf_feed/targets.html', {'form': form})
Пример #4
0
def celery_move_files(chosen_files, target_dir, token):
    client = GenomeSpaceClient(token=token)
    # common prefix doesn't return the common path: but rather
    # all the characters that match. So we need to trim it back to the path
    # separator...
    base = os.path.commonprefix(chosen_files).rpartition(os.sep)[0]
    for path in chosen_files:
        # there will always be a leading '/', as the base doesn't include it
        # so remove it from the file name
        file_name = path[len(base) + 1 if len(base) else 0:]
        # the genomespace will expect a '/' in a file name to be a directory
        file_name = file_name.replace('/', '_')
        bucket = target_dir['url'] + '/' + file_name
        fd = FileDescriptor.get_file_descriptor_for(path)
        try:
            logging.info('About to move %s to %s' % (path, bucket))
            start_time = time.time()
            client.copy(path, bucket)
            elapsed_time = time.time() - start_time
            bytes_moved = os.path.getsize(path)
            logging.info('%s bytes moved in %.2f seconds' %
                         (bytes_moved, elapsed_time))
        except GSClientException as error:
            logging.error('Error uploading %s: %s' % (file_name, error))
            fd.set_failed_upload()
        except SoftTimeLimitExceeded:
            logging.error('Soft time limit exceed for %s' % path)
            fd.set_failed_upload()
        except Exception as exp:
            # all other errors should be logged and the upload marked as failed
            logging.exception('On uploading %s' % path)
            fd.set_failed_upload()
        else:
            logging.info('Successfully uploaded %s' % file_name)
            fd.set_uploaded()
        fd.save()
Пример #5
0
def upload_to_genomespace(token, input_file, target_url):
    token = token or os.environ.get('GS_TOKEN')
    gs_client = GenomeSpaceClient(token=token)
    gs_client.copy(input_file, target_url)
    print("File successfully copied.")
Пример #6
0
def upload_to_genomespace(token, input_file, target_url):
    token = token or os.environ.get('GS_TOKEN')
    gs_client = GenomeSpaceClient(token=token)
    gs_client.copy(input_file, target_url)
    print("File successfully copied.")
Пример #7
0
def get_genomespace_client():
    return GenomeSpaceClient(username=get_test_username(),
                             password=get_test_password())
Пример #8
0
 def GeneLabLogin(self, username, password):
     self.myGeneLabClient = GenomeSpaceClient(username, password)
     return self.myGeneLabClient
Пример #9
0
def get_client(args):
    return GenomeSpaceClient(username=args.user,
                             password=args.password,
                             token=args.token)