Skip to content

Commit

Permalink
wmltools: split campaigns/add-ons into separate subtrees for wmlscope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
groggyd88 committed Aug 14, 2014
1 parent c6b4e13 commit 956fa83
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions data/tools/wesnoth/wmltools.py
Expand Up @@ -77,12 +77,51 @@ def __init__(self, dirpath, exclude=None):
"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)
Expand Down

0 comments on commit 956fa83

Please sign in to comment.