Author: esr
Date: Thu May  3 09:21:46 2007
New Revision: 17279

URL: http://svn.gna.org/viewcvs/wesnoth?rev=17279&view=rev
Log:
Refactoring step.

Modified:
    trunk/data/tools/upconvert

Modified: trunk/data/tools/upconvert
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/upconvert?rev=17279&r1=17278&r2=17279&view=diff
==============================================================================
--- trunk/data/tools/upconvert (original)
+++ trunk/data/tools/upconvert Thu May  3 09:21:46 2007
@@ -25,6 +25,10 @@
 # This script will barf on maps with custom terrains.
 
 import sys, os, re, getopt, curses.ascii
+
+def vcdir(filename):
+    "Predicate that tells us to ignore a file if it's part of the VCS state."
+    return ".svn" in filename  # Change if we move away from  Subversion
 
 filemoves = {
     # Older includes all previous to 1.3.1.
@@ -288,31 +292,29 @@
     "~" : "_f",
 }
 max_len = max(*map(len, conversion1.values()))
-
-def get_adjacent(x, y, map):
-    "Returns string of original location+adjacent locations on hex 1-char map"
+width = max_len+2
+
+def neighborhood(x, y, map):
+    "Returns list of original location+adjacent locations from a hex map"
     odd = (x) % 2
-    adj = map[y][x];
+    adj = [map[y][x]];
     if x > 0:
-       adj += map[y][x-1]
+       adj.append(map[y][x-1])
     if x < len(map[y])-1:
-       adj += map[y][x+1]
+       adj.append(map[y][x+1])
     if y > 0:
-       adj += map[y-1][x]
+       adj.append(map[y-1][x])
     if y < len(map)-1:
-       adj += map[y+1][x]
+       adj.append(map[y+1][x])
     if x > 0 and y > 0 and not odd:
-       adj += map[y-1][x-1]
+       adj.append(map[y-1][x-1])
     if x < len(map[y])-1 and y > 0 and not odd:
-       adj += map[y-1][x+1];
+       adj.append(map[y-1][x+1])
     if x > 0 and y < len(map)-1 and odd:
-       adj += map[y+1][x-1]
+       adj.append(map[y+1][x-1])
     if x < len(map[y])-1 and y < len(map)-1 and odd:
-       adj += map[y+1][x+1]
-    adj = adj.replace("\n", "").replace("\r", "")
+       adj.append(map[y+1][x+1])
     return adj
-
-width = max_len+2
 
 def maptransform1(input, baseline, inmap, y):
     "Transform a map line from 1.2.x to 1.3.x format."
@@ -335,7 +337,9 @@
             sys.exit(1)
         if "_K" in ohex:
             # Convert keeps according to adjacent hexes
-            adj = get_adjacent(x, y, inmap)
+            adj = neighborhood(x, y, inmap)
+            adj = "".join(adj).replace("\n", "").replace("\r", "")
+
             # print "adjacent: %s" % adj
             hexcount = {}
             for i in range(1, len(adj)):
@@ -509,18 +513,28 @@
     else:
         return None
 
-ignore = (".tgz", ".png", ".jpg")
+ignore = (".tgz", ".png", ".jpg", "-bak")
+
+def interesting(fn):
+    "Is a file interesting for conversion purposes?"
+    return fn.endswith(".cfg") or fn.endswith(".map") \
+        or ("maps" in fn and fn[-4:] not in ignore)
 
 def allcfgfiles(dir):
-    "Get the names of all .cfg and map files under dir, ignoring .svn 
directories."
+    "Get the names of all interesting files under dir."
     datafiles = []
-    os.path.walk(dir,
-                 lambda arg, dir, names: datafiles.extend(map(lambda x: 
os.path.normpath(os.path.join(dir, x)), names)),
-                 None)
-    datafiles = filter(lambda x: ".svn" not in x, datafiles)
-    datafiles = filter(lambda x: x.endswith(".cfg") or ('maps' in x and 
os.path.isfile(x) and x[-4:] not in ignore), datafiles)
-    datafiles = filter(lambda x: not x.endswith("-bak"), datafiles)
-    datafiles.sort()   # So changes and diffs for the same campaigns will 
cluster in the report
+    if not os.path.isdir(dir):
+        if interesting(dir):
+            datafiles.append(dir)
+    else:
+        for root, dirs, files in os.walk(dir):
+            if vcdir(dirs):
+                dirs.remove(dirs)
+            for name in files:
+                if interesting(os.path.join(root, name)):
+                    datafiles.append(os.path.join(root, name))
+    print datafiles
+    datafiles.sort()   # So diffs for same campaigns will cluster in reports
     return datafiles
 
 def help():


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to