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

Side by Side Diff: sitescripts/docs/bin/generate_docs.py

Issue 29335805: Issue 1299 - Generate docs outside the devbuild build process (Closed)
Patch Set: Use hg clone/pull instead of hg archive Created Feb. 8, 2016, 9:57 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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", "--update"
39 try: 39 "--repository", sources_dir])
Wladimir Palant 2016/02/09 10:44:28 You don't really want to call |hg pull --update|,
Felix Dahlke 2016/02/09 12:40:22 Done.
40 with open(id_path, "rb") as id_file: 40 else:
41 local_id = id_file.read() 41 subprocess.check_call(["hg", "clone", "--quiet",
42 if local_id == remote_id: 42 "--updaterev", "master",
43 return 43 repository_url, sources_dir])
44 except IOError:
45 pass
46
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 44
62 def replace_dir(source_dir, target_dir): 45 def replace_dir(source_dir, target_dir):
63 if not os.path.exists(target_dir): 46 if not os.path.exists(target_dir):
64 parent_dir = os.path.dirname(target_dir) 47 parent_dir = os.path.dirname(target_dir)
65 try: 48 try:
66 os.makedirs(parent_dir) 49 os.makedirs(parent_dir)
67 except OSError: 50 except OSError:
68 pass 51 pass
69 os.rename(source_dir, target_dir) 52 os.rename(source_dir, target_dir)
70 else: 53 else:
(...skipping 19 matching lines...) Expand all
90 sources_dir = os.path.join(temp_directory, name) 73 sources_dir = os.path.join(temp_directory, name)
91 sync_sources(sources_dir, data["repository"]) 74 sync_sources(sources_dir, data["repository"])
92 output_dir = sources_dir.rstrip(os.path.sep) + ".docs" 75 output_dir = sources_dir.rstrip(os.path.sep) + ".docs"
93 run_generation_command(data["command"], sources_dir, output_dir) 76 run_generation_command(data["command"], sources_dir, output_dir)
94 replace_dir(output_dir, data["target_directory"]) 77 replace_dir(output_dir, data["target_directory"])
95 78
96 if __name__ == "__main__": 79 if __name__ == "__main__":
97 config = get_config() 80 config = get_config()
98 projects = read_projects(config) 81 projects = read_projects(config)
99 generate_docs(projects, config) 82 generate_docs(projects, config)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld