# HG changeset patch # User Paul Boddie # Date 1555017236 -7200 # Node ID 18182c6682d63fdd000d6f794c24590dd403cb98 # Parent 3f8ff30eefc074c05e8248de0b24e991789d7d8c Prevent recursive searching for pages in a flat page archive. diff -r 3f8ff30eefc0 -r 18182c6682d6 moinformat/input/directory.py --- a/moinformat/input/directory.py Thu Apr 11 22:54:17 2019 +0200 +++ b/moinformat/input/directory.py Thu Apr 11 23:13:56 2019 +0200 @@ -3,7 +3,7 @@ """ Directory input context. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -49,9 +49,11 @@ "Return all pages in the context." + nested = self.level_sep == sep + # Ignore dotfiles. - return map(self.to_pagename, self.dir.select_files("[!.]*")) + return map(self.to_pagename, self.dir.select_files("[!.]*", nested)) # Page characteristics. @@ -59,8 +61,9 @@ "Return the subpage filenames of 'pagename'." + nested = self.level_sep == sep pattern = self.to_filename("%s/*" % pagename) - return self.dir.select_files(pattern) + return self.dir.select_files(pattern, nested) def subpages(self, pagename): diff -r 3f8ff30eefc0 -r 18182c6682d6 moinformat/utils/directory.py --- a/moinformat/utils/directory.py Thu Apr 11 22:54:17 2019 +0200 +++ b/moinformat/utils/directory.py Thu Apr 11 23:13:56 2019 +0200 @@ -3,7 +3,7 @@ """ Directory context functionality. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -132,11 +132,12 @@ rename(self.get_filename(old), self.get_filename(new)) - def select_files(self, pattern): + def select_files(self, pattern, recursive=False): """ Return a list of filenames found within the directory matching - 'pattern'. These filenames are relative to the directory. + 'pattern'. These filenames are relative to the directory. If 'recursive' + is specified and is a true value, subdirectories are also searched. """ selected = [] @@ -144,6 +145,9 @@ # Obtain pathnames, directory names and filenames within the directory. for dirpath, dirnames, filenames in walk(self.filename): + if not recursive and dirpath != self.filename: + continue + for filename in filenames: # Qualify filenames with the directory path.