Crossfire Server, Branch 1.12
R12190
|
00001 #loreCollect.py 00002 #To collect lore - endlore contents from Crossfire maps and archetypes file 00003 #temitchell@sympatici.ca for comments/requests 00004 #Python 2.x (never tested on 1.5...) 00005 00006 import sys 00007 import os 00008 import string 00009 00010 def mapLoreCollect(lfile, dir, files): 00011 for file in files: 00012 file = os.path.join(dir,file) 00013 try: 00014 f = open(file,'r') 00015 contents = f.read().split('\n') 00016 match = 0 00017 for line in contents: 00018 if line == 'maplore': 00019 lfile.write("lore\n") 00020 match = 1 00021 elif match == 1 and line == 'lore': 00022 match = 2 00023 elif match == 2 and line == 'endmaplore': 00024 match = 0 00025 break 00026 elif match == 2: 00027 lfile.write('%s\n' %(line)) 00028 else: 00029 pass 00030 f.close() 00031 except (OSError, IOError): 00032 pass 00033 00034 def loreCollect(file, lfile): 00035 try: 00036 f = open(file,'r') 00037 contents = f.read().split('\n') 00038 match = 0 00039 for line in contents: 00040 if line[:5] == 'name ': 00041 tempname = line 00042 match = 1 00043 elif match == 1 and line == 'lore': 00044 match = 2 00045 lfile.write("lore\n%s\n" %tempname) 00046 tempname = 0 00047 elif match == 2 and line == 'endlore': 00048 match = 0 00049 lfile.write("endlore\n") 00050 pass 00051 elif match == 2: 00052 lfile.write('%s\n' %(line)) 00053 else: 00054 pass 00055 f.close() 00056 except (OSError, IOError): 00057 print "Error" 00058 pass 00059 00060 if __name__ == '__main__': 00061 import sys 00062 if len(sys.argv) < 4: 00063 sys.stderr.write ('Collects lore from maps and arches into a single file\nUsage: loreCollect.py <map directory root> <path to archetypes file> <target filename>') 00064 sys.exit() 00065 else: 00066 lfile = open(sys.argv[3],'w') 00067 print "Collecting map lore...this may take a minute" 00068 os.path.walk(sys.argv[1],mapLoreCollect,lfile) 00069 print "Collecting arch lore..." 00070 loreCollect(sys.argv[2],lfile) 00071 lfile.close() 00072 print "finished collecting lore"