-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
40 lines (30 loc) · 1.2 KB
/
builder.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
from docset.index import Index
from docset import rules
import os
import shutil
def build_docset(info, ds_rules, src_dir, out_dir):
root_dir = os.path.join(out_dir, info['name'] + '.docset')
content_dir = os.path.join(root_dir, 'Contents')
resources_dir = os.path.join(content_dir, 'Resources')
doc_dir = os.path.join(resources_dir, 'Documents')
index_path = os.path.join(resources_dir, 'docSet.dsidx')
if not os.path.exists(doc_dir):
os.makedirs(doc_dir)
with open(os.path.join(content_dir, "Info.plist"), "w+t") as f:
f.write(info['plist'])
if 'icon' in info and os.path.exists(info['icon']):
shutil.copy2(info['icon'], root_dir)
idx = Index(index_path)
for root, dirnames, filenames in os.walk(src_dir):
for filename in filenames:
full_path = os.path.join(root, filename)
rel_path = os.path.relpath(full_path, src_dir)
dest_path = os.path.join(doc_dir, rel_path)
ctx = {
'src_path': full_path,
'dest_path': dest_path,
'rel_path': rel_path,
'idx': idx
}
rules.process_file_rules(ds_rules, ctx)
idx.flush()