Merge "Convert MeetingJobs methods to top-level functions"
This commit is contained in:
		@@ -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'
 | 
			
		||||
 
 | 
			
		||||
@@ -29,14 +29,17 @@ logging.basicConfig(format='%(asctime)s  - %(levelname)s - %(message)s',
 | 
			
		||||
                    level=logging.DEBUG)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MeetingJobs:
 | 
			
		||||
    """Executes post, gate, and check jobs."""
 | 
			
		||||
 | 
			
		||||
    def execute_check(self):
 | 
			
		||||
def execute_check():
 | 
			
		||||
    """Execute check job."""
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    meetings = __load_meetings(yaml_dir)
 | 
			
		||||
 | 
			
		||||
    # convert meetings to a list of ical
 | 
			
		||||
    for m in meetings:
 | 
			
		||||
@@ -51,7 +54,8 @@ class MeetingJobs:
 | 
			
		||||
    logging.info('Check job finished.')
 | 
			
		||||
    return 1
 | 
			
		||||
 | 
			
		||||
    def execute_gate(self):
 | 
			
		||||
 | 
			
		||||
def execute_gate():
 | 
			
		||||
    """Execute gate job."""
 | 
			
		||||
 | 
			
		||||
    logging.info('Gate job initiated.')
 | 
			
		||||
@@ -60,11 +64,13 @@ class MeetingJobs:
 | 
			
		||||
    logging.info('Gate job finished.')
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
    def execute_post(self):
 | 
			
		||||
 | 
			
		||||
def execute_post():
 | 
			
		||||
    """Execute post job."""
 | 
			
		||||
 | 
			
		||||
    logging.info('Post job initiated.')
 | 
			
		||||
        meetings = self.retrieve_meetings(const.YAML_DIR)
 | 
			
		||||
    yaml_dir = const.DEFAULT_YAML_DIR
 | 
			
		||||
    meetings = __load_meetings(yaml_dir)
 | 
			
		||||
 | 
			
		||||
    # convert meetings to a list of ical
 | 
			
		||||
    for m in meetings:
 | 
			
		||||
@@ -73,7 +79,7 @@ class MeetingJobs:
 | 
			
		||||
    logging.info('Post job finished.')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def retrieve_meetings(self, yaml_dir):
 | 
			
		||||
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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user