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

Delta Between Two Patch Sets: build.py

Issue 9259023: Use platform-dependent metadata files to allow multiple builds from the same repository (Closed)
Left Patch Set: Created Jan. 25, 2013, 7:10 a.m.
Right Patch Set: The -t command line flag is now properly documented in the help output, it`s still a very special c… Created Jan. 25, 2013, 8:22 a.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 | « no previous file | packager.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 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 def usage(scriptName, type, commandName=None): 107 def usage(scriptName, type, commandName=None):
108 if commandName == None: 108 if commandName == None:
109 global commandsList 109 global commandsList
110 descriptions = [] 110 descriptions = []
111 for command in commandsList: 111 for command in commandsList:
112 if not command.isSupported(type): 112 if not command.isSupported(type):
113 continue 113 continue
114 commandText = ('%s %s' % (command.name, command.params)).ljust(39) 114 commandText = ('%s %s' % (command.name, command.params)).ljust(39)
115 descriptionParts = splitByLength(command.shortDescription, 29) 115 descriptionParts = splitByLength(command.shortDescription, 29)
116 descriptions.append(' %s %s %s' % (scriptName, commandText, descriptionPa rts[0])) 116 descriptions.append(' %s [-t %s] %s %s' % (scriptName, type, commandText, descriptionParts[0]))
117 for part in descriptionParts[1:]: 117 for part in descriptionParts[1:]:
118 descriptions.append(' %s %s %s' % (' ' * len(scriptName), ' ' * len(com mandText), part)) 118 descriptions.append(' %s %s %s %s' % (' ' * len(scriptName), ' ' * len(type), ' ' * len(commandText), part))
119 print '''Usage: 119 print '''Usage:
120 120
121 %(descriptions)s 121 %(descriptions)s
122 122
123 For details on a command run: 123 For details on a command run:
124 124
125 %(scriptName)s <command> --help 125 %(scriptName)s [-t %(type)s] <command> --help
126 ''' % { 126 ''' % {
127 'scriptName': scriptName, 127 'scriptName': scriptName,
128 'type': type,
128 'descriptions': '\n'.join(descriptions) 129 'descriptions': '\n'.join(descriptions)
129 } 130 }
130 else: 131 else:
131 global commands 132 global commands
132 command = commands[commandName] 133 command = commands[commandName]
133 description = '\n'.join(map(lambda s: '\n'.join(splitByLength(s, 80)), comma nd.description.split('\n'))) 134 description = '\n'.join(map(lambda s: '\n'.join(splitByLength(s, 80)), comma nd.description.split('\n')))
134 options = [] 135 options = []
135 for descr, short, long, value, types in command.options: 136 for descr, short, long, value, types in command.options:
136 if types != None and type not in types: 137 if types != None and type not in types:
137 continue 138 continue
138 if short == None: 139 if short == None:
139 shortText = '' 140 shortText = ''
140 elif value == None: 141 elif value == None:
141 shortText = '-%s' % short 142 shortText = '-%s' % short
142 else: 143 else:
143 shortText = '-%s %s' % (short, value) 144 shortText = '-%s %s' % (short, value)
144 if long == None: 145 if long == None:
145 longText = '' 146 longText = ''
146 elif value == None: 147 elif value == None:
147 longText = '--%s' % long 148 longText = '--%s' % long
148 else: 149 else:
149 longText = '--%s=%s' % (long, value) 150 longText = '--%s=%s' % (long, value)
150 descrParts = splitByLength(descr, 46) 151 descrParts = splitByLength(descr, 46)
151 options.append(' %s %s %s' % (shortText.ljust(11), longText.ljust(19), de scrParts[0])) 152 options.append(' %s %s %s' % (shortText.ljust(11), longText.ljust(19), de scrParts[0]))
152 for part in descrParts[1:]: 153 for part in descrParts[1:]:
153 options.append(' %s %s %s' % (' ' * 11, ' ' * 19, part)) 154 options.append(' %s %s %s' % (' ' * 11, ' ' * 19, part))
154 print '''%(scriptName)s %(name)s %(params)s 155 print '''%(scriptName)s [-t %(type)s] %(name)s %(params)s
155 156
156 %(description)s 157 %(description)s
157 158
158 Options: 159 Options:
159 %(options)s 160 %(options)s
160 ''' % { 161 ''' % {
161 'scriptName': scriptName, 162 'scriptName': scriptName,
163 'type': type,
162 'name': command.name, 164 'name': command.name,
163 'params': command.params, 165 'params': command.params,
164 'description': description, 166 'description': description,
165 'options': '\n'.join(options) 167 'options': '\n'.join(options)
166 } 168 }
167 169
168 170
169 def runBuild(baseDir, scriptName, opts, args, type): 171 def runBuild(baseDir, scriptName, opts, args, type):
170 locales = None 172 locales = None
171 buildNum = None 173 buildNum = None
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 352
351 def generateDocs(baseDir, scriptName, opts, args, type): 353 def generateDocs(baseDir, scriptName, opts, args, type):
352 if len(args) == 0: 354 if len(args) == 0:
353 print 'No target directory specified for the documentation' 355 print 'No target directory specified for the documentation'
354 usage(scriptName, type, 'docs') 356 usage(scriptName, type, 'docs')
355 return 357 return
356 targetDir = args[0] 358 targetDir = args[0]
357 359
358 toolkit = None 360 toolkit = None
359 for option, value in opts: 361 for option, value in opts:
360 if option in ('-k', '--toolkit'): 362 if option in ('-t', '--toolkit'):
361 toolkit = value 363 toolkit = value
362 364
363 if toolkit == None: 365 if toolkit == None:
364 toolkit = os.path.join(baseDir, 'jsdoc-toolkit') 366 toolkit = os.path.join(baseDir, 'jsdoc-toolkit')
365 if not os.path.exists(toolkit): 367 if not os.path.exists(toolkit):
366 subprocess.Popen(['hg', 'clone', 'https://hg.adblockplus.org/jsdoc-toolkit /', toolkit]).communicate() 368 subprocess.Popen(['hg', 'clone', 'https://hg.adblockplus.org/jsdoc-toolkit /', toolkit]).communicate()
367 369
368 command = [sys.executable, 370 command = [sys.executable,
369 os.path.join(toolkit, 'jsrun.py'), 371 os.path.join(toolkit, 'jsrun.py'),
370 '-t=' + os.path.join(toolkit, 'templates', 'jsdoc'), 372 '-t=' + os.path.join(toolkit, 'templates', 'jsdoc'),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 with addCommand(showDescriptions, 'showdesc') as command: 473 with addCommand(showDescriptions, 'showdesc') as command:
472 command.shortDescription = 'Print description strings for all locales' 474 command.shortDescription = 'Print description strings for all locales'
473 command.description = 'Display description strings for all locales as specifie d in the corresponding meta.properties files.' 475 command.description = 'Display description strings for all locales as specifie d in the corresponding meta.properties files.'
474 command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3') 476 command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3')
475 command.params = '[options]' 477 command.params = '[options]'
476 command.supportedTypes = ('gecko') 478 command.supportedTypes = ('gecko')
477 479
478 with addCommand(generateDocs, 'docs') as command: 480 with addCommand(generateDocs, 'docs') as command:
479 command.shortDescription = 'Generate documentation' 481 command.shortDescription = 'Generate documentation'
480 command.description = 'Generate documentation files and write them into the sp ecified directory.' 482 command.description = 'Generate documentation files and write them into the sp ecified directory.'
481 command.addOption('JsDoc Toolkit location', short='k', long='toolkit', value=' dir') 483 command.addOption('JsDoc Toolkit location', short='t', long='toolkit', value=' dir')
482 command.params = '[options] <directory>' 484 command.params = '[options] <directory>'
483 command.supportedTypes = ('gecko') 485 command.supportedTypes = ('gecko')
484 486
485 with addCommand(runReleaseAutomation, 'release') as command: 487 with addCommand(runReleaseAutomation, 'release') as command:
486 command.shortDescription = 'Run release automation' 488 command.shortDescription = 'Run release automation'
487 command.description = 'Note: If you are not the project owner then you '\ 489 command.description = 'Note: If you are not the project owner then you '\
488 'probably don\'t want to run this!\n\n'\ 490 'probably don\'t want to run this!\n\n'\
489 'Runs release automation: creates downloads for the new version, tags '\ 491 'Runs release automation: creates downloads for the new version, tags '\
490 'source code repository as well as downloads and buildtools repository.' 492 'source code repository as well as downloads and buildtools repository.'
491 command.addOption('File containing private key and certificates required to si gn the release', short='k', long='key', value='file', types=('gecko')) 493 command.addOption('File containing private key and certificates required to si gn the release', short='k', long='key', value='file', types=('gecko'))
492 command.addOption('Directory containing downloads repository (if omitted ../do wnloads is assumed)', short='d', long='downloads', value='dir') 494 command.addOption('Directory containing downloads repository (if omitted ../do wnloads is assumed)', short='d', long='downloads', value='dir')
493 command.params = '[options] <version>' 495 command.params = '[options] <version>'
494 command.supportedTypes = ('gecko') 496 command.supportedTypes = ('gecko')
495 497
496 with addCommand(syncLocales, 'synclocales') as command: 498 with addCommand(syncLocales, 'synclocales') as command:
497 command.shortDescription = 'Sync locales with a Firefox extension' 499 command.shortDescription = 'Sync locales with a Firefox extension'
498 command.description = 'Updates locale files with strings from a Firefox extens ion corresponding to the entries in [locale_sync] metadata section.' 500 command.description = 'Updates locale files with strings from a Firefox extens ion corresponding to the entries in [locale_sync] metadata section.'
499 command.params = '<firefox_addon_directory>' 501 command.params = '<firefox_addon_directory>'
500 command.supportedTypes = ('chrome') 502 command.supportedTypes = ('chrome')
501 503
502 with addCommand(updatePSL, 'updatepsl') as command: 504 with addCommand(updatePSL, 'updatepsl') as command:
503 command.shortDescription = 'Updates Public Suffix List' 505 command.shortDescription = 'Updates Public Suffix List'
504 command.description = 'Downloads Public Suffix List (see http://publicsuffix.o rg/) and generates lib/publicSuffixList.js from it.' 506 command.description = 'Downloads Public Suffix List (see http://publicsuffix.o rg/) and generates lib/publicSuffixList.js from it.'
505 command.supportedTypes = ('chrome') 507 command.supportedTypes = ('chrome')
506 508
507 def getType(baseDir, args): 509 def getType(baseDir, scriptName, args):
508 # Look for an explicit type parameter 510 # Look for an explicit type parameter (has to be the first parameter)
509 for i in range(len(args)): 511 if len(args) >= 2 and args[0] == '-t':
Felix Dahlke 2013/01/25 08:30:49 Hard coding that -t needs to be the very first par
510 if args[i] == '-t' and i < len(args) - 1: 512 type = args[1]
511 type = args[i + 1] 513 del args[1]
512 del args[i + 1] 514 del args[0]
513 del args[i] 515 if type not in knownTypes:
514 if type not in knownTypes: 516 print '''
515 print '''
516 Unknown type %s specified, supported types are: %s 517 Unknown type %s specified, supported types are: %s
517 ''' % (type, knownTypes) 518 ''' % (type, ', '.join(knownTypes))
518 return None 519 return None
519 else: 520 return type
520 return type
521 521
522 # Try to guess repository type 522 # Try to guess repository type
523 types = [] 523 types = []
524 for t in knownTypes: 524 for t in knownTypes:
525 if os.path.exists(os.path.join(baseDir, 'metadata.%s' % t)): 525 if os.path.exists(os.path.join(baseDir, 'metadata.%s' % t)):
526 types.append(t) 526 types.append(t)
527 527
528 if len(types) == 1: 528 if len(types) == 1:
529 return types[0] 529 return types[0]
530 elif len(types) > 1: 530 elif len(types) > 1:
531 print ''' 531 print '''
532 Ambiguous repository type, please specify -t parameter explicitly, e.g. 532 Ambiguous repository type, please specify -t parameter explicitly, e.g.
533 -t %s 533 %s -t %s build
534 ''' % types[0] 534 ''' % (scriptName, types[0])
535 return None 535 return None
536 else: 536 else:
537 print ''' 537 print '''
538 No metadata file found in this repository, a metadata file like 538 No metadata file found in this repository, a metadata file like
539 metadata.%s is required. 539 metadata.%s is required.
540 ''' % knownTypes[0] 540 ''' % knownTypes[0]
541 return None 541 return None
542 542
543 def processArgs(baseDir, args): 543 def processArgs(baseDir, args):
544 global commands 544 global commands
545 545
546 scriptName = os.path.basename(args[0]) 546 scriptName = os.path.basename(args[0])
547 args = args[1:] 547 args = args[1:]
548 type = getType(baseDir, args) 548 type = getType(baseDir, scriptName, args)
Felix Dahlke 2013/01/25 08:30:49 There's a rogue white space before "args". Utter n
Wladimir Palant 2013/01/25 10:23:49 Fixed that before pushing.
549 if type == None: 549 if type == None:
550 return 550 return
551 551
552 if len(args) == 0: 552 if len(args) == 0:
553 args = ['build'] 553 args = ['build']
554 print ''' 554 print '''
555 No command given, assuming "build". For a list of commands run: 555 No command given, assuming "build". For a list of commands run:
556 556
557 %s help 557 %s help
558 ''' % scriptName 558 ''' % scriptName
(...skipping 11 matching lines...) Expand all
570 if option in ('-h', '--help'): 570 if option in ('-h', '--help'):
571 usage(scriptName, type, command) 571 usage(scriptName, type, command)
572 sys.exit() 572 sys.exit()
573 commands[command](baseDir, scriptName, opts, args, type) 573 commands[command](baseDir, scriptName, opts, args, type)
574 else: 574 else:
575 print 'Command %s is not supported for this application type' % command 575 print 'Command %s is not supported for this application type' % command
576 usage(scriptName, type) 576 usage(scriptName, type)
577 else: 577 else:
578 print 'Command %s is unrecognized' % command 578 print 'Command %s is unrecognized' % command
579 usage(scriptName, type) 579 usage(scriptName, type)
LEFTRIGHT
« no previous file | packager.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld