Crossfire Server, Trunk
loreCollect.py
Go to the documentation of this file.
1
#loreCollect.py
2
#To collect lore - endlore contents from Crossfire maps and archetypes file
3
#temitchell@sympatici.ca for comments/requests
4
#Python 2.x (never tested on 1.5...)
5
6
import
sys
7
import
os
8
import
string
9
10
def
mapLoreCollect
(lfile, dir, files):
11
for
file
in
files:
12
file = os.path.join(dir,file)
13
try
:
14
f =
open
(file,
'r'
)
15
contents = f.read().
split
(
'\n'
)
16
match = 0
17
for
line
in
contents:
18
if
line ==
'maplore'
:
19
lfile.write(
"lore\n"
)
20
match = 1
21
elif
match == 1
and
line ==
'lore'
:
22
match = 2
23
elif
match == 2
and
line ==
'endmaplore'
:
24
match = 0
25
break
26
elif
match == 2:
27
lfile.write(
'%s\n'
%(line))
28
else
:
29
pass
30
f.close()
31
except
(OSError, IOError):
32
pass
33
34
def
loreCollect
(file, lfile):
35
try
:
36
f =
open
(file,
'r'
)
37
contents = f.read().
split
(
'\n'
)
38
match = 0
39
for
line
in
contents:
40
if
line[:5] ==
'name '
:
41
tempname = line
42
match = 1
43
elif
match == 1
and
line ==
'lore'
:
44
match = 2
45
lfile.write(
"lore\n%s\n"
%tempname)
46
tempname = 0
47
elif
match == 2
and
line ==
'endlore'
:
48
match = 0
49
lfile.write(
"endlore\n"
)
50
pass
51
elif
match == 2:
52
lfile.write(
'%s\n'
%(line))
53
else
:
54
pass
55
f.close()
56
except
(OSError, IOError):
57
print
"Error"
58
pass
59
60
if
__name__ ==
'__main__'
:
61
import
sys
62
if
len(sys.argv) < 4:
63
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>'
)
64
sys.exit()
65
else
:
66
lfile =
open
(sys.argv[3],
'w'
)
67
print
"Collecting map lore...this may take a minute"
68
os.path.walk(sys.argv[1],mapLoreCollect,lfile)
69
print
"Collecting arch lore..."
70
loreCollect
(sys.argv[2],lfile)
71
lfile.close()
72
print
"finished collecting lore"
CFBank.open
def open()
Definition:
CFBank.py:70
loreCollect.loreCollect
def loreCollect(file, lfile)
Definition:
loreCollect.py:34
loreCollect
Definition:
loreCollect.py:1
loreCollect.mapLoreCollect
def mapLoreCollect(lfile, dir, files)
Definition:
loreCollect.py:10
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition:
mapper.cpp:2605
crossfire-crossfire-server
utils
loreCollect.py
Generated by
1.8.17