Fix default paths for meetings and ical dir

Previously, the iCal directory and the meetings directory defaulted
to relative paths. This change defaults those paths to a full path name
for both.

This change also adds the icals directory to the .gitignore of the
project. This way when users generate icals and use the default
settings, they aren't adding icals to the project repository.

Change-Id: If5d62d2c74a7edebc00d58cf210e47c45ec2ea7b
This commit is contained in:
Lance Bragstad 2014-06-01 01:52:44 +00:00
parent ed99e524a8
commit 02c8a264e7
6 changed files with 51 additions and 38 deletions

2
.gitignore vendored
View File

@ -53,4 +53,4 @@ ChangeLog
# other # other
*.ics *.ics
.cache .cache
icals

View File

@ -26,8 +26,6 @@ WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3,
SRC_DIR = project_dir SRC_DIR = project_dir
DEFAULT_YAML_DIR = './meetings'
DEFAULT_ICAL_DIR = './icals'
# NOTE(jotan): The following publish URL is for testing purposes only. # NOTE(jotan): The following publish URL is for testing purposes only.
# It should be later changed to the official OpenStack Meetings Wiki. # It should be later changed to the official OpenStack Meetings Wiki.
PUBLISH_URL = 'https://wiki.openstack.org/wiki/Meetings_Autogenerated' PUBLISH_URL = 'https://wiki.openstack.org/wiki/Meetings_Autogenerated'

View File

@ -71,7 +71,6 @@ Post:
help="convert meeting YAML to iCal format.") help="convert meeting YAML to iCal format.")
parser.add_argument("-y", "--yamldir", parser.add_argument("-y", "--yamldir",
dest="yaml_dir", dest="yaml_dir",
default=const.DEFAULT_YAML_DIR,
help="directory containing YAML to process") help="directory containing YAML to process")
parser.add_argument("-m", "--meetings", parser.add_argument("-m", "--meetings",
dest="meeting_list_file", dest="meeting_list_file",
@ -82,7 +81,6 @@ Post:
newlines.") newlines.")
parser.add_argument("-i", "--icaldir", parser.add_argument("-i", "--icaldir",
dest="ical_dir", dest="ical_dir",
default=const.DEFAULT_ICAL_DIR,
help="directory to store converted iCal") help="directory to store converted iCal")
# parse arguments: # parse arguments:
@ -98,8 +96,8 @@ def execute_check(yaml_dir, ical_dir):
util.convert_yaml_to_ical(yaml_dir, ical_dir) util.convert_yaml_to_ical(yaml_dir, ical_dir)
os.chdir(const.SRC_DIR) os.chdir(const.SRC_DIR)
if util.check_uniqueness() == 0: if util.check_uniqueness(yaml_dir) == 0:
if util.check_conflicts() == 0: if util.check_conflicts(yaml_dir) == 0:
logging.info('Check job finished.') logging.info('Check job finished.')
return 0 return 0
logging.info('Check job finished.') logging.info('Check job finished.')
@ -111,7 +109,7 @@ def execute_gate(yaml_dir):
logging.info('Gate job initiated.') logging.info('Gate job initiated.')
os.chdir(const.SRC_DIR) os.chdir(const.SRC_DIR)
result = util.check_conflicts() result = util.check_conflicts(yaml_dir)
logging.info('Gate job finished.') logging.info('Gate job finished.')
return result return result
@ -127,6 +125,11 @@ def execute_post(yaml_dir, ical_dir, publish_url):
logging.info('Post job finished.') 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(): def main():
args = parse_args() args = parse_args()
@ -136,10 +139,8 @@ def main():
meeting_list_file = args.meeting_list_file meeting_list_file = args.meeting_list_file
ical_dir = args.ical_dir ical_dir = args.ical_dir
if (yaml_dir and not os.path.isdir(yaml_dir)): _check_if_directory_exists(yaml_dir)
raise ValueError("invalid YAML directory provided") _check_if_directory_exists(ical_dir)
if (ical_dir and not os.path.isdir(ical_dir)):
raise ValueError("invalid iCal directory provided")
if not test and not convert: if not test and not convert:
raise ValueError( raise ValueError(

View File

@ -44,7 +44,7 @@ class Meeting:
cal.add('prodid', '-//OpenStack//Gerrit-Powered Meeting Agendas//EN') cal.add('prodid', '-//OpenStack//Gerrit-Powered Meeting Agendas//EN')
cal.add('version', '2.0') cal.add('version', '2.0')
for sch in self.schs: for sch in self.schedules:
# one Event per iCal file # one Event per iCal file
event = icalendar.Event() event = icalendar.Event()
@ -94,9 +94,6 @@ class Meeting:
ical_filename = os.path.basename(self._filename).split('.')[0] + '.ics' ical_filename = os.path.basename(self._filename).split('.')[0] + '.ics'
ical_filename = os.path.join(ical_dir, ical_filename) 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 # write ical files to disk
with open(ical_filename, 'wb') as ics: with open(ical_filename, 'wb') as ics:
ics.write(cal.to_ical()) ics.write(cal.to_ical())

View File

@ -33,10 +33,15 @@ def publish(meeting, ical):
def convert_yaml_to_ical(yaml_dir, ical_dir, meeting_list_file=None): def convert_yaml_to_ical(yaml_dir, ical_dir, meeting_list_file=None):
"""Convert meeting YAML files to the iCal format and place """Convert meeting YAML files to iCal.
in ical_dir. If meeting_list is specified, only those meetings
in yaml_dir with filenames contained in meeting_list are If meeting_list is specified, only those meetings in yaml_dir with
converted; otherwise, all meeting in yaml_dir are converted. 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) 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))) logging.info('Wrote %d meetings to iCal' % (len(meetings)))
def check_uniqueness(): def check_uniqueness(yaml_dir):
"""Check for uniqueness in meeting room and time combination. During gate """Check for uniqueness in meeting room and time combination.
job, we do not care about the meeting name.
: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 # 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) change_dict = _counting_dict_with(_make_schedule_key, change_list)
# fails if duplicates exist # fails if duplicates exist
@ -75,22 +81,26 @@ def check_uniqueness():
return 1 return 1
def check_conflicts(): def check_conflicts(yaml_dir):
"""Return whether the meeting would create scheduling conflicts. At this """Return whether the meeting would create scheduling conflicts.
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.
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 # 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) change_dict = _make_schedule_dict(_make_schedule_key, change_list, True)
# FIXME(lbragstad): Removed the clonerepo script since Jenkins takes care # FIXME(lbragstad): Removed the clonerepo script since Jenkins takes care
# of that. The path resolution needs to be fix here too. # of that. The path resolution needs to be fix here too.
origin_dict = _make_schedule_dict(_make_schedule_key, origin_dict = _make_schedule_dict(_make_schedule_key,
_read_yaml_files(const.DEFAULT_YAML_DIR), _read_yaml_files(yaml_dir),
True) True)
# make a set with all the meeting time # make a set with all the meeting time
@ -109,13 +119,14 @@ def check_conflicts():
conflict = True conflict = True
if conflict: if conflict:
# FIXME(lbragstad): replace this with True and False instead of
# integers that represent true and false.
return 1 return 1
return 0 return 0
def _read_yaml_files(directory): def _read_yaml_files(directory):
"""Reads all the yaml in the given directory and returns a list of """Reads all the yaml in the given directory.
schedules times.
:param directory: location of the yaml files :param directory: location of the yaml files
:returns: list of schedules :returns: list of schedules
@ -141,7 +152,9 @@ def _read_yaml_files(directory):
def _counting_dict_with(key_maker, list): 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. the element; the value counts the occurrence of the item in the list.
:param key_maker: converts list items to strings :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): 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 true, then the value is the meeting name; otherwise, if
replace_flag is false, the value is a list of meeting names. 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): 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. schedule is meeting name, followed by a tuple of time, day, and room.
:param schedule: a schedule tuple :param schedule: a schedule tuple

View File

@ -24,7 +24,7 @@ agenda: |
* Summit! * Summit!
** Storyboard Session (ttx) ** Storyboard Session (ttx)
** UX Testing ** UX Testing
* Open Discussion topics (Bring them up if youre interested): * Open Discussion topics (Bring them up if you are interested):
** Event Subscription ** Event Subscription
** Code Reviews ** Code Reviews
** Fulltext Searc ** Fulltext Search