Permalink
Browse files

Finished options refactor.

  • Loading branch information...
1 parent 28d2482 commit 960482827259034749146423a1e3381cc3e93690 @jejansse jejansse committed Feb 14, 2012
Showing with 25 additions and 13 deletions.
  1. +10 −0 dumbo/cmd.py
  2. +1 −1 dumbo/core.py
  3. +5 −3 dumbo/util.py
  4. +9 −9 tests/testexamples.py
View
@@ -68,12 +68,15 @@ def start(prog,
opts,
stdout=sys.stdout,
stderr=sys.stderr):
+
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('start'))
pyenv = envdef('PYTHONPATH', opts['libegg'],
shortcuts=dict(configopts('eggs', prog)),
extrapaths=sys.path)
+
if not opts['prog']:
opts.add('prog', prog)
@@ -82,6 +85,7 @@ def start(prog,
print >> sys.stderr, 'ERROR:', prog, 'does not exist'
return 1
prog = '-m ' + prog
+
return execute("%s %s" % (sys.executable, prog),
opts,
pyenv,
@@ -91,36 +95,42 @@ def start(prog,
def cat(path, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('cat'))
return create_filesystem(opts).cat(path, opts)
def ls(path, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('ls'))
return create_filesystem(opts).ls(path, opts)
def exists(path, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('exists'))
return create_filesystem(opts).exists(path, opts)
def rm(path, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('rm'))
return create_filesystem(opts).rm(path, opts)
def put(path1, path2, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('put'))
return create_filesystem(opts).put(path1, path2, opts)
def get(path1, path2, opts):
+ opts = Options(opts)
opts += Options(configopts('common'))
opts += Options(configopts('get'))
return create_filesystem(opts).get(path1, path2, opts)
View
@@ -361,7 +361,7 @@ def run(mapper,
for output in dumpcode(inputs):
print '\t'.join(output)
else:
- opts = opts or Options()
+ opts = Options(opts)
if type(mapper) == str:
opts.add('mapper', mapper)
elif hasattr(mapper, 'opts'):
View
@@ -81,8 +81,8 @@ def loadtext(inputs):
class Options(object):
"""
- Class that represent a a set of options. A key can hold
- more than a value and key are stored in lowercase.
+ Class that represents a set of options. A key can hold
+ more than one value and keys are stored in lowercase.
"""
def __init__(self, seq=None, **kwargs):
@@ -93,7 +93,9 @@ def __init__(self, seq=None, **kwargs):
- seq: a list of (key, value) pairs
"""
self._opts = defaultdict(set)
- options = (seq or []) + kwargs.items()
+ options = seq or []
+ for k, v in kwargs.iteritems():
+ self.add(k, v)
for k, v in options:
self.add(k, v)
View
@@ -27,7 +27,7 @@ def tearDown(self):
def testwordcount(self):
opts = self.common_opts
- opts += Options([('input', self.exdir+'brian.txt'), ('output', self.outfile)])
+ opts += [('input', self.exdir+'brian.txt'), ('output', self.outfile)]
retval = cmd.start(self.exdir+'wordcount.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEqual(0, retval)
@@ -36,8 +36,8 @@ def testwordcount(self):
def testoowordcount(self):
opts = self.common_opts
- opts += Options([('excludes', self.exdir+'excludes.txt'),
- ('input', self.exdir+'brian.txt'), ('output', self.outfile)])
+ opts += [('excludes', self.exdir+'excludes.txt'),
+ ('input', self.exdir+'brian.txt'), ('output', self.outfile)]
retval = cmd.start(self.exdir+'oowordcount.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEquals(0, retval)
@@ -46,7 +46,7 @@ def testoowordcount(self):
def testaltwordcount(self):
opts = self.common_opts
- opts += Options([('input', self.exdir+'brian.txt'), ('output', self.outfile)])
+ opts += [('input', self.exdir+'brian.txt'), ('output', self.outfile)]
retval = cmd.start(self.exdir+'altwordcount.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEqual(0, retval)
@@ -55,7 +55,7 @@ def testaltwordcount(self):
def testitertwice(self):
opts = self.common_opts
- opts += Options([('input', self.exdir+'brian.txt'), ('output', self.outfile)])
+ opts += [('input', self.exdir+'brian.txt'), ('output', self.outfile)]
retval = cmd.start(self.exdir+'itertwice.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEqual(0, retval)
@@ -64,9 +64,9 @@ def testitertwice(self):
def testjoin(self):
opts = self.common_opts
- opts += Options([('input', self.exdir+'hostnames.txt'),
+ opts += [('input', self.exdir+'hostnames.txt'),
('input', self.exdir+'logs.txt'),
- ('output', self.outfile)])
+ ('output', self.outfile)]
retval = cmd.start(self.exdir+'join.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEqual(0, retval)
@@ -75,9 +75,9 @@ def testjoin(self):
def testmulticount(self):
opts = self.common_opts
- opts += Options([('input', self.exdir+'brian.txt'),
+ opts += [('input', self.exdir+'brian.txt'),
('input', self.exdir+'eno.txt'),
- ('output', self.outfile)])
+ ('output', self.outfile)]
retval = cmd.start(self.exdir+'multicount.py', opts,
stdout=self.logfile, stderr=self.logfile)
self.assertEqual(0, retval)

0 comments on commit 9604828

Please sign in to comment.