Example #1
0
    def generate_file_info(self, file_path):
        info = self.webdavClient.info(file_path)

        is_dir = False
        is_link = False

        if self.webdavClient.is_dir(file_path):
            is_dir = True
        else:
            pass

        file_name = urn.Urn(file_path).filename().replace("/", "")
        file_dir = urn.Urn(file_path).parent()

        ext = ''
        divide = file_name.split('.')
        if len(divide) > 1:
            ext = file_name.split('.')[-1].lower()

        mtime = info['modified']

        file_info = {
            "is_dir": is_dir,
            "is_link": is_link,
            "name": file_name,
            "ext": ext,
            "path": file_dir,
            "owner": self.user,
            "mode": "600",
            "size": info['size'] if not is_dir else 0,
            "mtime": mtime,
            'mtime_str': str(mtime),
        }
        return file_info
Example #2
0
def test_api_install_script(cerise_service, cerise_client, webdav_client):
    job = _start_job(cerise_client, webdav_client, InstallScriptTestJob)
    job = _wait_for_state(job.id, 10.0, 'DONE', cerise_client)
    assert job.state == 'Success'

    output_path = '/files/output/{}/output.txt'.format(job.id)
    resource = wc.Resource(webdav_client, wu.Urn(output_path))
    output_buffer = io.BytesIO()
    resource.write_to(output_buffer)
    assert output_buffer.getvalue() == b'Testing API installation\n'
Example #3
0
def _start_job(cerise_client, webdav_client, job_fixture, test_name=None):
    if test_name is None:
        test_name = 'test_post_' + job_fixture.__name__

    input_dir = '/files/input/{}'.format(test_name)
    webdav_client.mkdir(input_dir)

    if job_fixture.workflow is not None:
        workflow_file = input_dir + '/workflow.cwl'
        workflow_res = wc.Resource(webdav_client, wu.Urn(workflow_file))
        workflow_res.read_from(io.BytesIO(job_fixture.workflow))
    else:
        workflow_file = ''

    for input_file in job_fixture.local_input_files:
        input_path = '{}/{}'.format(input_dir, input_file.location)
        input_res = wc.Resource(webdav_client, wu.Urn(input_path))
        if input_file.location in job_fixture.input_content:
            input_res.read_from(
                io.BytesIO(job_fixture.input_content[input_file.location]))

        for secondary_file in input_file.secondary_files:
            input_path = '{}/{}'.format(input_dir, secondary_file.location)
            input_res = wc.Resource(webdav_client, wu.Urn(input_path))
            if secondary_file.location in job_fixture.input_content:
                input_res.read_from(
                    io.BytesIO(
                        job_fixture.input_content[secondary_file.location]))

    input_dir_url = 'http://localhost:29593{}/'.format(input_dir)
    input_text = job_fixture.local_input(input_dir_url)
    input_data = json.loads(input_text)

    JobDescription = cerise_client.get_model('job-description')
    job_desc = JobDescription(name=test_name,
                              workflow='http://localhost:29593' +
                              workflow_file,
                              input=input_data)

    job, response = cerise_client.jobs.post_job(body=job_desc).result()

    assert response.status_code == 201
    return job
Example #4
0
 def path(self, path):
     return urn.Urn(path).path()
Example #5
0
 def parent(self, path):
     return urn.Urn(path).parent()