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

Side by Side Diff: pkg/docgen/bin/upload_docgen.py

Issue 56183003: Refactor scripts, so we have a single entrypoint, dartdoc.py, to generate docs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 """ This file will run docgen.dart on the SDK libraries, and upload them to 7 """ This file will run docgen.dart on the SDK libraries, and upload them to
8 Google Cloud Storage for the documentation viewer. 8 Google Cloud Storage for the documentation viewer.
9 """ 9 """
10 10
11 import optparse 11 import optparse
12 import os 12 import os
13 from os.path import join, dirname, abspath, exists 13 from os.path import join, dirname, abspath, exists
14 import platform 14 import platform
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 sys.path.append(abspath(join(dirname(__file__), '../../../tools'))) 17 sys.path.append(abspath(join(dirname(__file__), '../../../tools')))
18 import utils 18 import utils
19 from upload_sdk import ExecuteCommand 19 from upload_sdk import ExecuteCommand
20 20
21 21
22 DART = abspath(join(dirname(__file__), '../../../%s/%s/dart-sdk/bin/dart' 22 DART = abspath(join(dirname(__file__), '../../../%s/%s/dart-sdk/bin/dart'
23 % (utils.BUILD_ROOT[utils.GuessOS()], utils.GetBuildConf('release', 23 % (utils.BUILD_ROOT[utils.GuessOS()], utils.GetBuildConf('release',
24 utils.GuessArchitecture())))) 24 utils.GuessArchitecture()))))
25 PACKAGE_ROOT = abspath(join(dirname(__file__), '../../../%s/%s/packages/' 25 PACKAGE_ROOT = abspath(join(dirname(__file__), '../../../%s/%s/packages/'
26 % (utils.BUILD_ROOT[utils.GuessOS()], utils.GetBuildConf('release', 26 % (utils.BUILD_ROOT[utils.GuessOS()], utils.GetBuildConf('release',
27 utils.GuessArchitecture())))) 27 utils.GuessArchitecture()))))
28 GSUTIL = utils.GetBuildbotGSUtilPath() 28 GSUTIL = utils.GetBuildbotGSUtilPath()
29 GS_SITE = 'gs://dartlang-docgen' 29 GS_SITE = 'gs://dartlang-docgen'
30 DESCRIPTION='Runs docgen.dart on the SDK libraries, and uploads them to Google \ 30 DESCRIPTION='Runs docgen.dart on the SDK libraries, and uploads them to Google \
31 Cloud Storage for the dartdoc-viewer. ' 31 Cloud Storage for the dartdoc-viewer. '
32 # Allow us to override checking SVN's revision number. Useful for development 32 # Allow us to override checking SVN's revision number. Useful for development
33 # so we can upload docs from a branch using an SDK that was built on a 33 # so we can upload docs from a branch using an SDK that was built on a
34 # revision newer than when the branch was forked. 34 # revision newer than when the branch was forked.
35 trustSVN = None 35 trustSVN = None
36 36
37 def GetOptions(): 37 def GetOptions():
38 parser = optparse.OptionParser(description=DESCRIPTION) 38 parser = optparse.OptionParser(description=DESCRIPTION)
39 parser.add_option('--package-root', dest='pkg_root', 39 parser.add_option('--package-root', dest='pkg_root',
40 help='The package root for dart. (Default is in the build directory.)', 40 help='The package root for dart. (Default is in the build directory.)',
41 action='store', default=PACKAGE_ROOT) 41 action='store', default=PACKAGE_ROOT)
42 parser.add_option('--dontTrustSVN', dest='dontTrustSVN', default=False, 42 parser.add_option('--dontTrustSVN', dest='dontTrustSVN', default=False,
43 help='Don''t rely on the SVN revision number, check the DART SDK instead', 43 help='Don''t rely on the SVN revision number, check the DART SDK instead',
44 action='store_true') 44 action='store_true')
45 (options, args) = parser.parse_args() 45 (options, args) = parser.parse_args()
46 SetPackageRoot(options.pkg_root) 46 SetPackageRoot(options.pkg_root)
47 trustSVN = not options.dontTrustSVN 47 trustSVN = not options.dontTrustSVN
48 48
49 def SetPackageRoot(path): 49 def SetPackageRoot(path):
50 global PACKAGE_ROOT 50 global PACKAGE_ROOT
51 if exists(path): 51 if exists(path):
52 PACKAGE_ROOT = abspath(path) 52 PACKAGE_ROOT = abspath(path)
53 53
54 54
55 def SetGsutil(): 55 def SetGsutil():
56 """ If not on buildbots, find gsutil relative to docgen. """ 56 """ If not on buildbots, find gsutil relative to docgen. """
57 global GSUTIL 57 global GSUTIL
58 if not exists(GSUTIL): 58 if not exists(GSUTIL):
59 GSUTIL = abspath(join(dirname(__file__), 59 GSUTIL = abspath(join(dirname(__file__),
60 '../../../third_party/gsutil/gsutil')) 60 '../../../third_party/gsutil/gsutil'))
61 61
62 62
63 def Upload(source, target): 63 def Upload(source, target):
64 """ Upload files to Google Storage. """ 64 """ Upload files to Google Storage. """
65 cmd = [GSUTIL, '-m', 'cp', '-q', '-a', 'public-read', '-r', source, target] 65 cmd = [GSUTIL, '-m', 'cp', '-q', '-a', 'public-read', '-r', source, target]
66 (status, output) = ExecuteCommand(cmd) 66 (status, output) = ExecuteCommand(cmd)
67 return status 67 return status
68 68
69 69
70 def main(): 70 def main():
71 GetOptions() 71 GetOptions()
72 72
73 SetGsutil() 73 SetGsutil()
74 74
75 # Execute Docgen.dart on the SDK. 75 # Execute Docgen.dart on the SDK.
76 ExecuteCommand(['sh', './generate_all_docs.sh']) 76 ExecuteCommand(['python', 'dartdoc.py', '-d'])
77 77
78 # Use SVN Revision to get the revision number. 78 # Use SVN Revision to get the revision number.
79 revision = None 79 revision = None
80 if trustSVN: 80 if trustSVN:
81 revision = utils.GetSVNRevision() 81 revision = utils.GetSVNRevision()
82 82
83 if revision is None: 83 if revision is None:
84 # Try to find the version from the dart-sdk folder. 84 # Try to find the version from the dart-sdk folder.
85 revision_file_location = abspath(join(dirname(__file__), 85 revision_file_location = abspath(join(dirname(__file__),
86 '../../../%s/%s/dart-sdk/revision' % (utils.BUILD_ROOT[utils.GuessOS()], 86 '../../../%s/%s/dart-sdk/revision' % (utils.BUILD_ROOT[utils.GuessOS()],
87 utils.GetBuildConf('release', utils.GuessArchitecture())))) 87 utils.GetBuildConf('release', utils.GuessArchitecture()))))
88 with open(revision_file_location, 'r') as revision_file: 88 with open(revision_file_location, 'r') as revision_file:
89 revision = revision_file.readline(5) 89 revision = revision_file.readline(5)
90 revision_file.close() 90 revision_file.close()
91 91
92 if revision is None: 92 if revision is None:
93 raise Exception("Unable to find revision. ") 93 raise Exception("Unable to find revision. ")
94 94
95 # Upload the all files in Docs into a folder based off Revision number on 95 # Upload the all files in Docs into a folder based off Revision number on
96 # Cloud Storage. 96 # Cloud Storage.
97 # TODO(alanknight): If we give it ./docs/* it fails to upload files in the 97 # TODO(alanknight): If we give it ./docs/* it fails to upload files in the
98 # subdirectory, probably due to escaping. Work around it by changing dir. 98 # subdirectory, probably due to escaping. Work around it by changing dir.
99 # Better, generalize this to be less dependent on the working directory. 99 # Better, generalize this to be less dependent on the working directory.
100 os.chdir('docs') 100 os.chdir('docs')
101 Upload('.', GS_SITE + '/' + revision + '/') 101 Upload('.', GS_SITE + '/' + revision + '/')
102 os.chdir('..') 102 os.chdir('..')
103 103
104 # Update VERSION file in Cloud Storage. 104 # Update VERSION file in Cloud Storage.
105 with open('VERSION', 'w') as version_file: 105 with open('VERSION', 'w') as version_file:
106 version_file.write(revision) 106 version_file.write(revision)
107 version_file.close() 107 version_file.close()
108 Upload('./VERSION', GS_SITE + '/VERSION') 108 Upload('./VERSION', GS_SITE + '/VERSION')
109 Upload('./VERSION', GS_SITE + '/' + revision + '/' + 'VERSION') 109 Upload('./VERSION', GS_SITE + '/' + revision + '/' + 'VERSION')
110 110
111 # Clean up the files it creates. 111 # Clean up the files it creates.
112 ExecuteCommand(['rm', '-rf', './docs']) 112 ExecuteCommand(['rm', '-rf', './docs'])
113 ExecuteCommand(['rm', '-f', './VERSION']) 113 ExecuteCommand(['rm', '-f', './VERSION'])
114 114
115 115
116 if __name__ == '__main__': 116 if __name__ == '__main__':
117 main() 117 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698