Index: build.py |
=================================================================== |
--- a/build.py |
+++ b/build.py |
@@ -13,16 +13,18 @@ |
# GNU General Public License for more details. |
# |
# You should have received a copy of the GNU General Public License |
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
import os, sys, re, subprocess, buildtools |
from getopt import getopt, GetoptError |
+knownTypes = ('gecko', 'chrome') |
+ |
class Command(object): |
name = property(lambda self: self._name) |
shortDescription = property(lambda self: self._shortDescription, |
lambda self, value: self.__dict__.update({'_shortDescription': value})) |
description = property(lambda self: self._description, |
lambda self, value: self.__dict__.update({'_description': value})) |
params = property(lambda self: self._params, |
lambda self, value: self.__dict__.update({'_params': value})) |
@@ -350,17 +352,17 @@ def generateDocs(baseDir, scriptName, op |
if len(args) == 0: |
print 'No target directory specified for the documentation' |
usage(scriptName, type, 'docs') |
return |
targetDir = args[0] |
toolkit = None |
for option, value in opts: |
- if option in ('-t', '--toolkit'): |
+ if option in ('-k', '--toolkit'): |
toolkit = value |
if toolkit == None: |
toolkit = os.path.join(baseDir, 'jsdoc-toolkit') |
if not os.path.exists(toolkit): |
subprocess.Popen(['hg', 'clone', 'https://hg.adblockplus.org/jsdoc-toolkit/', toolkit]).communicate() |
command = [sys.executable, |
@@ -471,17 +473,17 @@ with addCommand(showDescriptions, 'showd |
command.description = 'Display description strings for all locales as specified in the corresponding meta.properties files.' |
command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3') |
command.params = '[options]' |
command.supportedTypes = ('gecko') |
with addCommand(generateDocs, 'docs') as command: |
command.shortDescription = 'Generate documentation' |
command.description = 'Generate documentation files and write them into the specified directory.' |
- command.addOption('JsDoc Toolkit location', short='t', long='toolkit', value='dir') |
+ command.addOption('JsDoc Toolkit location', short='k', long='toolkit', value='dir') |
command.params = '[options] <directory>' |
command.supportedTypes = ('gecko') |
with addCommand(runReleaseAutomation, 'release') as command: |
command.shortDescription = 'Run release automation' |
command.description = 'Note: If you are not the project owner then you '\ |
'probably don\'t want to run this!\n\n'\ |
'Runs release automation: creates downloads for the new version, tags '\ |
@@ -497,21 +499,61 @@ with addCommand(syncLocales, 'synclocale |
command.params = '<firefox_addon_directory>' |
command.supportedTypes = ('chrome') |
with addCommand(updatePSL, 'updatepsl') as command: |
command.shortDescription = 'Updates Public Suffix List' |
command.description = 'Downloads Public Suffix List (see http://publicsuffix.org/) and generates lib/publicSuffixList.js from it.' |
command.supportedTypes = ('chrome') |
-def processArgs(baseDir, args, type='gecko'): |
+def getType(baseDir, args): |
+ # Look for an explicit type parameter |
+ for i in range(len(args)): |
+ if args[i] == '-t' and i < len(args) - 1: |
+ type = args[i + 1] |
+ del args[i + 1] |
+ del args[i] |
+ if type not in knownTypes: |
+ print ''' |
+Unknown type %s specified, supported types are: %s |
+''' % (type, knownTypes) |
+ return None |
+ else: |
+ return type |
+ |
+ # Try to guess repository type |
+ types = [] |
+ for t in knownTypes: |
+ if os.path.exists(os.path.join(baseDir, 'metadata.%s' % t)): |
+ types.append(t) |
+ |
+ if len(types) == 1: |
+ return types[0] |
+ elif len(types) > 1: |
+ print ''' |
+Ambiguous repository type, please specify -t parameter explicitly, e.g. |
+-t %s |
+''' % types[0] |
+ return None |
+ else: |
+ print ''' |
+No metadata file found in this repository, a metadata file like |
+metadata.%s is required. |
+''' % knownTypes[0] |
+ return None |
+ |
+def processArgs(baseDir, args): |
global commands |
scriptName = os.path.basename(args[0]) |
args = args[1:] |
+ type = getType(baseDir, args) |
+ if type == None: |
+ return |
+ |
if len(args) == 0: |
args = ['build'] |
print ''' |
No command given, assuming "build". For a list of commands run: |
%s help |
''' % scriptName |