-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_single_script.py
executable file
·93 lines (70 loc) · 3.1 KB
/
make_single_script.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
#!/usr/bin/env python3
# python 3.6+
# Collect all source and data files into single stand-alone sympad.py script file.
import io
import os
_TEXT_FILES = ('style.css', 'script.js', 'index.html', 'help.html')
_BIN_FILES = ('bg.png', 'wait.webp')
_PY_FILES = ('lalr1.py', 'sast.py', 'sxlat.py', 'sym.py', 'sparser.py', 'spatch.py', 'splot.py', 'server.py')
_HEADER = '''
#!/usr/bin/env python3
# python 3.6+
# THIS SCRIPT WAS AUTOGENERATED FROM SOURCE FILES FOUND AT:
# https://github.com/Pristine-Cat/SymPad
# Copyright (c) 2019 Tomasz Pytel
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
_RUNNING_AS_SINGLE_SCRIPT = True
import sys
sys.path.insert (0, '') # allow importing from current directory first (for SymPy development version)
'''.lstrip ()
if __name__ == '__main__':
fdout = io.StringIO ()
fdout.write (_HEADER)
fdout.write ('\n_FILES = {\n')
for fnm in _TEXT_FILES:
fdout.write (f'''\n\t'{fnm}': # {fnm}\n\nr"""''')
for line in open (fnm, encoding="utf8"):
fdout.write (line)
fdout.write ('""".encode ("utf8"),\n')
for fnm in _BIN_FILES:
fdout.write (f"\n\t'{fnm}': # {fnm}\n\n")
data = open (fnm, 'rb').read ()
for i in range (0, len (data), 64):
fdout.write (f"\t\t{data [i : i + 64]!r}{',' if i + 64 >= len (data) else ''}\n")
fdout.write ('}\n\n')
for fnm in _PY_FILES:
writing = True
for line in open (fnm):
liner = line.rstrip ()
if writing:
if not liner.endswith ('# AUTO_REMOVE_IN_SINGLE_SCRIPT'):
if liner.lstrip () == '# AUTO_REMOVE_IN_SINGLE_SCRIPT_BLOCK_START':
writing = False
else:
fdout.write (line)
else:
if liner.lstrip () == '# AUTO_REMOVE_IN_SINGLE_SCRIPT_BLOCK_END':
writing = True
open ('sympad/sympad.py', 'w', newline = '', encoding="utf8").write (fdout.getvalue ())
open ('bin/sympad', 'w', newline = '', encoding="utf8").write (fdout.getvalue ())
os.chmod ('bin/sympad', 0o755)