Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/docs/bin/generate_docs.py

Issue 29335805: Issue 1299 - Generate docs outside the devbuild build process (Closed)
Left Patch Set: Address comments Created Feb. 6, 2016, 10:46 a.m.
Right Patch Set: Separate pull and update, specify revision to include Created Feb. 9, 2016, 12:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/docs/bin/__init__.py ('k') | sitescripts/extensions/bin/createNightlies.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # This file is part of Adblock Plus <https://adblockplus.org/>, 3 # This file is part of Adblock Plus <https://adblockplus.org/>,
4 # Copyright (C) 2006-2016 Eyeo GmbH 4 # Copyright (C) 2006-2016 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 16 matching lines...) Expand all
27 key_parts = key.split("_", 1) 27 key_parts = key.split("_", 1)
28 if len(key_parts) < 2: 28 if len(key_parts) < 2:
29 continue 29 continue
30 project_name, field_name = key_parts 30 project_name, field_name = key_parts
31 if field_name not in {"repository", "target_directory", "command"}: 31 if field_name not in {"repository", "target_directory", "command"}:
32 continue 32 continue
33 projects.setdefault(project_name, {})[field_name] = value 33 projects.setdefault(project_name, {})[field_name] = value
34 return projects 34 return projects
35 35
36 def sync_sources(sources_dir, repository_url): 36 def sync_sources(sources_dir, repository_url):
37 remote_id = subprocess.check_output(["hg", "id", "--id", repository_url]) 37 if os.path.exists(sources_dir):
38 id_path = sources_dir.rstrip(os.path.sep) + ".id" 38 subprocess.check_call(["hg", "pull", "--quiet",
39 try: 39 "--rev", "master",
40 with open(id_path, "rb") as id_file: 40 "--repository", sources_dir])
41 local_id = id_file.read() 41 subprocess.check_call(["hg", "update", "--quiet",
42 if local_id == remote_id: 42 "--rev", "master"])
43 return 43 else:
44 except IOError: 44 subprocess.check_call(["hg", "clone", "--quiet",
45 pass 45 "--updaterev", "master",
46 46 repository_url, sources_dir])
47 shutil.rmtree(sources_dir, ignore_errors=True)
48 subprocess.check_call(["hg", "archive",
49 "--repository", repository_url,
50 "--rev", "master",
51 sources_dir])
52
53 # In theory, it is possible that some changesets are pushed after we fetch
54 # the ID above, but before we run `hg archive`, which will lead to an
55 # unnecessary `hg archive` operation the next time this runs.
56 with open(id_path, "wb") as id_file:
57 id_file.write(remote_id)
58
59 # This is a workaround for https://issues.adblockplus.org/ticket/3635.
60 os.makedirs(os.path.join(sources_dir, ".hg"))
61 47
62 def replace_dir(source_dir, target_dir): 48 def replace_dir(source_dir, target_dir):
63 if not os.path.exists(target_dir): 49 if not os.path.exists(target_dir):
64 parent_dir = os.path.dirname(target_dir) 50 parent_dir = os.path.dirname(target_dir)
65 try: 51 try:
66 os.makedirs(parent_dir) 52 os.makedirs(parent_dir)
67 except OSError: 53 except OSError:
68 pass 54 pass
69 os.rename(source_dir, target_dir) 55 os.rename(source_dir, target_dir)
70 else: 56 else:
(...skipping 19 matching lines...) Expand all
90 sources_dir = os.path.join(temp_directory, name) 76 sources_dir = os.path.join(temp_directory, name)
91 sync_sources(sources_dir, data["repository"]) 77 sync_sources(sources_dir, data["repository"])
92 output_dir = sources_dir.rstrip(os.path.sep) + ".docs" 78 output_dir = sources_dir.rstrip(os.path.sep) + ".docs"
93 run_generation_command(data["command"], sources_dir, output_dir) 79 run_generation_command(data["command"], sources_dir, output_dir)
94 replace_dir(output_dir, data["target_directory"]) 80 replace_dir(output_dir, data["target_directory"])
95 81
96 if __name__ == "__main__": 82 if __name__ == "__main__":
97 config = get_config() 83 config = get_config()
98 projects = read_projects(config) 84 projects = read_projects(config)
99 generate_docs(projects, config) 85 generate_docs(projects, config)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld