From 9724aab632ee208fd1c1bf738d5ad1e4e476150d Mon Sep 17 00:00:00 2001 From: Josh Tan Date: Fri, 18 Apr 2014 13:55:31 -0500 Subject: [PATCH] Convert MeetingJobs methods to top-level functions Having MeetingJobs methods remain as class methods unnecessary requires a MeetingJobs object to be instantiated before they can be invoked. Each of these class methods has been converted to corresponding top-level functions in the jobs module. In addition, constant variable defintions have been moved from the jobs module to the const module. Some variable names for constant variables in the const module have been prepended with 'DEFAULT_', since future patches will allow for these values to be optionally overriden by command-line parameters. Change-Id: I884ea95f56fca56dd4ae697d67e8b592e30aa998 --- gerrit-powered-agenda/const.py | 12 +++-- gerrit-powered-agenda/jobs.py | 86 +++++++++++++++++--------------- gerrit-powered-agenda/meeting.py | 2 +- gerrit-powered-agenda/util.py | 7 +-- 4 files changed, 58 insertions(+), 49 deletions(-) diff --git a/gerrit-powered-agenda/const.py b/gerrit-powered-agenda/const.py index 497f139..4642253 100644 --- a/gerrit-powered-agenda/const.py +++ b/gerrit-powered-agenda/const.py @@ -1,5 +1,4 @@ #! /usr/bin/env python -# -*- coding: utf-8 -*- # # Copyright 2014 North Dakota State University # @@ -16,8 +15,6 @@ # under the License. -PUBLISH_URL = '127.0.0.1' - YAML_FILE_EXT = ('.yaml', '.yml') WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, @@ -27,6 +24,11 @@ BASH_SCRIPT = './clonerepo.sh' CACHE_DIR = '../.cache' CACHE_YAML_DIR = '../.cache/meetings' -ICAL_DIR = '../icals' + SRC_DIR = '../gerrit-powered-agenda' -YAML_DIR = '../meetings' + +DEFAULT_YAML_DIR = '../meetings' +DEFAULT_ICAL_DIR = '../icals' +# NOTE(jotan): The following publish URL is for testing purposes only. +# It should be later changed to the official OpenStack Meetings Wiki. +DEFAULT_PUBLISH_URL = 'https://wiki.openstack.org/wiki/Meetings_Autogenerated' diff --git a/gerrit-powered-agenda/jobs.py b/gerrit-powered-agenda/jobs.py index 82282c5..e25b0a7 100644 --- a/gerrit-powered-agenda/jobs.py +++ b/gerrit-powered-agenda/jobs.py @@ -29,51 +29,57 @@ logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.DEBUG) -class MeetingJobs: - """Executes post, gate, and check jobs.""" +def execute_check(): + """Execute check job.""" - def execute_check(self): - """Execute check job.""" + logging.info('Check job initiated.') - logging.info('Check job initiated.') - meetings = self.retrieve_meetings(const.YAML_DIR) + # NOTE(jotan): once a CLI parameter for YAML_DIR has been + # implemented, only use DEFAULT_YAML_DIR if the parameter has + # not been supplied + yaml_dir = const.DEFAULT_YAML_DIR - # convert meetings to a list of ical - for m in meetings: - m.write_ical() - logging.info('Wrote %d meetings to iCal' % (len(meetings))) + meetings = __load_meetings(yaml_dir) - os.chdir(const.SRC_DIR) - if util.check_uniqueness() == 0: - if util.check_conflicts() == 0: - logging.info('Check job finished.') - return 0 - logging.info('Check job finished.') - return 1 + # convert meetings to a list of ical + for m in meetings: + m.write_ical() + logging.info('Wrote %d meetings to iCal' % (len(meetings))) - def execute_gate(self): - """Execute gate job.""" - - logging.info('Gate job initiated.') - os.chdir(const.SRC_DIR) - result = util.check_conflicts() - logging.info('Gate job finished.') - return result - - def execute_post(self): - """Execute post job.""" - - logging.info('Post job initiated.') - meetings = self.retrieve_meetings(const.YAML_DIR) - - # convert meetings to a list of ical - for m in meetings: - m.write_ical() - logging.info('Wrote %d meetings to iCal' % (len(meetings))) - logging.info('Post job finished.') + os.chdir(const.SRC_DIR) + if util.check_uniqueness() == 0: + if util.check_conflicts() == 0: + logging.info('Check job finished.') + return 0 + logging.info('Check job finished.') + return 1 -def retrieve_meetings(self, yaml_dir): +def execute_gate(): + """Execute gate job.""" + + logging.info('Gate job initiated.') + os.chdir(const.SRC_DIR) + result = util.check_conflicts() + logging.info('Gate job finished.') + return result + + +def execute_post(): + """Execute post job.""" + + logging.info('Post job initiated.') + yaml_dir = const.DEFAULT_YAML_DIR + meetings = __load_meetings(yaml_dir) + + # convert meetings to a list of ical + for m in meetings: + m.write_ical() + logging.info('Wrote %d meetings to iCal' % (len(meetings))) + logging.info('Post job finished.') + + +def __load_meetings(yaml_dir): """Return a list of Meetings initialized from files in yaml_dir.""" os.chdir(yaml_dir) @@ -86,6 +92,6 @@ def retrieve_meetings(self, yaml_dir): os.chdir(const.SRC_DIR) return meetings + # entry point -jobs = MeetingJobs() -jobs.execute_check() +execute_check() diff --git a/gerrit-powered-agenda/meeting.py b/gerrit-powered-agenda/meeting.py index 7c5bb1e..6867696 100644 --- a/gerrit-powered-agenda/meeting.py +++ b/gerrit-powered-agenda/meeting.py @@ -99,7 +99,7 @@ class Meeting: cal.add_component(event) # write ical files to disk - ical_dir = const.ICAL_DIR + ical_dir = const.DEFAULT_ICAL_DIR ical_filename = self.filename[:-4] + 'ics' if not os.path.exists(ical_dir): diff --git a/gerrit-powered-agenda/util.py b/gerrit-powered-agenda/util.py index b178551..6e101bf 100644 --- a/gerrit-powered-agenda/util.py +++ b/gerrit-powered-agenda/util.py @@ -41,7 +41,7 @@ def check_uniqueness(): """ # reads the current changes and verifies - change_list = _read_yaml_files(const.YAML_DIR) + change_list = _read_yaml_files(const.DEFAULT_YAML_DIR) change_dict = _counting_dict_with(_make_schedule_key, change_list) # fails if duplicates exist @@ -68,7 +68,7 @@ def check_conflicts(): """ # reads the current changes and verifies - change_list = _read_yaml_files(const.YAML_DIR) + change_list = _read_yaml_files(const.DEFAULT_YAML_DIR) change_dict = _make_schedule_dict(_make_schedule_key, change_list, True) # runs the bash script to clone origin yaml files to .cache folder @@ -79,7 +79,8 @@ def check_conflicts(): True) # make a set with all the meeting time - meeting_time_set = set(change_dict.keys() + origin_dict.keys()) + meeting_time_set = set(list(change_dict.keys()) + + list(origin_dict.keys())) # compares the two, keep track of a conflict flag conflict = False # doing this way so we can log all the conflicts