1.1 --- a/moinformat/input/directory.py Sat Apr 13 23:26:24 2019 +0200
1.2 +++ b/moinformat/input/directory.py Sun Apr 14 00:01:23 2019 +0200
1.3 @@ -45,7 +45,7 @@
1.4
1.5 self.level_sep = metadata.get("input_separator", sep)
1.6
1.7 - # Search recursively in nested directories for pages and files.
1.8 + # Search recursively in nested directories for pages.
1.9
1.10 self.nested = self.level_sep == sep
1.11
1.12 @@ -65,7 +65,20 @@
1.13
1.14 "Return all attachment filenames in the context."
1.15
1.16 - return self.dir.select_files(join(self.attachments_dir, "*"), self.nested)
1.17 + return self.dir.select_files(join(self.attachments_dir, "*"), True)
1.18 +
1.19 + def get_attachments(self, pagename):
1.20 +
1.21 + """
1.22 + Return all attachment filenames for the given 'pagename'. Each filename
1.23 + is relative to the appropriate attachment directory.
1.24 + """
1.25 +
1.26 + attachments_dir = Directory(join(self.dir.filename,
1.27 + self.attachments_dir,
1.28 + pagename))
1.29 +
1.30 + return attachments_dir.select_files("*")
1.31
1.32 # Page characteristics.
1.33
1.34 @@ -73,8 +86,8 @@
1.35
1.36 "Return the subpage filenames of 'pagename'."
1.37
1.38 - pattern = self.to_filename("%s/*" % pagename)
1.39 - return self.dir.select_files(pattern)
1.40 + pattern = self.to_filename("%s%s*" % (pagename, self.level_sep))
1.41 + return self.dir.select_files(pattern, self.nested)
1.42
1.43 def subpages(self, pagename):
1.44
1.45 @@ -105,11 +118,8 @@
1.46 if not pagename:
1.47 return None
1.48
1.49 - if self.nested:
1.50 - return self.dir.get_filename(join(self.to_filename(pagename),
1.51 - self.attachments_dir, filename))
1.52 - else:
1.53 - return self.dir.get_filename(join(self.attachments_dir, filename))
1.54 + return self.dir.get_filename(join(self.attachments_dir,
1.55 + pagename, filename))
1.56
1.57 # NOTE: Translation methods should encode filenames appropriately.
1.58