Command constructor: default_time optional

This commit is contained in:
Josh Holtrop 2011-01-01 17:51:04 -05:00
parent 67a04df59a
commit 78cb101357
3 changed files with 7 additions and 7 deletions

View File

@ -3,8 +3,11 @@ from datetime import datetime, timedelta
import re import re
class Command: class Command:
def __init__(self, default_time, cmdline): def __init__(self, cmdline, default_time = None):
self.time = default_time if default_time is None:
self.time = datetime.now()
else:
self.time = default_time
self.command = 'start' self.command = 'start'
self.argstr = '' self.argstr = ''
self.parseCommandLine(cmdline) self.parseCommandLine(cmdline)

5
dwtt
View File

@ -3,7 +3,6 @@
import os import os
import sys import sys
import getopt import getopt
from datetime import datetime
from CmdWindow import CmdWindow from CmdWindow import CmdWindow
from Command import Command from Command import Command
@ -24,8 +23,6 @@ def main(argv):
usage() usage()
sys.exit(1) sys.exit(1)
timenow = datetime.now()
for opt, arg in opts: for opt, arg in opts:
if opt == "--help": if opt == "--help":
usage() usage()
@ -41,7 +38,7 @@ def main(argv):
ds = DataStore(timedbfile) ds = DataStore(timedbfile)
cmdline = doCmdWindow() cmdline = doCmdWindow()
cmd = Command(timenow, cmdline) cmd = Command(cmdline)
print "Command:", cmd print "Command:", cmd
def doCmdWindow(): def doCmdWindow():

2
test
View File

@ -10,7 +10,7 @@ def testcmd(cmdline, cmd, argstr):
global n_tests, n_pass global n_tests, n_pass
n_tests += 1 n_tests += 1
print "Testing command line '%s'" % cmdline print "Testing command line '%s'" % cmdline
c = Command(datetime.now(), cmdline) c = Command(cmdline)
if c.command == cmd and c.argstr == argstr: if c.command == cmd and c.argstr == argstr:
n_pass += 1 n_pass += 1
else: else: