예제 #1
0
파일: main.py 프로젝트: adrpar/uws-client
def list_jobs(url, user_name, password, bitmask):
    uws_connection = UWS.connection.Connection(url, user_name, password)
    uws_client = UWS.base.BaseUWSClient(uws_connection)

    jobs = uws_client.get_job_list()

    rows = [["ID", "Job name", "Status"]]
    for job in jobs.job_reference:
        if bitmask == 0:
            _register_job_reference_for_table(rows, job)
        if bitmask & 1:
            if 'COMPLETED' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 2:
            if 'PENDING' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 4:
            if 'QUEUED' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 8:
            if 'EXECUTING' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 16:
            if 'ERROR' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 32:
            if 'ABORTED' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 64:
            if 'UNKNOWN' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 128:
            if 'HELD' in job.phase:
                _register_job_reference_for_table(rows, job)
                continue
        if bitmask & 256:
            if 'SUSPENDED' in job.phase:
                _register_job_reference_for_table(rows, job)

    (console_width, console_height) = console.get_terminal_size()

    table = tt.Texttable(max_width=console_width)
    table.set_deco(tt.Texttable.HEADER)
    table.set_cols_dtype(['t', 't', 't'])
    table.add_rows(rows)

    print "List of jobs on UWS service for user: '******'" % user_name
    print table.draw()
    print "%d jobs listed." % (len(rows) - 1)
예제 #2
0
def _print_job(job):
    # format stuff
    rows = [["Field", "Value"]]
    rows.append(["Job id", job.job_id])

    rows.append(["Run id", job.run_id])

    if (job.owner_id):
        rows.append(["Owner id", job.owner_id])

    rows.append(["Phase", ", ".join(job.phase)])

    if (job.quote):
        rows.append(["Quote", job.quote])

    if (job.creation_time):
        rows.append(["Creation time", job.creation_time])

    rows.append(["Start time", job.start_time])
    rows.append(["End time", job.end_time])
    rows.append(["Execution duration", job.execution_duration])
    rows.append(["Destruction time", job.destruction])

    for param in job.parameters:
        rows.append(["Parameter " + param.id, param.value])

    for result in job.results:
        rows.append(["Result " + result.id, result.reference])

    try:
        if (job.error_summary):
            rows.append(["Errors", "; ".join(job.error_summary.messages)])
    except:
        pass

    for info in job.job_info:
        rows.append(["Job info", unicode(info)])

    (console_width, console_height) = console.get_terminal_size()

    fields = [row[0] for row in rows]
    max_field_len = len(max(fields, key=len))

    table = tt.Texttable(max_width=console_width)
    table.set_deco(tt.Texttable.HEADER)
    table.set_cols_dtype(['t', 't'])
    table.set_cols_width([max_field_len, console_width - max_field_len - 4])
    table.add_rows(rows)
    print table.draw()
예제 #3
0
파일: main.py 프로젝트: murodin/uws-client
def new_job(url, user_name, password, parameters={}, run=False):
    uws_client = UWS.client.Client(url=url, user=user_name, password=password)

    job = uws_client.new_job(parameters)

    if run:
        # execute the job
        job = uws_client.run_job(job.job_id)

    (console_width, console_height) = console.get_terminal_size()

    _print_job(job)

    print "\n"
    print "*" * (console_width - 1)
    print "You can access this job with the id:\n"
    print "Job ID: %s" % job.job_id
    print "Command: uws -H %s --user %s --password YOUR_PASSWORD_HERE job show %s" % (url, user_name, job.job_id)
    print "*" * (console_width - 1)
예제 #4
0
def list_jobs(url, user_name, password, phases, after=None, last=None):
    uws_client = UWS.client.Client(url=url, user=user_name, password=password)

    filters = {}
    if phases:
        filters['phases'] = phases
    if after:
        filters['after'] = after
    if last:
        filters['last'] = last

    jobs = uws_client.get_job_list(filters)

    job_phases = UWS.models.JobPhases

    # we will apply client side filtering anyways, since we are not
    # sure that a UWS service is version 1.1 and supports server side
    # filtering.
    rows = [["Job Id", "[Run]", "[Owner]", "[Creation Time]", "Status"]]
    for job in jobs.job_reference:
        if not phases or jobs.version == "1.1":
            _register_job_reference_for_table(rows, job)
        else:
            if job_phases.COMPLETED in phases and job_phases.COMPLETED in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.PENDING in phases and job_phases.PENDING in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.QUEUED in phases and job_phases.QUEUED in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.EXECUTING in phases and job_phases.EXECUTING in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.ERROR in phases and job_phases.ERROR in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.ABORTED in phases and job_phases.ABORTED in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.UNKNOWN in phases and job_phases.UNKNOWN in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.HELD in phases and job_phases.HELD in job.phase:
                _register_job_reference_for_table(rows, job)
            if job_phases.SUSPENDED in phases and job_phases.SUSPENDED in job.phase:
                _register_job_reference_for_table(rows, job)
            # add ARCHIVED phase as well for services with version 1.0 that already support this
            if job_phases.ARCHIVED in phases and job_phases.ARCHIVED in job.phase:
                _register_job_reference_for_table(rows, job)
    (console_width, console_height) = console.get_terminal_size()

    # Now we have the rows all stored. Check if all columns exist and remove
    # empty columns for a more friendly output.

    # Set existing_col to 0, i.e. all cols missing initially. If at least one
    # entry is found for a column, then display it, otherwise ignore it.
    existing_col = [0, 0, 0, 0, 0]

    for j, row in enumerate(rows):
        if j > 0:  # ignore header line here
            for i, col in enumerate(row):
                if col != '' and col is not None:
                    existing_col[i] = 1

    ncols = existing_col.count(1)
    dtypes = ['t'] * ncols

    # remove empty cols (in-place removal)
    rows[:] = [[col for i, col in enumerate(row) if existing_col[i] == 1]
               for row in rows]

    table = tt.Texttable(max_width=console_width)
    table.set_deco(tt.Texttable.HEADER)
    table.set_cols_dtype(dtypes)  # ['t', 't', 't', 't', 't'])
    table.add_rows(rows)

    print "List of jobs on UWS service for user: '******'" % user_name
    print table.draw()
    print "%d jobs listed." % (len(rows) - 1)