summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--perc65
1 files changed, 47 insertions, 18 deletions
diff --git a/perc b/perc
index b125b3a..7419476 100644
--- a/perc
+++ b/perc
@@ -391,30 +391,22 @@ def parseUserArgs(args, user):
format = None
times = args[0:1]
- default_start = datetime.strptime(CONFIG["DEFAULTS"][NICK]["start"], "%H:%M")
- default_finish = datetime.strptime(CONFIG["DEFAULTS"][NICK]["finish"], "%H:%M")
-
- # Set start and finish to defaults
- start = datetime.combine(NOW.date(), default_start.time())
- finish = datetime.combine(NOW.date(), default_finish.time())
-
if len(times) == 1:
- finish, format = parseDatetime(times[0])#parseTime(times[0])
+ finish, format = parseDatetime(times[0])
elif len(times) >= 2:
- start, format = parseDatetime(times[0])#parseTime(times[0])
- finish, format = parseDatetime(times[1])#parseTime(times[1])
+ start, format = parseDatetime(times[0])
+ finish, format = parseDatetime(times[1])
if options.start:
- start, format = parseDatetime(options.start)#parseTime(options.start)
+ start, format = parseDatetime(options.start)
if options.finish:
- finish, format = parseDatetime(options.finish)#parseTime(options.finish)
- if format is None:
- format = CONFIG["DEFAULTS"][NICK]["format"]
-
- start_formatted = start.strftime(format)
- finish_formatted = finish.strftime(format)
+ finish, format = parseDatetime(options.finish)
+
+ if format:
+ start_formatted = start.strftime(format)
+ finish_formatted = finish.strftime(format)
- output_type = options.output if options.output else CONFIG["DEFAULTS"][NICK]["output"]
+ output_type = options.output if options.output else user.output
ratio = clamp(calculate_ratio(start, finish), 0.0, 1.0)
@@ -470,6 +462,8 @@ class Output(object):
func(ratio, start, finish)
class User(object):
+
+ PROPERTIES = ["start", "finish", "format", "output", "lunch"]
Name = property(fget=lambda self: self._name)
@@ -490,6 +484,41 @@ class User(object):
sys.exit(1)
CONFIG["DEFAULTS"][self.Name] = self.data
+
+ CONFIG_IS_DIRTY = True
+
+ def __datetimeGetter(self, name):
+ try:
+ return datetime.combine(NOW.date(), datetime.strptime(self.data[name], "%H:%M").time())
+ except KeyError:
+ return CONFIG["DEFAULTS"]["default"][name]
+
+ def __defaultSetter(self, name, value):
+ self._data[name] = value
+
+ def __defaultDeleter(self, name):
+ del self._data[name]
+
+ def __defaultGetter(self, name):
+ try:
+ return self.data[name]
+ except KeyError:
+ return CONFIG["DEFAULTS"]["default"][name]
+
+ def __getattr__(self, name):
+ if name not in User.PROPERTIES:
+ raise NameError()
+
+ if name in ["start", "finish"]:
+ return self.__datetimeGetter(name)
+ elif name in ["format", "output"]:
+ return self.__defaultGetter(name)
+ elif name == "lunch":
+ pass
+
+ def __setattr__(self, name, value):
+ if name not in User.PROPERTIES:
+ raise NameError()
@property
def start(self):