/
packres.py
executable file
·117 lines (99 loc) · 3.88 KB
/
packres.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python2.7
# This Python script will create a set of PK3 files that contain the files
# that Doomsday needs at runtime. The PK3 files are organized using the
# traditional data/ and defs/ structure.
import sys, os, os.path, zipfile
if len(sys.argv) < 2:
print "Usage: %s pk3-target-dir" % sys.argv[0]
print "(run in build/scripts/)"
sys.exit(0)
# Check quiet flag.
quietMode = False
if '--quiet' in sys.argv:
sys.argv.remove('--quiet')
quietMode = True
deng_dir = os.path.join('..', '..')
target_dir = os.path.abspath(sys.argv[1])
class Pack:
def __init__(self):
self.files = [] # tuples
def add_files(self, fileNamesArray):
self.files += fileNamesArray
def msg(self, text):
if not quietMode: print text
def create(self, name):
full_name = os.path.join(target_dir, name)
self.msg("Creating %s as %s..." % (os.path.normpath(name), os.path.normpath(full_name)))
pk3 = zipfile.ZipFile(full_name, 'w', zipfile.ZIP_DEFLATED)
for src, dest in self.files:
full_src = os.path.join(deng_dir, src)
# Is this a file or a folder?
if os.path.isfile(full_src):
# Write the file as is.
self.msg("writing %s as %s" % (os.path.normpath(full_src), os.path.normpath(dest)))
pk3.write(full_src, dest)
elif os.path.isdir(full_src):
# Write the contents of the folder recursively.
def process_dir(path, dest_path):
self.msg("processing %s" % os.path.normpath(path))
for file in os.listdir(path):
real_file = os.path.join(path, file)
if file[0] == '.':
continue # Ignore these.
if os.path.isfile(real_file):
if not quietMode:
self.msg("writing %s as %s" % (os.path.normpath(real_file),
os.path.normpath(os.path.join(dest_path, file))))
pk3.write(real_file, os.path.join(dest_path, file))
elif os.path.isdir(real_file):
process_dir(real_file,
os.path.join(dest_path, file))
process_dir(full_src, dest)
# Write it out.
print "Created %s (with %i files)." % (os.path.normpath(full_name), len(pk3.namelist()))
pk3.close()
# First up, doomsday.pk3.
# Directory contents added recursively.
p = Pack()
p.add_files(
[ ('client/defs', 'defs'),
('client/data', 'data') ] )
p.create('doomsday.pk3')
# defaultstyle.pack
p = Pack()
p.add_files(
[ ('client/data/defaultstyle.pack', '') ] )
p.create('defaultstyle.pack')
# renderer.pack
p = Pack()
p.add_files(
[ ('client/data/renderer.pack', '') ] )
p.create('renderer.pack')
# libdoom.pk3
p = Pack()
p.add_files(
[ ('plugins/doom/defs', 'defs/jdoom'),
('plugins/doom/data/conhelp.txt', 'data/jdoom/conhelp.txt'),
('plugins/doom/data/lumps', '#.basedata') ] )
p.create('libdoom.pk3')
# libheretic.pk3
p = Pack()
p.add_files(
[ ('plugins/heretic/defs', 'defs/jheretic'),
('plugins/heretic/data/conhelp.txt', 'data/jheretic/conhelp.txt'),
('plugins/heretic/data/lumps', '#.basedata') ] )
p.create('libheretic.pk3')
# libhexen.pk3
p = Pack()
p.add_files(
[ ('plugins/hexen/defs', 'defs/jhexen'),
('plugins/hexen/data/conhelp.txt', 'data/jhexen/conhelp.txt'),
('plugins/hexen/data/lumps', '#.basedata') ] )
p.create('libhexen.pk3')
# libdoom64.pk3
p = Pack()
p.add_files(
[ ('plugins/doom64/defs', 'defs/jdoom64'),
('plugins/doom64/data/conhelp.txt', 'data/jdoom64/conhelp.txt'),
('plugins/doom64/data/lumps', '#.basedata') ] )
p.create('libdoom64.pk3')