in update-imported-docs/update-imported-docs.py [0:0]
def main():
"""The main entry of the program."""
if len(error_msgs) > 0:
for msg in error_msgs:
print(msg + "\n")
return -2
# first parse input argument
in_args = parse_input_args()
config_file = in_args.config_file
print("config_file is {}".format(config_file))
# second parse input argument
k8s_release = in_args.k8s_release
print("k8s_release is {}".format(k8s_release))
# if release string does not contain patch num, add zero
if len(k8s_release) == 4:
k8s_release = k8s_release + ".0"
print("k8s_release updated to {}".format(k8s_release))
curr_dir = os.path.dirname(os.path.abspath(__file__))
print("curr_dir {}".format(curr_dir))
root_dir = os.path.realpath(os.path.join(curr_dir, '..'))
print("root_dir {}".format(root_dir))
try:
config_data = yaml.full_load(open(config_file, 'r'))
except Exception as ex:
# to catch when a user specifies a file that does not exist
print("[Error] failed in loading config file - {}".format(str(ex)))
return -2
os.chdir(root_dir)
# create the temp work_dir
try:
print("Making temp work_dir")
work_dir = tempfile.mkdtemp(
dir='/tmp' if platform.system() == 'Darwin' else tempfile.gettempdir()
)
except OSError as ose:
print("[Error] Unable to create temp work_dir {}; error: {}"
.format(work_dir, ose))
return -2
print("Working dir {}".format(work_dir))
for repo in config_data["repos"]:
if "name" not in repo:
print("[Error] repo missing name")
continue
repo_name = repo["name"]
if "remote" not in repo:
print("[Error] repo {} missing repo path".format(repo_name))
continue
repo_remote = repo["remote"]
remote_regex = re.compile(r"^https://(?P<prefix>.*)\.git$")
matches = remote_regex.search(repo_remote)
if not matches:
print("[Error] repo path for {} is invalid".format(repo_name))
continue
repo_path = os.path.join("src", matches.group('prefix'))
os.chdir(work_dir)
print("Cloning repo {}".format(repo_name))
cmd = "git clone --depth=1 -b {0} {1} {2}".format(
repo["branch"], repo_remote, repo_path)
res = subprocess.call(cmd, shell=True)
if res != 0:
print("[Error] failed in cloning repo {}".format(repo_name))
continue
os.chdir(repo_path)
if "generate-command" in repo:
gen_cmd = repo["generate-command"]
gen_cmd = "export K8S_RELEASE=" + k8s_release + "\n" + \
"export GOPATH=" + work_dir + "\n" + \
"export K8S_ROOT=" + work_dir + \
"/src/k8s.io/kubernetes" + "\n" + \
"export K8S_WEBROOT=" + root_dir + "\n" + gen_cmd
print("Generating docs for {} with {}".format(repo_name, gen_cmd))
res = subprocess.call(gen_cmd, shell=True)
if res != 0:
print("[Error] failed in generating docs for {}".format(
repo_name))
continue
os.chdir(root_dir)
for f in repo["files"]:
process_file(f['src'], f['dst'], repo_path, work_dir, root_dir,
"gen-absolute-links" in repo)
print("Completed docs update. Now run the following command to commit:\n\n"
" git add .\n"
" git commit -m <comment>\n"
" git push\n"
" delete temp dir {} when done ".format(work_dir))