-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_doc.py
executable file
·46 lines (37 loc) · 1.13 KB
/
publish_doc.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
#!/usr/bin/env python
import os
import commands
import yaml
def publish_doc(packages, output_dir):
repo_name = os.getenv('REPO_NAME')
repos_file = os.getenv('REPOS_FILE')
public_dir = os.getenv('PUBLIC_DIR')
repo_contents = {}
repo_contents[repo_name] = packages
if not os.path.isfile(repos_file):
# copying new docs
for package in packages:
cmd = 'rsync -a ' + os.path.join(output_dir, package) + ' ' + public_dir
print '+', cmd
os.system(cmd)
doc = open(repos_file, 'w')
doc.write(yaml.dump(repo_contents))
doc.close()
else:
doc = open(repos_file, 'r')
repos = yaml.safe_load(doc)
doc.close()
if repo_name in repos:
# deleting old docs
for package in repos[repo_name]:
cmd = 'rm -rf ' + os.path.join(public_dir, package)
print '+', cmd
os.system(cmd)
# copying new docs
for package in packages:
cmd = 'rsync -a ' + os.path.join(output_dir, package) + ' ' + public_dir
print '+', cmd
os.system(cmd)
repos[repo_name] = packages
doc = open(repos_file, 'w')
doc.write(yaml.dump(repos))