Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: tools/telemetry/build/update_docs.py

Issue 17560002: [telemetry] Remove all pyc files before doing presumibit work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import logging 4 import logging
5 import optparse 5 import optparse
6 import os 6 import os
7 import pkgutil 7 import pkgutil
8 import pydoc 8 import pydoc
9 import re 9 import re
10 import sys 10 import sys
11 11
12 from telemetry.core import util 12 from telemetry.core import util
13 13
14 telemetry_dir = util.GetTelemetryDir() 14 telemetry_dir = util.GetTelemetryDir()
15 docs_dir = os.path.join(telemetry_dir, 'docs') 15 docs_dir = os.path.join(telemetry_dir, 'docs')
16 16
17 def EnsureTelemetryIsInPath(): 17 def EnsureTelemetryIsInPath():
18 if telemetry_dir not in sys.path: 18 if telemetry_dir not in sys.path:
19 sys.path.append(telemetry_dir) 19 sys.path.append(telemetry_dir)
20 20
21 def RemoveAllDocs(): 21 def RemoveAllDocs():
22 for dirname, _, filenames in os.walk(docs_dir): 22 for dirname, _, filenames in os.walk(docs_dir):
23 for filename in filenames: 23 for filename in filenames:
24 os.remove(os.path.join(dirname, filename)) 24 os.remove(os.path.join(dirname, filename))
25 25
26 def RemoveAllStalePycFiles():
27 for dirname, _, filenames in os.walk(telemetry_dir):
28 for filename in filenames:
29 if not filename.endswith('.pyc'):
30 continue
31 pycpath = os.path.join(dirname, filename)
tonyg 2013/06/21 19:02:38 I'd find these more readable as pyc_path and py_pa
32 pypath = os.path.splitext(pycpath)[0] + '.py'
33 if not os.path.exists(pypath):
34 os.remove(pypath)
35
26 def GenerateHTMLForModule(module): 36 def GenerateHTMLForModule(module):
27 html = pydoc.html.page(pydoc.describe(module), 37 html = pydoc.html.page(pydoc.describe(module),
28 pydoc.html.document(module, module.__name__)) 38 pydoc.html.document(module, module.__name__))
29 39
30 # pydoc writes out html with links in a variety of funky ways. We need 40 # pydoc writes out html with links in a variety of funky ways. We need
31 # to fix them up. 41 # to fix them up.
32 assert not telemetry_dir.endswith(os.sep) 42 assert not telemetry_dir.endswith(os.sep)
33 links = re.findall('(<a href="(.+?)">(.+?)</a>)', html) 43 links = re.findall('(<a href="(.+?)">(.+?)</a>)', html)
34 for link_match in links: 44 for link_match in links:
35 link, href, link_text = link_match 45 link, href, link_text = link_match
(...skipping 16 matching lines...) Expand all
52 return html 62 return html
53 63
54 def WriteHTMLForModule(module): 64 def WriteHTMLForModule(module):
55 page = GenerateHTMLForModule(module) 65 page = GenerateHTMLForModule(module)
56 path = os.path.join(docs_dir, '%s.html' % module.__name__) 66 path = os.path.join(docs_dir, '%s.html' % module.__name__)
57 with open(path, 'w') as f: 67 with open(path, 'w') as f:
58 sys.stderr.write('Wrote %s\n' % os.path.relpath(path)) 68 sys.stderr.write('Wrote %s\n' % os.path.relpath(path))
59 f.write(page) 69 f.write(page)
60 70
61 def GetAllModulesToDocument(module): 71 def GetAllModulesToDocument(module):
72 RemoveAllStalePycFiles()
62 modules = [module] 73 modules = [module]
63 for _, modname, _ in pkgutil.walk_packages( 74 for _, modname, _ in pkgutil.walk_packages(
64 module.__path__, module.__name__ + '.'): 75 module.__path__, module.__name__ + '.'):
65 if modname.endswith('_unittest'): 76 if modname.endswith('_unittest'):
66 logging.debug("skipping %s due to being a unittest", modname) 77 logging.debug("skipping %s due to being a unittest", modname)
67 continue 78 continue
68 79
69 module = __import__(modname, fromlist=[""]) 80 module = __import__(modname, fromlist=[""])
70 name, _ = os.path.splitext(module.__file__) 81 name, _ = os.path.splitext(module.__file__)
71 if not os.path.exists(name + '.py'): 82 if not os.path.exists(name + '.py'):
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EnsureTelemetryIsInPath() 159 EnsureTelemetryIsInPath()
149 import telemetry 160 import telemetry
150 161
151 old_cwd = os.getcwd() 162 old_cwd = os.getcwd()
152 try: 163 try:
153 os.chdir(telemetry_dir) 164 os.chdir(telemetry_dir)
154 for module in GetAllModulesToDocument(telemetry): 165 for module in GetAllModulesToDocument(telemetry):
155 WriteHTMLForModule(module) 166 WriteHTMLForModule(module)
156 finally: 167 finally:
157 os.chdir(old_cwd) 168 os.chdir(old_cwd)
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 408576698