Commits

Mathias Panzenböck committed 2e43ca1

support multiple holiday files (not yet via arguments)

  • Participants
  • Parent commits b234d20

Comments (0)

Files changed (1)

 class TimeTable(object):
 	def __init__(self):
 		self._entries = []
-		self.holidays = None
+		self.holidays = []
 		self._quota = []
 		self._http = None
 		self._onmsg = []
 				if key == 'holidays':
 					if (value.startswith('http:') or value.startswith('https:') or
 						value.startswith('ftp:') or value.startswith('sftp:')):
-						self.holidays = value
+						self.holidays.append(value)
 					else:
-						self.holidays = os.path.join(dirname,value)
+						self.holidays.append(os.path.join(dirname,value))
 				elif key == 'quota':
 					self.set_quota(Quota.parse(value))
 				elif key == 'onmsg':
 
 	def store(self,f):
 		self.write_comment(f,"panzi's simple time tracking")
-		if self.holidays:
-			self.write_setting(f, 'holidays', self.holidays)
+		for holidays in self.holidays:
+			self.write_setting(f, 'holidays', holidays)
 		for quota in self._quota:
 			self.write_setting(f, 'quota', str(quota))
 		for cmd in self._onmsg:
 		zero = timedelta()
 		if self.holidays:
 			from icalendar import Calendar
-			if self.holidays.startswith("http:") or self.holidays.startswith("https:"):
-				cals = Calendar.from_string(self._http_get(self.holidays), True)
-			else:
-				with open(self.holidays) as f:
-					cals = Calendar.from_string(f.read(), True)
-			for cal in cals:
-				for holiday in cal.subcomponents:
-					start = holiday['dtstart'].dt
-					if isinstance(start, datetime):
-						startdate = startdate.date()
-					elif not isinstance(start, date):
-						raise ValueError('Unknown date type: %s' % repr(start))
-					else:
-						startdate = start
-					none_work_days.add(startdate)
-					if 'dtend' in holiday:
-						end = holiday['dtend'].dt
-					elif 'duration' in holiday:
-						end = start + holiday['duration'].td
-					else:
-						sys.stderr.write('*** error: no end date or duration for holiday: %s %s\n' %
-							(start, holiday['summary']))
-						continue
+			for holidays in self.holidays:
+				if holidays.startswith("http:") or holidays.startswith("https:"):
+					cals = Calendar.from_string(self._http_get(holidays), True)
+				else:
+					with open(holidays) as f:
+						cals = Calendar.from_string(f.read(), True)
+				for cal in cals:
+					for holiday in cal.subcomponents:
+						start = holiday['dtstart'].dt
+						if isinstance(start, datetime):
+							startdate = startdate.date()
+						elif not isinstance(start, date):
+							raise ValueError('Unknown date type: %s' % repr(start))
+						else:
+							startdate = start
+						none_work_days.add(startdate)
+						if 'dtend' in holiday:
+							end = holiday['dtend'].dt
+						elif 'duration' in holiday:
+							end = start + holiday['duration'].td
+						else:
+							sys.stderr.write('*** error: no end date or duration for holiday: %s %s\n' %
+								(start, holiday['summary']))
+							continue
 
-					if isinstance(end, datetime):
-						if end - datetime(end.year, end.month, end.day) > zero:
-							end = end.date() + one_day
-						else:
-							end = end.date()
-					elif not isinstance(end, date):
-						raise ValueError('Unknown date type: %s' % repr(end))
-					dt = startdate + one_day
-					while dt < end:
-						none_work_days.add(dt)
-						dt += one_day
+						if isinstance(end, datetime):
+							if end - datetime(end.year, end.month, end.day) > zero:
+								end = end.date() + one_day
+							else:
+								end = end.date()
+						elif not isinstance(end, date):
+							raise ValueError('Unknown date type: %s' % repr(end))
+						dt = startdate + one_day
+						while dt < end:
+							none_work_days.add(dt)
+							dt += one_day
 		
 		day = self.first_day
 		today = datetime.now().date()
 	elif opts.holidays:
 		if args:
 			parser.error('no arguments expected')
-		timeTable.holidays = opts.holidays
+		timeTable.holidays = [opts.holidays]
 		timeTable.storef(opts.file)
 	elif opts.set_quota:
 		if args: