Commits

Mathias Panzenböck  committed 4dc1546

--join to join files

  • Participants
  • Parent commits 2e43ca1

Comments (0)

Files changed (1)

 	
 	@property
 	def first_day(self):
-		return self._entries[0].first[0].date()
+		days = [quota.start for quota in self._quota]
+
+		if self._entries and self._entries[0].first:
+			days.append(self._entries[0].first[0].date())
+
+		return min(days)
 	
 	def set_quota(self,quota):
 		inserted = False
 		else:
 			self._quota.append(quota)
 
+	def joinf(self,fname):
+		other = TimeTable()
+		other.loadf(fname)
+		self.join(other)
+
+	def join(self,other):
+		if self.current or other.current:
+			raise ValueError('cannot join files with open sessions')
+		if self._entries:
+			del self._entries[-1]
+		other_entries = other._entries
+		if other_entries:
+			self._entries.extend(other_entries[:-1])
+		self._entries.append(Entry())
+		self._entries.sort()
+		self.holidays.extend(other.holidays)
+		self._quota.extend(other._quota)
+		self._onmsg.extend(other._onmsg)
+		self._onwrite.extend(other._onwrite)
+
 	def loadf(self,fname):
 		with open(fname,'r') as f:
 			self.load(f,os.path.dirname(os.path.abspath(fname)))
 		self._entries[-1].end()
 		self._entries.append(Entry())
 	
+	@property
 	def current(self):
 		if not self._entries or not self._entries[-1]:
+			return None
+		return self._entries[-1]
+
+	def printCurrent(self):
+		current = self.current
+		if not current:
 			sys.stdout.write('no current session\n')
 		else:
-			self._entries[-1].write(sys.stdout,True)
+			current.write(sys.stdout,True)
 	
 	def list(self):
 		if not self._entries:
 		help='Set quota in h/workday for a given date range.',default=None)
 	parser.add_option('--quota','-q',action='store_true',default=False,
 		help='Show difference to current work quota.')
+	parser.add_option('--join','-j',action='append',type='string',
+		help='Join time tracking files into this one.')
 
 	opts, args = parser.parse_args()
 
 		if args:
 			parser.error('no arguments expected')
 		timeTable.printQuota()
+	elif opts.join:
+		if args:
+			parser.error('no arguments expected')
+		for fname in opts.join:
+			timeTable.joinf(fname)
+		timeTable.storef(opts.file)
 	elif opts.current or (not args and not opts.end and not opts.repeat):
 		if args:
 			parser.error('no arguments expected')
-		timeTable.current()
+		timeTable.printCurrent()
 	else:
 		if opts.repeat:
 			if args: