summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xperc48
-rw-r--r--perc.cfg4
2 files changed, 38 insertions, 14 deletions
diff --git a/perc b/perc
index 08103cb..d3c9d27 100755
--- a/perc
+++ b/perc
@@ -33,6 +33,8 @@
# - Maintains a list of admins allowed to perform admin actions
# 3.4:
# - Ability to add new users added
+# 3.4.1:
+# - Can now clone (-c/--clone) existing users to create new users (also allows other options in addition such as -s -f to further customise a new user)
import copy
import decimal
@@ -45,7 +47,7 @@ import sys
from datetime import datetime, date, timedelta, time
PROG = "perc"
-VERSION = "3.4"
+VERSION = "3.4.1"
CONFIG_FILE = "perc.cfg"
@@ -442,20 +444,29 @@ class TimeRange(object):
def toDict(self):
return { "start": self._start, "finish": self._finish }
+
+ def __copy__(self):
+ return TimeRange(self._start, self._finish, self.user)
+
+ def __deepcopy__(self, memo):
+ return TimeRange(self._start, self._finish, self.user)
class User(object):
PROPERTIES = ["start", "finish", "format", "output", "lunch"]
- Name = property(fget=lambda self: self._name)
+ Name = property(fget=lambda self: self._name, fset=lambda self, value: setattr(self, "_name", value))
- def __init__(self, name):
+ def __init__(self, name, data=None):
self._name = name.lower()
- try:
- self.data = self.__parseData(CONFIG["DEFAULTS"][name])
- except KeyError:
- self.data = {}
+ if data:
+ self.data = data
+ else:
+ try:
+ self.data = self.__parseData(CONFIG["DEFAULTS"][name])
+ except KeyError:
+ self.data = {}
def __parseData(self, data):
data = copy.deepcopy(data)
@@ -532,6 +543,12 @@ class User(object):
self.__defaultDeleter(name)
else:
super(User, self).__delattr__(name)
+
+ def __copy__(self):
+ return User(copy.copy(self.data))
+
+ def __deepcopy__(self, memo):
+ return User(self.Name, copy.deepcopy(self.data))
def admin(args):
if USER.Name not in CONFIG["ADMINS"]:
@@ -544,6 +561,7 @@ def admin(args):
parser.add_option("-v", "--version", action="store_true", dest="version", help="Display the version of %s" % PROG)
parser.add_option("-a", "--add-event", action="store", dest="add_event", help="Add the named event to {prog} to be used in the usual !{prog} <event_name> way".format(prog=PROG))
parser.add_option("-u", "--user", action="store", dest="user", help="Reference the named user. Used in tandem with -l and -s and -f commands. If only used with -s and/or -f then sets start and finish times of entire day for user. If used with -l and -s and/or -f commands sets the lunch times of that user.")
+ parser.add_option("-c", "--clone", action="store", dest="clone", help="")
parser.add_option("-l", "--lunch", action="store_true", default=False, dest="lunch", help="Indicate that lunch times are to be set.")
parser.add_option("-r", "--remove-event", action="store", dest="remove_event", help="Remove a named event from %s" % PROG)
parser.add_option("-s", "--start", action="store", dest="start", help="Used in conjunction with -a/--add-event option. The start date/time of the event.")
@@ -558,30 +576,36 @@ def admin(args):
sys.exit(0)
if options.user:
- user = User(options.user)
+ user = None
+ if options.clone:
+ user = copy.deepcopy(User(options.clone))
+ user.Name = options.user
+ else:
+ user = User(options.user)
+
if options.lunch:
lunch_start = "13:00"
lunch_finish = "14:00"
-
+
if options.start:
lunch_start, f = parseTime(options.start)
lunch_start = lunch_start.strftime("%H:%M")
if options.finish:
lunch_finish, f = parseTime(options.finish)
lunch_finish = lunch_finish.strftime("%H:%M")
-
+
lunch = TimeRange(lunch_start, lunch_finish, user)
user.lunch = lunch
else:
if options.start:
start, f = parseTime(options.start)
user.start = start.strftime("%H:%M")
-
+
if options.finish:
finish, f = parseTime(options.finish)
user.finish = finish.strftime("%H:%M")
-
+
if options.format:
user.format = options.format
if options.output:
diff --git a/perc.cfg b/perc.cfg
index 586680a..f5a9b8c 100644
--- a/perc.cfg
+++ b/perc.cfg
@@ -5,8 +5,8 @@
"hyphens": "%d-%m-%Y"
},
"time": {
- "military": "%H%M",
"12hour": "%I:%M%p",
+ "military": "%H%M",
"12houronly": "%I%p",
"civilian": "%H:%M"
}
@@ -49,7 +49,7 @@
"finish": "14:00"
},
"format": "%I%p"
- },
+ },
"wjoe": {
"start": "09:00",
"finish": "17:00",