wmltools: split campaigns/add-ons into separate subtrees for wmlscope
The problem: wmlscope assigns each file to a directory-based subtree, and assumes that it is visible to every other file in that subtree. The intent is that each campaign (or add-on of another type) will be in its own subtree. However, wmlscope/wmltools has derived these subtrees based on what arguments get passed to wmlscope, rather than checking whether campaigns have actually been split out. For instance, invoking wmlscope with "../data/core ../data/campaigns <userdata>/data/add-ons" will cause wmlscope to see three subtrees, one of which consists of all mainline campaigns and another that includes all the user's add-ons. This leads to many spurious "more than one definition/resource is visible here" errors. A wildcard like "data/campaigns/*" would be expanded to all the individual campaign directories. However, the wmlscope user might not know that they should do that. Also, until the glob module was imported recently, globbing did not work in the Windows cmd shell. The solution: declare "campaigns" and "add-ons" to be roots, and check for their presence in the directory names. If indicated, split out the subdirectories into their own subtrees. Since it is possible that the user may have moved, copied, or drafted campaigns/add-ons to another folder that isn't following Wesnoth convention, also check for that.
This commit is contained in:
parent
c6b4e13456
commit
956fa83677
1 changed files with 42 additions and 3 deletions
|
@ -77,12 +77,51 @@ class Forest:
|
|||
"Get the names of all files under dirpath, ignoring version-control directories."
|
||||
self.forest = []
|
||||
self.dirpath = dirpath
|
||||
roots = ["campaigns", "add-ons"]
|
||||
for dir in dirpath:
|
||||
subtree = []
|
||||
rooted = False
|
||||
if os.path.isdir(dir): # So we skip .cfgs in a UMC mirror
|
||||
os.path.walk(dir,
|
||||
lambda arg, dir, names: subtree.extend([os.path.normpath(os.path.join(dir, x)) for x in names]),
|
||||
None)
|
||||
oldmain = os.path.join(os.path.dirname(dir), os.path.basename(dir) + '.cfg')
|
||||
if os.path.isfile(oldmain):
|
||||
subtree.append(oldmain)
|
||||
base = os.path.basename(os.path.dirname(os.path.abspath(dir)))
|
||||
if base in roots or base == "core":
|
||||
rooted = True
|
||||
for root, dirs, files in os.walk(dir):
|
||||
dirs.sort()
|
||||
dirlist = [x for x in dirs]
|
||||
# Split out individual campaigns/add-ons into their own subtrees
|
||||
if not rooted:
|
||||
if os.path.basename(root) == "core":
|
||||
rooted = True
|
||||
elif os.path.basename(root) in roots:
|
||||
for subdir in dirlist:
|
||||
if subdir + '.cfg' in files:
|
||||
files.remove(subdir + '.cfg')
|
||||
dirs.remove(subdir)
|
||||
dirpath.append(os.path.join(root, subdir))
|
||||
rooted = True
|
||||
elif "_info.cfg" in files or "info.cfg" in files:
|
||||
rooted = True
|
||||
roots.append(os.path.basename(os.path.dirname(os.path.abspath(root))))
|
||||
else:
|
||||
stop = min(len(dirs), 5)
|
||||
count = 0
|
||||
for subdir in dirlist[:stop]:
|
||||
if os.path.isfile(os.path.join(root, subdir, '_info.cfg')):
|
||||
count += 1
|
||||
elif os.path.isfile(os.path.join(root, subdir, 'info.cfg')):
|
||||
if os.path.isfile(os.path.join(root, subdir, 'COPYING.txt')):
|
||||
count += 1
|
||||
if count >= (stop / 2):
|
||||
roots.append(os.path.basename(root))
|
||||
for subdir in dirlist:
|
||||
if subdir + '.cfg' in files:
|
||||
files.remove(subdir + '.cfg')
|
||||
dirs.remove(subdir)
|
||||
dirpath.append(os.path.join(root, subdir))
|
||||
subtree.extend([os.path.normpath(os.path.join(root, x)) for x in files])
|
||||
# Always look at _main.cfg first
|
||||
subtree.sort(lambda x, y: cmp(x, y) - 2*int(x.endswith("_main.cfg")) + 2*int(y.endswith("_main.cfg")))
|
||||
self.forest.append(subtree)
|
||||
|
|
Loading…
Add table
Reference in a new issue