1.1 --- a/moinformat/output/directory.py Mon Jul 30 01:03:50 2018 +0200
1.2 +++ b/moinformat/output/directory.py Mon Jul 30 17:18:52 2018 +0200
1.3 @@ -20,41 +20,24 @@
1.4 """
1.5
1.6 from moinformat.output.common import Output
1.7 -from os.path import abspath, commonprefix, join
1.8 -
1.9 -def inside(filename, dirname):
1.10 -
1.11 - "Return whether 'filename' is inside 'dirname'."
1.12 +from moinformat.utils.directory import Directory
1.13
1.14 - # Get the directory with trailing path separator.
1.15 -
1.16 - dirname = join(dirname, "")
1.17 - return commonprefix((filename, dirname)) == dirname
1.18 -
1.19 -
1.20 -
1.21 -class DirectoryOutput(Output):
1.22 +class DirectoryOutput(Output, Directory):
1.23
1.24 "A directory output context."
1.25
1.26 - def __init__(self, filename):
1.27 -
1.28 - "Initialise the context with the given 'filename'."
1.29 + name = "directory"
1.30
1.31 - Output.__init__(self)
1.32 - self.filename = abspath(filename)
1.33 + def __init__(self, parameters=None):
1.34
1.35 - def get_filename(self, filename):
1.36 + "Initialise the context with the given 'parameters'."
1.37
1.38 - "Return a file with the given 'filename' within the directory."
1.39 -
1.40 - # Get the absolute path for the combination of directory and filename.
1.41 + if not parameters or not parameters.has_key("filename"):
1.42 + raise ValueError, parameters
1.43
1.44 - pathname = abspath(join(self.filename, filename))
1.45 + Output.__init__(self, parameters)
1.46 + Directory.__init__(self, parameters["filename"])
1.47
1.48 - if inside(pathname, self.filename):
1.49 - return pathname
1.50 - else:
1.51 - raise ValueError, filename
1.52 +output = DirectoryOutput
1.53
1.54 # vim: tabstop=4 expandtab shiftwidth=4