diff --git a/.gitignore b/.gitignore index 86b7d64..46aec6e 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,4 @@ ChangeLog # other *.ics .cache - +icals diff --git a/arbiter/const.py b/arbiter/const.py index 6fe4a3f..efc4ff6 100644 --- a/arbiter/const.py +++ b/arbiter/const.py @@ -26,8 +26,6 @@ WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, SRC_DIR = project_dir -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. PUBLISH_URL = 'https://wiki.openstack.org/wiki/Meetings_Autogenerated' diff --git a/arbiter/jobs.py b/arbiter/jobs.py index 94bf8ff..f7aa44e 100644 --- a/arbiter/jobs.py +++ b/arbiter/jobs.py @@ -71,7 +71,6 @@ Post: 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", @@ -82,7 +81,6 @@ Post: newlines.") parser.add_argument("-i", "--icaldir", dest="ical_dir", - default=const.DEFAULT_ICAL_DIR, help="directory to store converted iCal") # parse arguments: @@ -98,8 +96,8 @@ def execute_check(yaml_dir, ical_dir): util.convert_yaml_to_ical(yaml_dir, ical_dir) os.chdir(const.SRC_DIR) - if util.check_uniqueness() == 0: - if util.check_conflicts() == 0: + if util.check_uniqueness(yaml_dir) == 0: + if util.check_conflicts(yaml_dir) == 0: logging.info('Check job finished.') return 0 logging.info('Check job finished.') @@ -111,7 +109,7 @@ def execute_gate(yaml_dir): logging.info('Gate job initiated.') os.chdir(const.SRC_DIR) - result = util.check_conflicts() + result = util.check_conflicts(yaml_dir) logging.info('Gate job finished.') return result @@ -127,6 +125,11 @@ def execute_post(yaml_dir, ical_dir, publish_url): logging.info('Post job finished.') +def _check_if_directory_exists(directory): + if directory and not os.path.isdir(directory): + raise ValueError("Invalid directory %s" % directory) + + def main(): args = parse_args() @@ -136,10 +139,8 @@ def main(): meeting_list_file = args.meeting_list_file ical_dir = args.ical_dir - if (yaml_dir and not os.path.isdir(yaml_dir)): - raise ValueError("invalid YAML directory provided") - if (ical_dir and not os.path.isdir(ical_dir)): - raise ValueError("invalid iCal directory provided") + _check_if_directory_exists(yaml_dir) + _check_if_directory_exists(ical_dir) if not test and not convert: raise ValueError( diff --git a/arbiter/meeting.py b/arbiter/meeting.py index c51d760..70b4be3 100644 --- a/arbiter/meeting.py +++ b/arbiter/meeting.py @@ -44,7 +44,7 @@ class Meeting: cal.add('prodid', '-//OpenStack//Gerrit-Powered Meeting Agendas//EN') cal.add('version', '2.0') - for sch in self.schs: + for sch in self.schedules: # one Event per iCal file event = icalendar.Event() @@ -94,9 +94,6 @@ class Meeting: ical_filename = os.path.basename(self._filename).split('.')[0] + '.ics' ical_filename = os.path.join(ical_dir, ical_filename) - if not os.path.exists(ical_dir): - os.makedirs(ical_dir) - # write ical files to disk with open(ical_filename, 'wb') as ics: ics.write(cal.to_ical()) diff --git a/arbiter/util.py b/arbiter/util.py index 7d587ea..821b353 100644 --- a/arbiter/util.py +++ b/arbiter/util.py @@ -33,10 +33,15 @@ def publish(meeting, ical): def convert_yaml_to_ical(yaml_dir, ical_dir, meeting_list_file=None): - """Convert meeting YAML files to the iCal format and place - in ical_dir. If meeting_list is specified, only those meetings - in yaml_dir with filenames contained in meeting_list are - converted; otherwise, all meeting in yaml_dir are converted. + """Convert meeting YAML files to iCal. + + If meeting_list is specified, only those meetings in yaml_dir with + filenames contained in meeting_list are converted; otherwise, + all meeting in yaml_dir are converted. + + :param yaml_dir: directory where meeting.yaml files are stored + :param ical_dir: location to store iCal files + :param meeting_list_file: file containing a list of meetings """ meetings = meeting.load_meetings(yaml_dir) @@ -50,14 +55,15 @@ def convert_yaml_to_ical(yaml_dir, ical_dir, meeting_list_file=None): logging.info('Wrote %d meetings to iCal' % (len(meetings))) -def check_uniqueness(): - """Check for uniqueness in meeting room and time combination. During gate - job, we do not care about the meeting name. +def check_uniqueness(yaml_dir): + """Check for uniqueness in meeting room and time combination. + :param yaml_dir: directory where meetings are stored + :returns: 0 if no conflicts, and 1 if there are meeting conflicts """ # reads the current changes and verifies - change_list = _read_yaml_files(const.DEFAULT_YAML_DIR) + change_list = _read_yaml_files(yaml_dir) change_dict = _counting_dict_with(_make_schedule_key, change_list) # fails if duplicates exist @@ -75,22 +81,26 @@ def check_uniqueness(): return 1 -def check_conflicts(): - """Return whether the meeting would create scheduling conflicts. At this - point, we are comparing the changes against the origin, while the meeting - do matter. If a meeting from the changes and a different meeting from the - origin shares the same time, then we have a conflict. +def check_conflicts(yaml_dir): + """Return whether the meeting would create scheduling conflicts. + At this point, we are comparing the changes against the origin, + while the meeting do matter. If a meeting from the changes and a + different meeting from the origin shares the same time, then we have a + conflict. + + :param yaml_dir: directory where meetings are stored + :returns: 0 if no conflicts, and 1 if there are meeting conflicts """ # reads the current changes and verifies - change_list = _read_yaml_files(const.DEFAULT_YAML_DIR) + change_list = _read_yaml_files(yaml_dir) change_dict = _make_schedule_dict(_make_schedule_key, change_list, True) # FIXME(lbragstad): Removed the clonerepo script since Jenkins takes care # of that. The path resolution needs to be fix here too. origin_dict = _make_schedule_dict(_make_schedule_key, - _read_yaml_files(const.DEFAULT_YAML_DIR), + _read_yaml_files(yaml_dir), True) # make a set with all the meeting time @@ -109,13 +119,14 @@ def check_conflicts(): conflict = True if conflict: + # FIXME(lbragstad): replace this with True and False instead of + # integers that represent true and false. return 1 return 0 def _read_yaml_files(directory): - """Reads all the yaml in the given directory and returns a list of - schedules times. + """Reads all the yaml in the given directory. :param directory: location of the yaml files :returns: list of schedules @@ -141,7 +152,9 @@ def _read_yaml_files(directory): def _counting_dict_with(key_maker, list): - """Make a counting dictionary. The key is obtained by a function applied to + """Make a counting dictionary. + + The key is obtained by a function applied to the element; the value counts the occurrence of the item in the list. :param key_maker: converts list items to strings @@ -161,7 +174,9 @@ def _counting_dict_with(key_maker, list): def _make_schedule_dict(key_maker, list, replace_flag): - """Make a schedule dictionary. The key is the time of the meeting. If + """Make a schedule dictionary. + + The key is the time of the meeting. If replace_flag is true, then the value is the meeting name; otherwise, if replace_flag is false, the value is a list of meeting names. @@ -186,7 +201,9 @@ def _make_schedule_dict(key_maker, list, replace_flag): def _make_schedule_key(schedule): - """A key making function for a schedule item. The first item in the + """A key making function for a schedule item. + + The first item in the schedule is meeting name, followed by a tuple of time, day, and room. :param schedule: a schedule tuple diff --git a/meetings/storyboard-meeting.yaml b/meetings/storyboard-meeting.yaml index 214916c..713c5c2 100644 --- a/meetings/storyboard-meeting.yaml +++ b/meetings/storyboard-meeting.yaml @@ -24,7 +24,7 @@ agenda: | * Summit! ** Storyboard Session (ttx) ** UX Testing - * Open Discussion topics (Bring them up if you’re interested): + * Open Discussion topics (Bring them up if you are interested): ** Event Subscription ** Code Reviews - ** Fulltext Searc + ** Fulltext Search