-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4a0bd1
commit 21a3a93
Showing
13 changed files
with
235 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import datetime | ||
|
||
import click | ||
|
||
from jsub import Jsub | ||
|
||
|
||
COLUMN_TITLE = { | ||
'task_id': 'Task ID', | ||
'name': 'Name', | ||
'app': 'Application', | ||
'backend': 'Backend', | ||
'status': 'Status', | ||
'created_at': 'Creation Time (UTC)', | ||
} | ||
|
||
|
||
def _convert_table_data(tasks_data, columns): | ||
table_data = [] | ||
for task_data in tasks_data: | ||
line_data = [] | ||
for col in columns: | ||
if col not in task_data: | ||
line_data.append('N/A') | ||
continue | ||
|
||
if col in ['app', 'backend']: | ||
if 'type' in task_data[col]: | ||
line_data.append(task_data[col]['type']) | ||
else: | ||
line_data.append(str(task_data[col])) | ||
elif col in ['created_at']: | ||
created_time = datetime.datetime.strptime(task_data[col], '%Y-%m-%dT%H:%M:%S.%f') | ||
time_str = datetime.datetime.strftime(created_time, '%Y-%m-%d %H:%M:%S') | ||
line_data.append(time_str) | ||
else: | ||
line_data.append(str(task_data[col])) | ||
table_data.append(line_data) | ||
return table_data | ||
|
||
def _print_header(columns, widths): | ||
for col, w in zip(columns, widths): | ||
fmt = '%%-%ds' % w | ||
click.echo(fmt % COLUMN_TITLE[col], nl=False) | ||
click.echo(' ', nl=False) | ||
click.echo('') | ||
|
||
def _print_hr(widths): | ||
for w in widths: | ||
click.echo('-'*w, nl=False) | ||
click.echo(' ', nl=False) | ||
click.echo('') | ||
|
||
def _print_data(table_data, widths): | ||
for line_data in table_data: | ||
for data, w in zip(line_data, widths): | ||
fmt = '%%-%ds' % w | ||
click.echo(fmt % data, nl=False) | ||
click.echo(' ', nl=False) | ||
click.echo('') | ||
|
||
def _print_table(table_data, columns): | ||
widths = [] | ||
index = 0 | ||
for col in columns: | ||
width = len(COLUMN_TITLE[col]) | ||
for data in table_data: | ||
width = max(width, len(data[index])) | ||
widths.append(width+1) | ||
index += 1 | ||
|
||
_print_header(columns, widths) | ||
_print_hr(widths) | ||
_print_data(table_data, widths) | ||
|
||
|
||
class Ls(object): | ||
def __init__(self, jsubrc, task_ids): | ||
self.__jsubrc = jsubrc | ||
self.__task_ids = task_ids if len(task_ids) else None | ||
|
||
def execute(self): | ||
j = Jsub(self.__jsubrc) | ||
tasks_data = j.ls(self.__task_ids) | ||
|
||
columns = ['task_id', 'name', 'app', 'backend', 'status', 'created_at'] | ||
|
||
table_data = _convert_table_data(tasks_data, columns) | ||
_print_table(table_data, columns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
class JsubError(Exception): | ||
pass | ||
|
||
|
||
class SplitterParamError(JsubError): | ||
pass | ||
|
||
class LauncherNotFoundError(JsubError): | ||
pass | ||
|
||
|
||
class TaskIdFormatError(JsubError): | ||
pass | ||
|
||
class TaskNotFoundError(JsubError): | ||
pass | ||
|
||
|
||
class RepoError(JsubError): | ||
pass | ||
|
||
class RepoReadError(RepoError): | ||
pass | ||
|
||
class RepoWriteError(RepoError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from jsub.error import TaskIdFormatError | ||
|
||
def _convert_tasks_data(tasks): | ||
tasks_data = [] | ||
for task in tasks: | ||
tasks_data.append(task.data) | ||
return tasks_data | ||
|
||
class Ls(object): | ||
def __init__(self, manager, task_id=None): | ||
self.__manager = manager | ||
self.__task_id = task_id | ||
|
||
self.__initialize_manager() | ||
|
||
def __initialize_manager(self): | ||
self.__config_mgr = self.__manager.load_config_manager() | ||
|
||
|
||
def handle(self): | ||
if self.__task_id is None: | ||
return self.__all_tasks() | ||
|
||
if isinstance(self.__task_id, (int, list)): | ||
return self.__find_tasks(self.__task_id) | ||
|
||
raise TaskIdFormatError('Unknown task ID format: %s' % self.__task_id) | ||
|
||
|
||
def __all_tasks(self): | ||
task_pool = self.__manager.load_task_pool() | ||
return _convert_tasks_data(task_pool.all()) | ||
|
||
def __find_tasks(self, task_ids): | ||
task_pool = self.__manager.load_task_pool() | ||
return _convert_tasks_data(task_pool.find(task_ids)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
log_level: DEBUG | ||
time_zone: utc | ||
|
||
extensions: [] | ||
|
||
max_jobs: 100000 | ||
|
||
backend: dirac | ||
|
Oops, something went wrong.