Skip to content

Commit

Permalink
Merge pull request EESSI#80 from Hafsa-Naeem/command_line_arguments
Browse files Browse the repository at this point in the history
split up option parsers for event handler and job manager
  • Loading branch information
trz42 authored Nov 30, 2022
2 parents 05716de + ee5496f commit 6cd0ddc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
5 changes: 3 additions & 2 deletions eessi_bot_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import waitress

from connections import github
from tools import args, config
from tools import config
from tools.args import event_handler_parse
from tasks.build import submit_build_jobs
from tasks.deploy import deploy_built_artefacts

Expand Down Expand Up @@ -93,7 +94,7 @@ def handle_pull_request_event(self, event_info, log_file=None):

def main():
"""Main function."""
opts = args.parse()
opts = event_handler_parse()
config.read_file("app.cfg")
github.connect()

Expand Down
6 changes: 4 additions & 2 deletions eessi_bot_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import time

from connections import github
from tools.args import job_manager_parse
from datetime import datetime, timezone
from tools import args, config, run_cmd
from tools import config, run_cmd

from pyghee.utils import log, error

Expand Down Expand Up @@ -502,7 +503,8 @@ def process_finished_job(self, finished_job):

def main():
"""Main function."""
opts = args.parse()

opts = job_manager_parse()
config.read_file("app.cfg")
github.connect()

Expand Down
30 changes: 26 additions & 4 deletions tools/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@
import argparse


def parse():
def parse_common_args(args=None):
parser = argparse.ArgumentParser()

parser.add_argument(
"-c", "--cron",
help="run in cron mode instead of web app mode",
"-d", "--debug",
help="print debug information",
action="store_true",
)

parsed_args, unknown = parser.parse_known_args(args=args)

return parsed_args, unknown


def event_handler_parse(args=None):
parsed_args, unknown_args = parse_common_args(args=args)
parser = argparse.ArgumentParser()

parser.add_argument(
"-b", "--build",
help="accept software build requests",
Expand All @@ -36,11 +46,23 @@ def parse():
help="use event data from a JSON file",
)

parser.add_argument(
"-c", "--cron",
help="run in cron mode instead of web app mode",
action="store_true",
)

parser.add_argument(
"-p", "--port", default=3000,
help="listen on a specific port for events (default 3000)",
)

return parser.parse_args(args=unknown_args, namespace=parsed_args)


def job_manager_parse(args=None):
parsed_args, unknown_args = parse_common_args(args=args)
parser = argparse.ArgumentParser()
parser.add_argument(
"-i", "--max-manager-iterations", default=-1,
help="loop behaviour: i<0 - indefinite, i==0 - don't run, i>0: run i iterations (default -1)",
Expand All @@ -51,4 +73,4 @@ def parse():
help="limits the processing to a specific job id or list of comma-separated list of job ids",
)

return parser.parse_args()
return parser.parse_args(args=unknown_args, namespace=parsed_args)

0 comments on commit 6cd0ddc

Please sign in to comment.