-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
119 lines (92 loc) · 3.18 KB
/
setup.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
118
119
from distutils.core import setup, Command
from distutils.spawn import find_executable, spawn
from zipfile import ZipFile
import os
import re
#
# where to write target files
#
target_dir = 'target'
#
#
#
platforms = 'win', 'mac', 'linux'
#platforms = 'win',
#
# find the executables to use in compiling the books
#
latex = find_executable('latex')
makeindex = find_executable('makeindex')
dvipdf = find_executable('dvipdf')
#
# Get the book version
#
s = open('frontmatter.tex').read()
mat = re.compile(r'Version\s*(.*)').search(s)
version = mat.group(1)
if not os.path.exists(target_dir):
os.mkdir(target_dir)
class CleanCommand(Command):
user_options = [ ]
def initialize_options(self):
self._clean_me = [ ]
for root, dirs, files in os.walk(target_dir):
for f in files:
self._clean_me.append(os.path.join(root, f))
def finalize_options(self):
pass
def run(self):
for clean_me in self._clean_me:
try:
os.unlink(clean_me)
except:
pass
class LatexCommand(Command):
user_options = [ ('cover=', 'c', 'include the cover in the output') ]
def initialize_options(self):
self.cover = 'include'
def finalize_options(self):
pass
def run(self):
for platform in platforms:
s = open('swfk.tex.pre').read()
if self.cover == 'include':
s = s.replace('@FRONTCOVER_INC@', 'include')
fname_suffix = ''
else:
s = s.replace('@FRONTCOVER_INC@', 'exclude')
fname_suffix = '-nc'
if platform == 'win':
s = s.replace('@WINDOWS_INC@', 'include')
s = s.replace('@MAC_INC@', 'exclude')
s = s.replace('@LINUX_INC@', 'exclude')
elif platform == 'mac':
s = s.replace('@WINDOWS_INC@', 'exclude')
s = s.replace('@MAC_INC@', 'include')
s = s.replace('@LINUX_INC@', 'exclude')
elif platform == 'linux':
s = s.replace('@WINDOWS_INC@', 'exclude')
s = s.replace('@MAC_INC@', 'exclude')
s = s.replace('@LINUX_INC@', 'include')
else:
raise RuntimeError('unrecognised platform %s' % platform)
swfk_tex = open('swfk.tex', 'w')
swfk_tex.write(s)
swfk_tex.close()
tex = 'swfk.tex'
spawn([latex, '--output-directory=%s' % target_dir, tex])
spawn([makeindex, '%s/swfk.idx' % target_dir])
spawn([latex, '--output-directory=%s' % target_dir, tex])
pdf = '%s/swfk-%s-%s%s.pdf' % (target_dir, platform, version, fname_suffix)
spawn([dvipdf, '%s/swfk.dvi' % target_dir, pdf])
zf = ZipFile('%s/swfk-%s-%s%s.zip' % (target_dir, platform, version, fname_suffix), 'w')
zf.write(pdf)
zf.close()
setup(
name = 'SWFK',
version = '1.00',
description = 'Snake Wrangling For Kids',
author = 'Jason R Briggs',
author_email = 'jason@briggs.net.nz',
cmdclass = { 'clean': CleanCommand, 'build' : LatexCommand }
)