| OLD | NEW |
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import logging | 6 import logging |
| 7 import io | 7 import io |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import shutil | 11 import shutil |
| 12 import subprocess | |
| 13 import sys | |
| 14 from urllib import urlencode | 12 from urllib import urlencode |
| 15 import urllib2 | 13 import urllib2 |
| 16 from functools import partial | 14 from functools import partial |
| 17 from StringIO import StringIO | 15 from StringIO import StringIO |
| 18 from zipfile import ZipFile | 16 from zipfile import ZipFile |
| 19 from buildtools.localeTools import read_locale_config | 17 from buildtools.localeTools import read_locale_config |
| 20 | 18 |
| 21 KNOWN_PLATFORMS = {'chrome', 'gecko', 'edge', 'generic'} | 19 KNOWN_PLATFORMS = {'chrome', 'gecko', 'edge', 'generic'} |
| 22 | 20 |
| 23 MAIN_PARSER = argparse.ArgumentParser( | 21 MAIN_PARSER = argparse.ArgumentParser( |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 from buildtools.packager import readMetadata | 277 from buildtools.packager import readMetadata |
| 280 metadata = readMetadata(base_dir, platform) | 278 metadata = readMetadata(base_dir, platform) |
| 281 | 279 |
| 282 basename = metadata.get('general', 'basename') | 280 basename = metadata.get('general', 'basename') |
| 283 locale_config = read_locale_config(base_dir, platform, metadata) | 281 locale_config = read_locale_config(base_dir, platform, metadata) |
| 284 | 282 |
| 285 import buildtools.localeTools as localeTools | 283 import buildtools.localeTools as localeTools |
| 286 localeTools.getTranslations(locale_config, basename, project_key) | 284 localeTools.getTranslations(locale_config, basename, project_key) |
| 287 | 285 |
| 288 | 286 |
| 289 @argparse_command( | |
| 290 valid_platforms={'chrome'}, | |
| 291 arguments=( | |
| 292 make_argument('target_dir'), | |
| 293 make_argument('-q', '--quiet', help='Suppress JsDoc output', | |
| 294 action='store_true', default=False), | |
| 295 ), | |
| 296 ) | |
| 297 def docs(base_dir, target_dir, quiet, platform, **kwargs): | |
| 298 """ | |
| 299 Generate documentation (requires node.js). | |
| 300 | |
| 301 Generate documentation files and write them into the specified directory. | |
| 302 """ | |
| 303 source_dir = os.path.join(base_dir, 'lib') | |
| 304 | |
| 305 # JSDoc struggles wih huge objects: | |
| 306 # https://github.com/jsdoc3/jsdoc/issues/976 | |
| 307 sources = [os.path.join(source_dir, filename) | |
| 308 for filename in os.listdir(source_dir) | |
| 309 if filename != 'publicSuffixList.js'] | |
| 310 | |
| 311 buildtools_path = os.path.dirname(__file__) | |
| 312 config = os.path.join(buildtools_path, 'jsdoc.conf') | |
| 313 | |
| 314 command = ['npm', 'run-script', 'jsdoc', '--', '--destination', target_dir, | |
| 315 '--configure', config] + sources | |
| 316 if quiet: | |
| 317 process = subprocess.Popen(command, stdout=subprocess.PIPE, | |
| 318 stderr=subprocess.PIPE, cwd=buildtools_path) | |
| 319 stderr = process.communicate()[1] | |
| 320 retcode = process.poll() | |
| 321 if retcode: | |
| 322 sys.stderr.write(stderr) | |
| 323 raise subprocess.CalledProcessError(command, retcode) | |
| 324 else: | |
| 325 subprocess.check_call(command, cwd=buildtools_path) | |
| 326 | |
| 327 | |
| 328 def valid_version_format(value): | 287 def valid_version_format(value): |
| 329 if re.search(r'[^\d\.]', value): | 288 if re.search(r'[^\d\.]', value): |
| 330 raise argparse.ArgumentTypeError('Wrong version number format') | 289 raise argparse.ArgumentTypeError('Wrong version number format') |
| 331 | 290 |
| 332 return value | 291 return value |
| 333 | 292 |
| 334 | 293 |
| 335 @argparse_command( | 294 @argparse_command( |
| 336 valid_platforms={'chrome', 'gecko', 'edge'}, multi_platform=True, | 295 valid_platforms={'chrome', 'gecko', 'edge'}, multi_platform=True, |
| 337 arguments=( | 296 arguments=( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if build_available_subcommands(base_dir): | 355 if build_available_subcommands(base_dir): |
| 397 MAIN_PARSER.set_defaults(base_dir=base_dir) | 356 MAIN_PARSER.set_defaults(base_dir=base_dir) |
| 398 | 357 |
| 399 # If no args are provided, this module is run directly from the command | 358 # If no args are provided, this module is run directly from the command |
| 400 # line. argparse will take care of consuming sys.argv. | 359 # line. argparse will take care of consuming sys.argv. |
| 401 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) | 360 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) |
| 402 | 361 |
| 403 function = arguments.function | 362 function = arguments.function |
| 404 del arguments.function | 363 del arguments.function |
| 405 function(**vars(arguments)) | 364 function(**vars(arguments)) |
| OLD | NEW |