Refactor/cleanup jobs.py module
Since this is the main entry point for now, we should make it more obvious and clean it up. This includes getting rid of relative imports, cleaning up imported classes, and pulling some of the boiler plate code into more readable methods. Change-Id: I7771c7ea8cc6e85121abad6b95c78d6cabb00dcd
This commit is contained in:
parent
d5e980a5f7
commit
7194607dfb
143
arbiter/jobs.py
143
arbiter/jobs.py
@ -15,12 +15,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
||||
import os
|
||||
|
||||
import const
|
||||
import util
|
||||
from arbiter import const
|
||||
from arbiter import util
|
||||
|
||||
|
||||
# logging settings
|
||||
@ -28,6 +28,67 @@ logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
level=logging.DEBUG)
|
||||
|
||||
|
||||
def parse_args():
|
||||
# build option parser:
|
||||
description = """
|
||||
A tool that automates the process for testing, integrating, and
|
||||
publishing changes to OpenStack meetings using the existing OpenStack
|
||||
project infrastructure.
|
||||
"""
|
||||
|
||||
epilog = """
|
||||
This program is meant to be invoked as a Jenkins job during check,
|
||||
gate, and post tests. Depending on which test invokes the program,
|
||||
it will perform different activites.
|
||||
|
||||
Check:
|
||||
- Verify correct YAML syntax for proposed meeting changes.
|
||||
- Verify YAML files can be converted to valid iCal files
|
||||
- Test that proposed changes would not result in scheduling
|
||||
conflicts
|
||||
|
||||
Gate:
|
||||
- Test that proposed changes would not result in scheduling
|
||||
conflicts (including conflicts with changes that have been
|
||||
made since the inital check test).
|
||||
|
||||
Post:
|
||||
- Convert YAML files to iCal files
|
||||
- Publish meeting changes and associated iCal files to a
|
||||
public wiki location
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description=description,
|
||||
epilog=epilog)
|
||||
|
||||
parser.add_argument("-t", "--test",
|
||||
help="test to execute. valid values are check,\
|
||||
gate, and post.")
|
||||
parser.add_argument("-c", "--convert",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="convert meeting YAML to iCal format.")
|
||||
parser.add_argument("-y", "--yamldir",
|
||||
dest="yaml_dir",
|
||||
default=const.DEFAULT_YAML_DIR,
|
||||
help="directory containing YAML to process")
|
||||
parser.add_argument("-m", "--meetings",
|
||||
dest="meeting_list_file",
|
||||
help="name of file containing meetings to \
|
||||
process. meetings are specified by filename,\
|
||||
which correspond to meeting filenames in\
|
||||
yamldir. filenames should be separated by\
|
||||
newlines.")
|
||||
parser.add_argument("-i", "--icaldir",
|
||||
dest="ical_dir",
|
||||
default=const.DEFAULT_ICAL_DIR,
|
||||
help="directory to store converted iCal")
|
||||
|
||||
# parse arguments:
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def execute_check(yaml_dir, ical_dir):
|
||||
"""Execute check job."""
|
||||
|
||||
@ -65,67 +126,9 @@ def execute_post(yaml_dir, ical_dir, publish_url):
|
||||
|
||||
logging.info('Post job finished.')
|
||||
|
||||
# entry point
|
||||
if __name__ == '__main__':
|
||||
|
||||
# build option parser:
|
||||
description = """
|
||||
A tool that automates the process for testing, integrating, and
|
||||
publishing changes to OpenStack meetings using the existing OpenStack
|
||||
project infrastructure.
|
||||
"""
|
||||
|
||||
epilog = """
|
||||
This program is meant to be invoked as a Jenkins job during check,
|
||||
gate, and post tests. Depending on which test invokes the program,
|
||||
it will perform different activites.
|
||||
|
||||
Check:
|
||||
- Verify correct YAML syntax for proposed meeting changes.
|
||||
- Verify YAML files can be converted to valid iCal files
|
||||
- Test that proposed changes would not result in scheduling
|
||||
conflicts
|
||||
|
||||
Gate:
|
||||
- Test that proposed changes would not result in scheduling
|
||||
conflicts (including conflicts with changes that have been
|
||||
made since the inital check test).
|
||||
|
||||
Post:
|
||||
- Convert YAML files to iCal files
|
||||
- Publish meeting changes and associated iCal files to a
|
||||
public wiki location
|
||||
"""
|
||||
parser = ArgumentParser(
|
||||
formatter_class=RawDescriptionHelpFormatter,
|
||||
description=description,
|
||||
epilog=epilog)
|
||||
|
||||
parser.add_argument("-t", "--test",
|
||||
help="test to execute. valid values are check,\
|
||||
gate, and post.")
|
||||
parser.add_argument("-c", "--convert",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="convert meeting YAML to iCal format.")
|
||||
parser.add_argument("-y", "--yamldir",
|
||||
dest="yaml_dir",
|
||||
default=const.DEFAULT_YAML_DIR,
|
||||
help="directory containing YAML to process")
|
||||
parser.add_argument("-m", "--meetings",
|
||||
dest="meeting_list_file",
|
||||
help="name of file containing meetings to \
|
||||
process. meetings are specified by filename,\
|
||||
which correspond to meeting filenames in\
|
||||
yamldir. filenames should be separated by\
|
||||
newlines.")
|
||||
parser.add_argument("-i", "--icaldir",
|
||||
dest="ical_dir",
|
||||
default=const.DEFAULT_ICAL_DIR,
|
||||
help="directory to store converted iCal")
|
||||
|
||||
# parse arguments:
|
||||
args = parser.parse_args()
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
test = args.test
|
||||
convert = args.convert
|
||||
@ -134,12 +137,12 @@ Post:
|
||||
ical_dir = args.ical_dir
|
||||
|
||||
if (yaml_dir and not os.path.isdir(yaml_dir)):
|
||||
parser.error("invalid YAML directory provided")
|
||||
raise ValueError("invalid YAML directory provided")
|
||||
if (ical_dir and not os.path.isdir(ical_dir)):
|
||||
parser.error("invalid iCal directory provided")
|
||||
raise ValueError("invalid iCal directory provided")
|
||||
|
||||
if not test and not convert:
|
||||
parser.error(
|
||||
raise ValueError(
|
||||
"invalid arguments. must specify test or convert")
|
||||
elif test:
|
||||
if test == "check":
|
||||
@ -149,15 +152,19 @@ Post:
|
||||
elif test == "post":
|
||||
execute_post(yaml_dir, ical_dir, const.PUBLISH_URL)
|
||||
else:
|
||||
parser.error("invalid test provided")
|
||||
raise ValueError("invalid test provided")
|
||||
elif convert:
|
||||
# if file containing list of meetings provided
|
||||
if meeting_list_file:
|
||||
if not os.path.isfile(meeting_list_file):
|
||||
parser.error("meeting list file does not exist")
|
||||
raise ValueError("meeting list file does not exist")
|
||||
util.convert_yaml_to_ical(yaml_dir,
|
||||
ical_dir,
|
||||
meeting_list_file)
|
||||
else:
|
||||
# convert all meetings in yaml_dir
|
||||
util.convert_yaml_to_ical(yaml_dir, ical_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user