Changeset 43:b086c7d68163 in stamper
- Timestamp:
- Aug 14, 2014, 9:16:27 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
stamper/stamper.py
r40 r43 2 2 import json 3 3 import re 4 import pygal4 import os.path 5 5 from datetime import datetime, date, timedelta 6 from os.path import expanduser, exists, islink, isdir 7 from os import symlink, remove 6 from os import symlink, remove, makedirs 8 7 from collections import OrderedDict 9 8 from operator import itemgetter 10 11 12 STAMPS_FILE = expanduser('~/.workstamps.json') 9 import pygal 10 11 12 STAMPS_FILE = os.path.expanduser('~/.workstamps.json') 13 CHARTS_DIR = os.path.expanduser('~/.workstamps-charts') 13 14 DATE_FORMAT = '%Y-%m-%d' 14 15 TIME_FORMAT = '%H:%M:%S' … … 20 21 class Stamper(object): 21 22 22 def __init__(self, stamps_file=STAMPS_FILE): 23 self.stamps_file = STAMPS_FILE 23 def __init__(self, stamps_file=STAMPS_FILE, charts_dir=CHARTS_DIR): 24 self.stamps_file = stamps_file 25 self.charts_dir = charts_dir 24 26 self.ensure_stamps_file() 27 self.ensure_charts_dir() 25 28 self.stamps = [] 26 29 … … 46 49 47 50 def ensure_stamps_file(self): 48 if not exists(self.stamps_file):51 if not os.path.exists(self.stamps_file): 49 52 with open(self.stamps_file, 'w') as stamps_file: 50 53 stamps_file.write('') 54 55 def ensure_charts_dir(self): 56 if not os.path.exists(self.charts_dir): 57 makedirs(self.charts_dir) 51 58 52 59 def load_stamps(self): … … 304 311 '%Y-%m-%d_%H%M%S') 305 312 chart_symlink = 'chart-latest.svg' 306 chart.render_to_file('graphs/' + chart_name) 307 if islink('graphs/'+ chart_symlink): 308 remove('graphs/'+ chart_symlink) 309 symlink(chart_name, 'graphs/'+ chart_symlink) 313 chart_path = os.path.join(self.charts_dir, chart_name) 314 chart_symlink_path = os.path.join(self.charts_dir, chart_symlink) 315 316 chart.render_to_file(chart_path) 317 print('Rendered chart: ' + chart_path) 318 if os.path.islink(chart_symlink_path): 319 remove(chart_symlink_path) 320 symlink(chart_name, chart_symlink_path) 321 print('Updated latest chart: ' + chart_symlink_path) 310 322 311 323 def show_stamps(self, customer=None, stamp_filter=None, verbose=False, … … 399 411 merging them into the list (removing duplicated entries) 400 412 """ 401 if not exists(filename):413 if not os.path.exists(filename): 402 414 print('[error] ' + filename + 'does not exist') 403 415 return 404 if isdir(filename):416 if os.path.isdir(filename): 405 417 print('[error] ' + filename + 'is a directory') 406 418 return
Note:
See TracChangeset
for help on using the changeset viewer.