[Pkg-mozext-commits] [adblock-plus] 147/464: Changed command line arguments for build.py and turned it into a replacement for setupTestEnvironment.pl as well

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:12 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 89eaa336df80a5d6cd539e1f65710f703fa052aa
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Mon May 16 16:38:01 2011 +0200

    Changed command line arguments for build.py and turned it into a replacement for setupTestEnvironment.pl as well
---
 build.py    | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 packager.py | 55 +++++++++++++++++++++++++++++++++-
 2 files changed, 139 insertions(+), 14 deletions(-)

diff --git a/build.py b/build.py
index 5eb6a4a..47cca04 100644
--- a/build.py
+++ b/build.py
@@ -9,11 +9,13 @@ import os, sys
 from getopt import getopt, GetoptError
 import buildtools.packager as packager
 
-def usage():
-  print '''Usage: %s [output_file]
+def usage_build(scriptName):
+  print '''%(name)s build [options] [output_file]
+
+Creates an extension build with given file name. If output_file is missing a
+default name will be chosen.
 
 Options:
-  -h          --help              Print this message and exit
   -l l1,l2,l3 --locales=l1,l2,l3  Only include the given locales (if omitted:
                                   all locales not marked as incomplete)
   -b num      --build=num         Use given build number (if omitted the build
@@ -22,14 +24,14 @@ Options:
                                   required to sign the package
   -r          --release           Create a release build
               --babelzilla        Create a build for Babelzilla
-''' % os.path.basename(sys.argv[0])
+''' % {"name": scriptName}
 
-def processArgs(baseDir, args):
+def runBuild(baseDir, scriptName, args):
   try:
-    opts, args = getopt(sys.argv[1:], 'hl:b:k:r', ['help', 'locales', 'build=', 'key=', 'release', 'babelzilla'])
+    opts, args = getopt(args, 'hl:b:k:r:', ['help', 'locales', 'build=', 'key=', 'release', 'babelzilla'])
   except GetoptError, e:
     print str(e)
-    usage()
+    usage_build(scriptName)
     sys.exit(2)
 
   locales = None
@@ -39,8 +41,8 @@ def processArgs(baseDir, args):
   limitMetadata = False
   for option, value in opts:
     if option in ('-h', '--help'):
-      usage()
-      sys.exit()
+      usage_build(scriptName)
+      return
     elif option in ('-l', '--locales'):
       locales = value.split(',')
     elif option in ('-b', '--build'):
@@ -52,11 +54,81 @@ def processArgs(baseDir, args):
     elif option == '--babelzilla':
       locales = 'all'
       limitMetadata = True
-
-  outFile = None
-  if len(args) >= 1:
-    outFile = args[0]
+  outFile = args[0] if len(args) > 0 else None
 
   packager.createBuild(baseDir, outFile=outFile, locales=locales, buildNum=buildNum,
                        releaseBuild=releaseBuild, keyFile=keyFile,
                        limitMetadata=limitMetadata)
+
+
+def usage_testenv(scriptName):
+  print '''%(name)s testenv [options] [profile_dir] ...
+
+Sets up the extension in given profiles in such a way that most files are read
+from the current directory. Changes in the files here will be available to these
+profiles immediately after a restart without having to reinstall the extension.
+If no directories are given the list of directories is read from a file.
+
+Options
+  -d file     --dirs=file         File listing profile directories to set up if
+                                  none are given on command line (default is
+                                  .profileDirs)
+''' % {"name": scriptName}
+
+def setupTestEnvironment(baseDir, scriptName, args):
+  try:
+    opts, args = getopt(args, 'hd:', ['help', 'dirs='])
+  except GetoptError, e:
+    print str(e)
+    usage_testenv(scriptName)
+    sys.exit(2)
+
+  dirsFile = '.profileDirs'
+  for option, value in opts:
+    if option in ('-h', '--help'):
+      usage_testenv(scriptName)
+      return
+    elif option in ('-d', '--dirs'):
+      dirsFile = value
+
+  profileDirs = args
+  if len(profileDirs) == 0:
+    handle = open(dirsFile, 'rb')
+    profileDirs = map(str.strip, handle.readlines())
+    handle.close()
+  packager.setupTestEnvironment(baseDir, profileDirs)
+
+
+def usage(scriptName):
+  print '''Usage:
+
+  %(name)s help                                   Show this message
+  %(name)s build [options] [output_file]          Create a build
+  %(name)s testenv [options] [profile_dir] ...    Set up test environment
+
+For details on a command run:
+
+  %(name)s <command> --help
+''' % {"name": scriptName}
+
+def processArgs(baseDir, args):
+  scriptName = os.path.basename(args[0])
+  args = args[1:]
+  if len(args) == 0:
+    args = ['build']
+    print '''
+No command given, assuming "build". For a list of commands run:
+
+  %s help
+''' % scriptName
+
+  command = args[0]
+  if command == 'help':
+    usage(scriptName)
+  elif command == 'build':
+    runBuild(baseDir, scriptName, args[1:])
+  elif command == 'testenv':
+    setupTestEnvironment(baseDir, scriptName, args[1:])
+  else:
+    print 'Command %s is unrecognized' % command
+    usage(scriptName)
diff --git a/packager.py b/packager.py
index d557f80..3d17cb0 100644
--- a/packager.py
+++ b/packager.py
@@ -5,7 +5,7 @@
 # compliance with the License. You may obtain a copy of the License at
 # http://www.mozilla.org/MPL/
 
-import os, re, subprocess, jinja2, buildtools, codecs, hashlib, base64
+import os, sys, re, subprocess, jinja2, buildtools, codecs, hashlib, base64, shutil
 from ConfigParser import SafeConfigParser
 from StringIO import StringIO
 from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
@@ -50,6 +50,9 @@ def getChromeSubdirs(baseDir, locales):
 def getXPIFiles(baseDir):
   return [os.path.join(baseDir, file) for file in ('components', 'modules', 'defaults', 'bootstrap.js', 'chrome.manifest', 'icon.png', 'icon64.png')]
 
+def getTestEnvFiles(baseDir):
+  return [os.path.join(baseDir, file) for file in ('components', 'defaults', 'bootstrap.js', 'chrome.manifest', 'icon.png', 'icon64.png')]
+
 def getIgnoredFiles(params):
   result = ['tests', 'mochitest', '.incomplete', 'meta.properties']
   if params['releaseBuild']:
@@ -300,3 +303,53 @@ def createBuild(baseDir, outFile=None, locales=None, buildNum=None, releaseBuild
   if keyFile:
     signFiles(files, keyFile)
   writeXPI(files, outFile)
+
+def setupTestEnvironment(baseDir, profileDirs):
+  metadata = readMetadata(baseDir)
+  params = {
+    'locales': getLocales(baseDir, True),
+    'releaseBuild': True,
+    'buildNum': '',
+    'version': '99.9',
+    'metadata': metadata,
+    'limitMetadata': False,
+  }
+  files = {}
+  files['install.rdf'] = createManifest(baseDir, params)
+  for path in getTestEnvFiles(baseDir):
+    if os.path.exists(path):
+      readFile(files, params, path, os.path.basename(path))
+
+  if 'chrome.manifest' in files:
+    # Redirect manifest entries to the current directory
+    if sys.platform == 'win32':
+      import nturl2path
+      baseURL = 'file:' + nturl2path.pathname2url(os.path.abspath(baseDir))
+    else:
+      import urllib
+      baseURL = 'file://' + urllib.quote(os.path.abspath(baseDir))
+    files['chrome.manifest'] = re.sub(r'\bjar:chrome/\w+\.jar!', '%s/chrome' % baseURL, files['chrome.manifest'])
+    files['chrome.manifest'] = re.sub(r'\bresource\s+\S+\s+', r'\0%s/' % baseURL, files['chrome.manifest'])
+    files['chrome.manifest'] = re.sub(r'\b(content\s+\S+\s+)(\w+/)', r'\1%s/\2' % baseURL, files['chrome.manifest'])
+    if os.path.exists(os.path.join(baseDir, 'chrome', 'content', 'mochitest')):
+      files['chrome.manifest'] += 'content mochikit %s/chrome/content/mochitest/\n' % baseURL
+
+  id = metadata.get('general', 'id')
+  for dir in profileDirs:
+    # Remove packed XPI file if there is one
+    packedPath = os.path.join(dir, 'extensions', '%s.xpi' % id)
+    if os.path.isfile(packedPath):
+      os.remove(packedPath)
+
+    # Replace unpacked dir by new data
+    unpackedPath = os.path.join(dir, 'extensions', id)
+    if os.path.isdir(unpackedPath):
+      shutil.rmtree(unpackedPath)
+    for file, data in files.iteritems():
+      filePath = os.path.join(unpackedPath, *(file.split('/')))
+      parentDir = os.path.dirname(filePath)
+      if not os.path.exists(parentDir):
+        os.makedirs(parentDir)
+      handle = open(filePath, 'wb')
+      handle.write(data)
+      handle.close()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list