-
Notifications
You must be signed in to change notification settings - Fork 2
/
embed.py
executable file
·58 lines (39 loc) · 1.1 KB
/
embed.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
#!/usr/bin/env python
# coding: utf-8
import re
import sys
skip_in_subfile = (
'^#!/bin/sh',
)
def embed_source(fn, processed=None, skip=()):
if processed is None:
processed = {}
lines = []
with open(fn, 'r') as f:
for line in f:
to_skip = False
for sk in skip:
if re.match(sk, line):
to_skip = True
break
if to_skip:
continue
m = re.match('^ *source (.*)', line)
if not m:
lines.append(line)
continue
subfn = m.groups()[0]
if subfn in processed:
continue
processed[subfn] = True
sublines = embed_source(subfn,
processed=processed,
skip=skip_in_subfile)
lines.extend(sublines)
return lines
if __name__ == "__main__":
fn = sys.argv[1]
dist = sys.argv[2]
lines = embed_source(fn)
with open(dist + '/' + fn, 'w') as f:
f.write(''.join(lines))