-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_docs.py
104 lines (83 loc) · 3.56 KB
/
build_docs.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
94
95
96
97
98
99
100
101
102
103
104
import argparse
import errno
import logging
import os
import sys
if sys.version_info < (3, 5):
logging.basicConfig(level=logging.INFO)
main_logger = logging.getLogger('init')
main_logger.info('only Python Versions from 3.5 are supported, exit with exitcode 0')
sys.exit(0)
from rst_include import *
from rst_include.libs import lib_log
import subprocess
# CONSTANTS & PROJECT SPECIFIC FUNCTIONS
codeclimate_link_hash = "2b2b6589f80589689c2b"
def project_specific(repository_slug, repository, repository_dashed):
# PROJECT SPECIFIC
logger = logging.getLogger('project_specific')
pass
def parse_args(cmd_args=sys.argv[1:]):
# type: ([]) -> []
parser = argparse.ArgumentParser(
description='Create Readme.rst',
epilog='check the documentation on github',
add_help=True)
parser.add_argument('travis_repo_slug', metavar='TRAVIS_REPO_SLUG in the form "<github_account>/<repository>"')
args = parser.parse_args(cmd_args)
return args, parser
def main(args):
logger = logging.getLogger('build_docs')
logger.info('create the README.rst')
travis_repo_slug = args.travis_repo_slug
repository = travis_repo_slug.split('/')[1]
repository_dashed = repository.replace('_', '-')
project_specific(travis_repo_slug, repository, repository_dashed)
"""
paths absolute, or relative to the location of the config file
the notation for relative files is like on windows or linux - not like in python.
so You might use ../../some/directory/some_document.rst to go two levels back.
avoid absolute paths since You never know where the program will run.
"""
logger.info('include the include blocks')
rst_inc(source='./docs/README_template.rst',
target='./docs/README_template_included.rst')
logger.info('replace repository related strings')
rst_str_replace(source='./docs/README_template_included.rst',
target='./docs/README_template_repo_replaced.rst',
old='{repository_slug}',
new=travis_repo_slug)
rst_str_replace(source='./docs/README_template_repo_replaced.rst',
target='./docs/README_template_repo_replaced2.rst',
old='{repository}',
new=repository)
rst_str_replace(source='./docs/README_template_repo_replaced2.rst',
target='./docs/README_template_repo_replaced3.rst',
old='{repository_dashed}',
new=repository_dashed)
rst_str_replace(source='./docs/README_template_repo_replaced3.rst',
target='./README.rst',
old='{codeclimate_link_hash}',
new=codeclimate_link_hash)
logger.info('cleanup')
os.remove('./docs/README_template_included.rst')
os.remove('./docs/README_template_repo_replaced.rst')
os.remove('./docs/README_template_repo_replaced2.rst')
os.remove('./docs/README_template_repo_replaced3.rst')
logger.info('done')
sys.exit(0)
if __name__ == '__main__':
lib_log.setup_logger()
main_logger = logging.getLogger('main')
try:
_args, _parser = parse_args()
main(_args)
except FileNotFoundError:
# see https://www.thegeekstuff.com/2010/10/linux-error-codes for error codes
sys.exit(errno.ENOENT) # No such file or directory
except FileExistsError:
sys.exit(errno.EEXIST) # File exists
except TypeError:
sys.exit(errno.EINVAL) # Invalid Argument
except ValueError:
sys.exit(errno.EINVAL) # Invalid Argument