TimeTracker/TimeTracker.py

branch
eric7
changeset 115
859d59103f9f
parent 114
f58b64382e67
child 116
e8b0641eba15
equal deleted inserted replaced
114:f58b64382e67 115:859d59103f9f
147 147
148 def __readTrackerEntries(self): 148 def __readTrackerEntries(self):
149 """ 149 """
150 Private slot to read the time tracker entries from a file. 150 Private slot to read the time tracker entries from a file.
151 """ 151 """
152 from .TimeTrackEntry import TimeTrackEntry
153
152 if os.path.exists(self.__trackerFilePath): 154 if os.path.exists(self.__trackerFilePath):
153 try: 155 try:
154 with open(self.__trackerFilePath, "r") as f: 156 with open(self.__trackerFilePath, "r") as f:
155 jsonString = f.read() 157 jsonString = f.read()
156 entriesDataList = json.loads(jsonString) 158 entriesDataList = json.loads(jsonString)
163 """ not be read.</p><p>Reason: {1}</p>""" 165 """ not be read.</p><p>Reason: {1}</p>"""
164 ).format(self.__trackerFilePath, str(err)), 166 ).format(self.__trackerFilePath, str(err)),
165 ) 167 )
166 return 168 return
167 169
168 from .TimeTrackEntry import TimeTrackEntry
169
170 invalidCount = 0 170 invalidCount = 0
171 for data in entriesDataList: 171 for data in entriesDataList:
172 entry = TimeTrackEntry(self.__plugin) 172 entry = TimeTrackEntry(self.__plugin)
173 eid = entry.fromDict(data) 173 eid = entry.fromDict(data)
174 if eid > -1: 174 if eid > -1:
207 ) 207 )
208 try: 208 try:
209 jsonString = json.dumps(entriesDataList, indent=2) 209 jsonString = json.dumps(entriesDataList, indent=2)
210 with open(filePath, "w") as f: 210 with open(filePath, "w") as f:
211 f.write(jsonString) 211 f.write(jsonString)
212 except (TypeError, OSError) as err: 212 except (OSError, TypeError) as err:
213 EricMessageBox.critical( 213 EricMessageBox.critical(
214 self.__ui, 214 self.__ui,
215 self.tr("Save Time Tracker File"), 215 self.tr("Save Time Tracker File"),
216 self.tr( 216 self.tr(
217 """<p>The time tracker file <b>{0}</b> could""" 217 """<p>The time tracker file <b>{0}</b> could"""
221 221
222 def importTrackerEntries(self, fname): 222 def importTrackerEntries(self, fname):
223 """ 223 """
224 Public slot to import tracker entries from a file. 224 Public slot to import tracker entries from a file.
225 225
226 @param fname name of the file to import (string) 226 @param fname name of the file to import
227 """ 227 @type str
228 """
229 from .TimeTrackEntry import TimeTrackEntry
230
228 try: 231 try:
229 with open(fname, "r", encoding="utf-8") as f: 232 with open(fname, "r", encoding="utf-8") as f:
230 jsonString = f.read() 233 jsonString = f.read()
231 entriesDataList = json.loads(jsonString) 234 entriesDataList = json.loads(jsonString)
232 except (OSError, json.JSONDecodeError) as err: 235 except (OSError, json.JSONDecodeError) as err:
237 """<p>The time tracker file <b>{0}</b> could""" 240 """<p>The time tracker file <b>{0}</b> could"""
238 """ not be read.</p><p>Reason: {1}</p>""" 241 """ not be read.</p><p>Reason: {1}</p>"""
239 ).format(fname, str(err)), 242 ).format(fname, str(err)),
240 ) 243 )
241 return 244 return
242
243 from .TimeTrackEntry import TimeTrackEntry
244 245
245 invalidCount = 0 246 invalidCount = 0
246 duplicateCount = 0 247 duplicateCount = 0
247 entries = [] 248 entries = []
248 249
318 @param task task description 319 @param task task description
319 @type str 320 @type str
320 @param comment comment 321 @param comment comment
321 @type str 322 @type str
322 """ 323 """
324 from .TimeTrackEntry import TimeTrackEntry
325
323 if not self.__plugin.getPreferences("AllowDuplicates"): 326 if not self.__plugin.getPreferences("AllowDuplicates"):
324 startDateTimes = [ 327 startDateTimes = [
325 entry.getStartDateTime() for entry in self.__entries.values() 328 entry.getStartDateTime() for entry in self.__entries.values()
326 ] 329 ]
327 if startDateTime in startDateTimes: 330 if startDateTime in startDateTimes:
329 332
330 if duration < self.__plugin.getPreferences("MinimumDuration"): 333 if duration < self.__plugin.getPreferences("MinimumDuration"):
331 return 334 return
332 335
333 nextID = max(self.__entries.keys()) + 1 if len(self.__entries.keys()) else 0 336 nextID = max(self.__entries.keys()) + 1 if len(self.__entries.keys()) else 0
334
335 from .TimeTrackEntry import TimeTrackEntry
336 337
337 entry = TimeTrackEntry(self.__plugin) 338 entry = TimeTrackEntry(self.__plugin)
338 entry.setID(nextID) 339 entry.setID(nextID)
339 entry.setStartDateTime(startDateTime) 340 entry.setStartDateTime(startDateTime)
340 entry.setDuration(duration) 341 entry.setDuration(duration)

eric ide

mercurial