Skip to content

Commit d24c4b5

Browse files
author
Sam Kleinman
committed
build: refactor utility functions and meta script
1 parent 94d819a commit d24c4b5

File tree

7 files changed

+59
-56
lines changed

7 files changed

+59
-56
lines changed

bin/delegated-build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import sys
55
import subprocess
66
import argparse
77
import datetime
8-
from docs_meta import PUBLISHED_BRANCHES, get_branch
8+
from docs_meta import PUBLISHED_BRANCHES
99
import utils
1010

1111
branches = PUBLISHED_BRANCHES
12-
current_branch = get_branch(os.getcwd())
12+
current_branch = utils.get_branch(os.getcwd())
1313

1414
if current_branch not in branches:
1515
branches.append(current_branch)
@@ -87,7 +87,7 @@ def update_repo(path, logfile=None, branch='master'):
8787
change_branch(branch, path)
8888

8989
def build_branch(branch, path, logfile, target='publish', wait=False):
90-
if get_branch(path) != branch:
90+
if utils.get_branch(path) != branch:
9191
change_branch(branch, path)
9292

9393
cmd = ['make', target]

bin/docs_meta.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
#!/usr/bin/python
22

33
import datetime
4-
import os
5-
import re
6-
import subprocess
74
import argparse
85
import yaml
96

7+
from utils import write_yaml, shell_value, get_commit, get_branch
8+
109
# branch and release information source
1110
GIT_REMOTE = { 'upstream': 'mongodb/docs' }
1211
MANUAL_BRANCH = 'master'
1312
PUBLISHED_BRANCHES = [ 'master', 'v2.2' ] # PUBLISHED_BRANCHES **must** be ordered from latest to oldest release.
1413
PUBLISHED_VERSIONS = [ '2.4', '2.2' ]
14+
1515
STABLE_RELEASE = PUBLISHED_VERSIONS[0]
1616
UPCOMING_RELEASE = None
1717

18-
def get_build_envs():
19-
s = (['build/' + branch + '/branch-source/' for branch in PUBLISHED_BRANCHES ] +
20-
['build/' + branch + '/branch-source-current/' for branch in PUBLISHED_BRANCHES ])
21-
s.append('build/' + branch + '/source/')
22-
return s
23-
24-
def shell_value(args, path=None):
25-
if path is None:
26-
path = os.getcwd()
27-
28-
if isinstance(args , str):
29-
r = re.compile("\s+")
30-
args = r.split(args)
31-
32-
p = subprocess.Popen(args, cwd=path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
33-
r = p.communicate()
34-
35-
return str(r[0].decode().rstrip())
36-
3718
def get_manual_path():
3819
branch = get_branch()
3920

@@ -44,18 +25,6 @@ def get_manual_path():
4425

4526
return manual_path
4627

47-
def get_commit(path=None):
48-
if path is None:
49-
path = os.getcwd()
50-
51-
return shell_value('git rev-parse --verify HEAD', path)
52-
53-
def get_branch(path=None):
54-
if path is None:
55-
path = os.getcwd()
56-
57-
return shell_value('git symbolic-ref HEAD', path).split('/')[2]
58-
5928
def get_versions():
6029
o = []
6130

@@ -85,8 +54,7 @@ def output_yaml(fn):
8554
'pdfs': []
8655
}
8756

88-
with open(fn, 'w') as f:
89-
f.write(yaml.dump(o, default_flow_style=False))
57+
write_yaml(o, fn)
9058

9159
def render_paths(fn):
9260
paths = {
@@ -101,8 +69,7 @@ def render_paths(fn):
10169
paths['branch-staging'] = paths['public'] + '/' + get_branch()
10270

10371
if str(fn).endswith('yaml'):
104-
with open(fn, 'w') as f:
105-
f.write(yaml.dump(paths, default_flow_style=False))
72+
utils.write_yaml(paths, fn)
10673
elif fn == 'print':
10774
print(yaml.dump(paths, default_flow_style=False))
10875
else:

bin/makecloth/delegated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
77

88
import utils
9-
import docs_meta as mongo_meta
9+
from docs_meta import PUBLISHED_BRANCHES
1010

1111
from makecloth import MakefileCloth
1212

1313
m = MakefileCloth()
1414

1515
def generate_delegated_interface(builders):
16-
branches = mongo_meta.PUBLISHED_BRANCHES
17-
current_branch = mongo_meta.get_branch()
16+
branches = PUBLISHED_BRANCHES
17+
current_branch = utils.get_branch()
1818

1919
if current_branch not in branches:
2020
branches.append(current_branch)

bin/makecloth/json_output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
77

88
import utils
9-
from docs_meta import get_manual_path, get_branch, render_paths
9+
from docs_meta import get_manual_path, render_paths
1010
from makecloth import MakefileCloth
1111

1212
paths = render_paths('dict')
1313
m = MakefileCloth()
1414

1515
def generate_list_file(outputs, path):
1616
with open(path, 'w') as f:
17-
branch = get_manual_path()
17+
branch =get_manual_path()
1818

1919
for fn in outputs:
2020
url = [ 'http://docs.mongodb.org', branch ]

bin/makecloth/meta.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
import os.path
44
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
55

6-
import docs_meta as docs_meta
6+
import utils
7+
from docs_meta import get_manual_path, MANUAL_BRANCH, render_paths
78
from makecloth import MakefileCloth
89
m = MakefileCloth()
910

1011
def generate_meta():
1112
m.section_break('branch/release meta', block='rel')
12-
m.var('manual-branch', docs_meta.MANUAL_BRANCH, block='rel')
13-
m.var('current-branch', str(docs_meta.get_branch()), block='rel')
14-
m.var('last-commit', str(docs_meta.get_commit()), block='rel')
15-
m.var('current-if-not-manual', str(docs_meta.get_manual_path()), block='rel')
13+
m.var('manual-branch', MANUAL_BRANCH, block='rel')
14+
m.var('current-branch', str(utils.get_branch()), block='rel')
15+
m.var('last-commit', str(utils.get_commit()), block='rel')
16+
m.var('current-if-not-manual', str(get_manual_path()), block='rel')
1617

17-
paths = docs_meta.render_paths(True)
18+
paths = render_paths(True)
1819

1920
m.section_break('file system paths', block='paths')
2021
m.var('output', paths['output'], block='paths')

bin/makecloth/pdfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import os.path
55

66
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
7-
import docs_meta
87
import utils
98
from makecloth import MakefileCloth
9+
from docs_meta import render_paths
1010

1111
m = MakefileCloth()
1212

13-
paths = docs_meta.render_paths('dict')
13+
paths = render_paths('dict')
1414

1515
def pdf_makefile(name, tag):
1616
name_tagged = '-'.join([name, tag])
1717
name_tagged_pdf = name_tagged + '.pdf'
18-
name_tagged_branch_pdf = '-'.join([name, tag, docs_meta.get_branch()]) + '.pdf'
18+
name_tagged_branch_pdf = '-'.join([name, tag, utils.get_branch()]) + '.pdf'
1919

2020
generated_latex = '{0}/latex/{1}.tex'.format(paths['branch-output'], name)
2121
built_tex = '{0}/latex/{1}.tex'.format(paths['branch-output'], name_tagged)

bin/utils.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
import re
12
import yaml
23
import sys
3-
import os.path
4+
import os
45
import subprocess
56
import json
67

8+
def shell_value(args, path=None):
9+
if path is None:
10+
path = os.getcwd()
11+
12+
if isinstance(args , str):
13+
r = re.compile("\s+")
14+
args = r.split(args)
15+
16+
p = subprocess.Popen(args, cwd=path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17+
r = p.communicate()
18+
19+
return str(r[0].decode().rstrip())
20+
21+
def get_commit(path=None):
22+
if path is None:
23+
path = os.getcwd()
24+
25+
return shell_value('git rev-parse --verify HEAD', path)
26+
27+
def get_branch(path=None):
28+
if path is None:
29+
path = os.getcwd()
30+
31+
return shell_value('git symbolic-ref HEAD', path).split('/')[2]
32+
733
def expand_tree(path, input_extension='yaml'):
834
file_list = []
935
for root, subFolders, files in os.walk(path):
@@ -40,6 +66,15 @@ def ingest_yaml(filename):
4066

4167
return o
4268

69+
def write_yaml(input, filename):
70+
with open(filename, 'w') as f:
71+
if isinstance(input, list):
72+
f.write(yaml.safe_dump_all(input, default_flow_style=False))
73+
elif isinstance(input, dict):
74+
f.write(yaml.safe_dump(input, default_flow_style=False))
75+
else:
76+
raise Exception('cannot dump $s objects to yaml.' % str(type(input)))
77+
4378
def ingest_json(filename):
4479
o = []
4580
with open(filename, 'r') as f:

0 commit comments

Comments
 (0)