Merge "Convert MeetingJobs methods to top-level functions"
This commit is contained in:
		@@ -1,5 +1,4 @@
 | 
				
			|||||||
#! /usr/bin/env python
 | 
					#! /usr/bin/env python
 | 
				
			||||||
# -*- coding: utf-8 -*-
 | 
					 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#    Copyright 2014 North Dakota State University
 | 
					#    Copyright 2014 North Dakota State University
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
@@ -16,8 +15,6 @@
 | 
				
			|||||||
#    under the License.
 | 
					#    under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PUBLISH_URL = '127.0.0.1'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
YAML_FILE_EXT = ('.yaml', '.yml')
 | 
					YAML_FILE_EXT = ('.yaml', '.yml')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3,
 | 
					WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3,
 | 
				
			||||||
@@ -27,6 +24,11 @@ BASH_SCRIPT = './clonerepo.sh'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
CACHE_DIR = '../.cache'
 | 
					CACHE_DIR = '../.cache'
 | 
				
			||||||
CACHE_YAML_DIR = '../.cache/meetings'
 | 
					CACHE_YAML_DIR = '../.cache/meetings'
 | 
				
			||||||
ICAL_DIR = '../icals'
 | 
					
 | 
				
			||||||
SRC_DIR = '../gerrit-powered-agenda'
 | 
					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,51 +29,57 @@ logging.basicConfig(format='%(asctime)s  - %(levelname)s - %(message)s',
 | 
				
			|||||||
                    level=logging.DEBUG)
 | 
					                    level=logging.DEBUG)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MeetingJobs:
 | 
					def execute_check():
 | 
				
			||||||
    """Executes post, gate, and check jobs."""
 | 
					    """Execute check job."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def execute_check(self):
 | 
					    logging.info('Check job initiated.')
 | 
				
			||||||
        """Execute check job."""
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        logging.info('Check job initiated.')
 | 
					    # NOTE(jotan): once a CLI parameter for YAML_DIR has been
 | 
				
			||||||
        meetings = self.retrieve_meetings(const.YAML_DIR)
 | 
					    # 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
 | 
					    meetings = __load_meetings(yaml_dir)
 | 
				
			||||||
        for m in meetings:
 | 
					 | 
				
			||||||
            m.write_ical()
 | 
					 | 
				
			||||||
            logging.info('Wrote %d meetings to iCal' % (len(meetings)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        os.chdir(const.SRC_DIR)
 | 
					    # convert meetings to a list of ical
 | 
				
			||||||
        if util.check_uniqueness() == 0:
 | 
					    for m in meetings:
 | 
				
			||||||
            if util.check_conflicts() == 0:
 | 
					        m.write_ical()
 | 
				
			||||||
                logging.info('Check job finished.')
 | 
					    logging.info('Wrote %d meetings to iCal' % (len(meetings)))
 | 
				
			||||||
                return 0
 | 
					 | 
				
			||||||
        logging.info('Check job finished.')
 | 
					 | 
				
			||||||
        return 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def execute_gate(self):
 | 
					    os.chdir(const.SRC_DIR)
 | 
				
			||||||
        """Execute gate job."""
 | 
					    if util.check_uniqueness() == 0:
 | 
				
			||||||
 | 
					        if util.check_conflicts() == 0:
 | 
				
			||||||
        logging.info('Gate job initiated.')
 | 
					            logging.info('Check job finished.')
 | 
				
			||||||
        os.chdir(const.SRC_DIR)
 | 
					            return 0
 | 
				
			||||||
        result = util.check_conflicts()
 | 
					    logging.info('Check job finished.')
 | 
				
			||||||
        logging.info('Gate job finished.')
 | 
					    return 1
 | 
				
			||||||
        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.')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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."""
 | 
					    """Return a list of Meetings initialized from files in yaml_dir."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    os.chdir(yaml_dir)
 | 
					    os.chdir(yaml_dir)
 | 
				
			||||||
@@ -86,6 +92,6 @@ def retrieve_meetings(self, yaml_dir):
 | 
				
			|||||||
    os.chdir(const.SRC_DIR)
 | 
					    os.chdir(const.SRC_DIR)
 | 
				
			||||||
    return meetings
 | 
					    return meetings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# entry point
 | 
					# entry point
 | 
				
			||||||
jobs = MeetingJobs()
 | 
					execute_check()
 | 
				
			||||||
jobs.execute_check()
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -99,7 +99,7 @@ class Meeting:
 | 
				
			|||||||
            cal.add_component(event)
 | 
					            cal.add_component(event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # write ical files to disk
 | 
					        # write ical files to disk
 | 
				
			||||||
        ical_dir = const.ICAL_DIR
 | 
					        ical_dir = const.DEFAULT_ICAL_DIR
 | 
				
			||||||
        ical_filename = self.filename[:-4] + 'ics'
 | 
					        ical_filename = self.filename[:-4] + 'ics'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not os.path.exists(ical_dir):
 | 
					        if not os.path.exists(ical_dir):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,7 @@ def check_uniqueness():
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # reads the current changes and verifies
 | 
					    # 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)
 | 
					    change_dict = _counting_dict_with(_make_schedule_key, change_list)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # fails if duplicates exist
 | 
					    # fails if duplicates exist
 | 
				
			||||||
@@ -68,7 +68,7 @@ def check_conflicts():
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # reads the current changes and verifies
 | 
					    # 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)
 | 
					    change_dict = _make_schedule_dict(_make_schedule_key, change_list, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # runs the bash script to clone origin yaml files to .cache folder
 | 
					    # runs the bash script to clone origin yaml files to .cache folder
 | 
				
			||||||
@@ -79,7 +79,8 @@ def check_conflicts():
 | 
				
			|||||||
                                      True)
 | 
					                                      True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # make a set with all the meeting time
 | 
					    # 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
 | 
					    # compares the two, keep track of a conflict flag
 | 
				
			||||||
    conflict = False  # doing this way so we can log all the conflicts
 | 
					    conflict = False  # doing this way so we can log all the conflicts
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user