import os, sys, re PATH=r"C:\Programme\L2j Server\jscript" TYPES={'q':'quests','b':'blacksmith','v':'village_master','t':'teleports','c':'custom'} j=os.path.join log=open("log.log", "w") sys.stdout=log for abbr, full in TYPES.iteritems(): print "\n", full, "\n*************" path=j(PATH, full) files=os.listdir(path) init=open(j(path, "__init__.py"), "r") all=init.read() init.close() for dir in files: fulldir=j(path, dir) if os.path.isdir(fulldir) and dir[0].isdigit(): changed=0 allfiles=os.listdir(fulldir) for file in allfiles: fullfile=j(fulldir, file) if os.path.isfile(fullfile) and (os.path.splitext(file)[1]==".htm" or file=="__init__.py"): f=open(fullfile, "r") script=f.read() f.close() count=script.count(dir) if count: script=script.replace(dir, abbr+dir) if file=='__init__.py': regex=re.compile('Quest\s*\(\s*\d+\s*,\s*"%s"' % (abbr+dir)) if regex.search(script): changed=1 else: print "WARNING: new Quest regex wasn't found in %s" % fullfile elif file=="__init__.py": print "WARNING: %s found %s times in %s" % (dir, count, fullfile) f=open(fullfile, "w") f.write(script) f.close() if changed: os.rename(fulldir, j(path, abbr+dir)) all=all.replace(dir, abbr+dir) init=open(j(path, "__init__.py"), "w") init.write(all) init.close() print "completed", full log.close()