-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mberacochea/feature/slurm
First working version that supports LSF and Slurm
- Loading branch information
Showing
10 changed files
with
736 additions
and
341 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ tasks: | |
build: | ||
cmds: | ||
- pyinstaller mjobs/main.py --onefile --clean --name mjobs | ||
- scp dist/mjobs codon:~/ |
Binary file not shown.
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,90 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2021-2024 - Martin Beracochea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import csv | ||
import sys | ||
from abc import ABC | ||
|
||
from rich.console import Console | ||
from rich.table import Table | ||
from rich_argparse import RichHelpFormatter | ||
|
||
|
||
class Base(ABC): | ||
def __init__(self, console: Console, error_console: Console) -> None: | ||
"""console is the default one to print content | ||
error_console will be used to print error messages | ||
""" | ||
self.console = console | ||
self.error_console = console | ||
super().__init__() | ||
|
||
def get_args(self, implementation_name: str): | ||
"""Base arguments that every implementation should support""" | ||
parser = argparse.ArgumentParser( | ||
description=f"Just like {implementation_name} but a bit nicer", | ||
formatter_class=RichHelpFormatter, | ||
) | ||
parser.add_argument( | ||
"-f", | ||
dest="filter", | ||
required=False, | ||
help="Filter the jobs using the specified regex on the job name or pending reason.", | ||
) | ||
parser.add_argument( | ||
"-ts", | ||
"--tsv", | ||
dest="tsv", | ||
action="store_true", | ||
help="No fancy table, a good ol' tsv", | ||
) | ||
parser.add_argument( | ||
"-nh", | ||
dest="no_header", | ||
action="store_true", | ||
help="Don't print the table header, useful to pipe the tsv output", | ||
) | ||
return parser | ||
|
||
def render( | ||
self, | ||
title: str, | ||
columns: list[dict[str, any]], | ||
rows: list[dict[str, any]], | ||
): | ||
"""Render the jobs""" | ||
if self.args.tsv: | ||
# print with no styles | ||
writer = csv.writer(sys.stdout, delimiter="\t") | ||
if not self.args.no_header: | ||
writer.writerow([c.get("header") for c in columns]) | ||
writer.writerows(rows) | ||
else: | ||
# print the fancy table | ||
table = Table( | ||
title=title, show_lines=True, show_header=not self.args.no_header | ||
) | ||
for col in columns: | ||
table.add_column(**col) | ||
for row in rows: | ||
table.add_row(*row) | ||
self.console.print(table) | ||
|
||
def main(self): | ||
"""Main execution point. | ||
Should handle the logic to get jobs, build the table and any other features""" | ||
pass |
Oops, something went wrong.