summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <stefanbeller@googlemail.com>2011-01-30 12:05:01 +0100
committerStefan Beller <stefanbeller@googlemail.com>2011-01-30 12:06:32 +0100
commitc7a427e1754ac9ed7f2f229605cd4fd5c7500e4c (patch)
treeb6d61a5c891eaecf170f9ef330a9870878aba02d
parent7c66053e0275797f9fa99c81ccdb10e388da3cb0 (diff)
downloadtools-c7a427e1754ac9ed7f2f229605cd4fd5c7500e4c.tar.gz
tools-c7a427e1754ac9ed7f2f229605cd4fd5c7500e4c.tar.bz2
tools-c7a427e1754ac9ed7f2f229605cd4fd5c7500e4c.tar.xz
tools-c7a427e1754ac9ed7f2f229605cd4fd5c7500e4c.zip
improving the showvars script
-rwxr-xr-xshowvars.py61
1 files changed, 43 insertions, 18 deletions
diff --git a/showvars.py b/showvars.py
index 4b3d0cb..94ab333 100755
--- a/showvars.py
+++ b/showvars.py
@@ -16,6 +16,7 @@ def handleFile(fname):
f = open(fname)
lines = f.readlines();
f.close()
+ rm=[]
for l in lines:
#remove comments
line = l.split(r"//")[0]
@@ -39,43 +40,67 @@ def handleFile(fname):
if endpos>0:
#ok its a oneliner, the comma is in the same line:
varname = line[0:endpos].strip()
- if varname.startswith("@"):
- continue
- if varname.startswith("$"):
- continue
- if varname in allvars:
- if not fname in allvars[varname]:
- allvars[varname] += [fname]
+ assignment = line[endpos+1:].strip()[:-1] # remove semicolon
+ if assignment != "0":
+ if varname.startswith("@"):
+ continue
+ if varname.startswith("$"):
+ continue
+ if varname in allvars:
+ if not fname in allvars[varname]:
+ allvars[varname] += [fname]
+ else:
+ allvars[varname] = [fname]
else:
- allvars[varname] = [fname]
+ #print fname
+ if fname == "." + os.sep + "functions" + os.sep + "clear_vars.txt":
+ rm += [varname]
+
else:
# ok error, you need to check manually:
print "\tline:\t",line
+ return rm
allvars = {}
-
+rmvars = []
print "please check manully for vars in here:"
os.chdir(".."+os.sep+"npc")
+
for tpl in os.walk("."):
for fname in tpl[2]:
- handleFile(tpl[0]+os.sep+fname)
+ rmvars += handleFile(tpl[0]+os.sep+fname)
# now check if the variable is not in npc/functions/clear_vars.txt, if so remove it
-checkstring = "." + os.sep + "functions" + os.sep + "clear_vars.txt"
-rm = []
+#~ checkstring = "." + os.sep + "functions" + os.sep + "clear_vars.txt"
+#~ rm = []
+#~ for var in allvars:
+ #~ if checkstring in allvars[var]:
+ #~ rm += [var]
+
+unusedcounter=0
+usedcounter=0
+print "These variables are found in the scripts, which are deleted in clear_vars"
for var in allvars:
- if checkstring in allvars[var]:
- rm += [var]
+ if not var in rmvars:
+ continue
+
+ unusedcounter+=1
+ print "\t",var
+ if options.verbose:
+ for fname in allvars[var]:
+ print "\t","\t", fname
-#now really remove these vars
-for var in rm:
- del allvars[var]
print "These variables are valid variables of the scripts:"
for var in allvars:
+ if var in rmvars:
+ continue
+
+ usedcounter+=1
print "\t",var
if options.verbose:
for fname in allvars[var]:
print "\t","\t", fname
-print "number of vars:", len(allvars)
+print "number of vars used:", usedcounter
+print "number of vars cleared:", unusedcounter