Make ical generation work without chdirs

chdir isn't something we need to be doing in Python
scripts, as we can and should use absolute or relative paths
in all cases. This will let us use paths passed to us in
config options later.

Change-Id: I3a5a950ab18931075767a81bbf727a5927b7a546
This commit is contained in:
Mathew Odden 2014-05-30 16:39:47 -05:00
parent 7194607dfb
commit 53063a4122
3 changed files with 11 additions and 16 deletions

View File

@ -26,8 +26,8 @@ WEEKDAYS = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3,
SRC_DIR = project_dir
DEFAULT_YAML_DIR = '../meetings'
DEFAULT_ICAL_DIR = '../icals'
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'

View File

@ -103,7 +103,6 @@ class Meeting:
if not os.path.exists(ical_dir):
os.makedirs(ical_dir)
os.chdir(ical_dir)
with open(ical_filename, 'wb') as ics:
ics.write(cal.to_ical())
@ -111,7 +110,6 @@ class Meeting:
num_events = len(cal.subcomponents)
logging.info('\'%s\' processed. [%d event(s)]' % (ical_filename,
num_events))
os.chdir(const.SRC_DIR)
def get_schedule_tuple(self):
"""returns a list of meeting tuples consisting meeting name, meeting

View File

@ -36,17 +36,16 @@ def publish(meeting, ical):
def load_meetings(yaml_dir, meeting_list=None):
"""Return a list of Meetings initialized from files in yaml_dir."""
os.chdir(yaml_dir)
if meeting_list:
meetings_yaml = [f for f in os.listdir()
if os.path.isfile(f) and
f.endswith(const.YAML_FILE_EXT) and
f in meeting_list]
else:
meetings_yaml = [f for f in os.listdir()
if os.path.isfile(f) and
f.endswith(const.YAML_FILE_EXT)]
meetings_yaml = []
for file_name in os.listdir(yaml_dir):
yaml_file = os.path.join(yaml_dir, file_name)
if not os.path.isfile(yaml_file):
continue
if meeting_list and yaml_file not in meeting_list:
continue
meetings_yaml.append(yaml_file)
print meetings_yaml
meetings = [Meeting(yaml.load(open(f, 'r')), f)
for f in meetings_yaml]
@ -151,7 +150,6 @@ def _read_yaml_files(directory):
"""
os.chdir(directory)
yaml_files = []
for file in os.listdir('.'):
if os.path.isfile(file) and file.endswith(const.YAML_FILE_EXT):
@ -167,7 +165,6 @@ def _read_yaml_files(directory):
for schedule in meeting.get_schedule_tuple():
schedules.append(schedule)
os.chdir(const.SRC_DIR)
return schedules