Commit 77b7d76f authored by Laurent Bachelier's avatar Laurent Bachelier

Centralize calls to os.getcwd()

The goal is to be able to change the working directory in a single
parent b87d3f6d
......@@ -21,9 +21,12 @@ import argparse
from ass2m import Ass2m
class CLI(object):
def __init__(self):
def __init__(self, working_dir=None):
if working_dir is None:
working_dir = os.getcwd()
self.working_dir = working_dir
self.parser = argparse.ArgumentParser(prog='ass2m')
self.ass2m = Ass2m(os.getcwd(), parser=self.parser)
self.ass2m = Ass2m(self.working_dir, parser=self.parser)
self.parser.add_argument('-V', '--version', action='version',
version='%(prog)s ' + self.ass2m.VERSION +
' ' + self.ass2m.COPYRIGHT)
......@@ -32,7 +35,7 @@ class CLI(object):
# TODO use cmd.Cmd to have a REPL application when no command
# is supplied.
args = self.parser.parse_args(argv[1:])
cmd = args.cmd(self.ass2m)
cmd = args.cmd(self.ass2m, self.working_dir)
except KeyboardInterrupt:
......@@ -98,8 +98,9 @@ class Command(ConsolePart):
def configure_parser(parser):
def __init__(self, ass2m):
def __init__(self, ass2m, working_dir):
self.ass2m = ass2m
self.working_dir = working_dir
def run(self, args):
if self.WORKDIR and not
......@@ -32,10 +32,10 @@ class InitCmd(Command):
def cmd(self, args):
print >>sys.stderr, 'Error: %s is already a working directory' % os.getcwd()
print >>sys.stderr, 'Error: %s is already a working directory' % self.working_dir
return 1
print 'Ass2m working directory created.'
class TreeCmd(Command):
......@@ -43,7 +43,7 @@ class TreeCmd(Command):
def cmd(self, args):
for root, directories, files in os.walk(os.getcwd()):
for root, directories, files in os.walk(self.working_dir):
path = root[len(self.ass2m.root):]
depth = path.count('/')
f =
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment