Bug 675123 - move config.json into virtualenv, a=testonly, DONTBUILD
authorJonathan Griffin <jgriffin@mozilla.com>
Wed, 03 Aug 2011 17:23:15 -0700
changeset 74451 70994f9acb3a53636e70d1c3ebf109d9cf57ba98
parent 74072 aca5afbed1883d081218aeb1d99c6f6ef5cfa2ba
child 74452 3c22aef81976413404c4e068fb9abd637c72f4d1
push idunknown
push userunknown
push dateunknown
reviewerstestonly, DONTBUILD
bugs675123
milestone8.0a1
Bug 675123 - move config.json into virtualenv, a=testonly, DONTBUILD
testing/tps/INSTALL.sh
testing/tps/config.json
testing/tps/config/README.txt
testing/tps/config/config.json.in
testing/tps/setup.py
testing/tps/tps/cli.py
old mode 100644
new mode 100755
--- a/testing/tps/INSTALL.sh
+++ b/testing/tps/INSTALL.sh
@@ -50,22 +50,41 @@ cd ${TARGET}
 if [ -z "${VIRTUAL_ENV}" ]
 then
     echo "virtualenv wasn't installed correctly, aborting"
     exit 1
 fi
 
 # install TPS
 cd ${CWD}
-python setup.py develop
+python setup.py install
 
 if [ "$?" -gt 0 ]
 then
   exit 1
 fi
 
+CONFIG="`find ${VIRTUAL_ENV} -name config.json.in`"
+NEWCONFIG=${CONFIG:0:${#CONFIG}-3}
+
+cd "../../services/sync/tests/tps"
+TESTDIR="`pwd`"
+
+cd "../../tps"
+EXTDIR="`pwd`"
+
+sed 's|__TESTDIR__|'"${TESTDIR}"'|' "${CONFIG}" | sed 's|__EXTENSIONDIR__|'"${EXTDIR}"'|' > "${NEWCONFIG}"
+rm ${CONFIG}
+
+echo
+echo "***********************************************************************"
 echo
 echo "To run TPS, activate the virtualenv using:"
 echo "  source ${TARGET}/${BIN_NAME}"
 echo "then execute tps using:"
 echo "  runtps --binary=/path/to/firefox"
 echo
 echo "See runtps --help for all options"
+echo
+echo "To change your TPS config, please edit the file: "
+echo "${NEWCONFIG}"
+echo
+echo "***********************************************************************"
deleted file mode 100644
--- a/testing/tps/config.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{ 
-  "account": {
-    "serverURL": "",
-    "admin-secret": "",
-    "username": "crossweaveservices@mozilla.com",
-    "password": "crossweaveservicescrossweaveservices",
-    "passphrase": "r-jwcbc-zgf42-fjn72-p5vpp-iypmi"
-  },
-  "resultstore": {
-    "host": "brasstacks.mozilla.com",
-    "path": "/resultserv/post/"
-  },
-  "email": {
-    "username": "crossweave@mozilla.com",
-    "password": "",
-    "passednotificationlist": ["crossweave@mozilla.com"],
-    "notificationlist": ["crossweave@mozilla.com"]
-  },
-  "platform": "win32",
-  "os": "win7",
-  "es": "localhost:9200"
-}
-
new file mode 100644
--- /dev/null
+++ b/testing/tps/config/README.txt
@@ -0,0 +1,7 @@
+To edit the TPS configuration, do not edit config.json.in in the tree. 
+Instead, edit config.json inside your virtualenv; it will be located at
+something like:
+
+  (linux): /path/to/virtualenv/lib/python2.6/site-packages/tps-0.2.40-py2.6.egg/tps/config.json
+  (win): /path/to/virtualenv/Lib/site-packages/tps-0.2.40-py2.6.egg/tps/config.json
+
new file mode 100644
--- /dev/null
+++ b/testing/tps/config/config.json.in
@@ -0,0 +1,25 @@
+{ 
+  "account": {
+    "serverURL": "",
+    "admin-secret": "",
+    "username": "crossweaveservices@mozilla.com",
+    "password": "crossweaveservicescrossweaveservices",
+    "passphrase": "r-jwcbc-zgf42-fjn72-p5vpp-iypmi"
+  },
+  "resultstore": {
+    "host": "brasstacks.mozilla.com",
+    "path": "/resultserv/post/"
+  },
+  "email": {
+    "username": "crossweave@mozilla.com",
+    "password": "",
+    "passednotificationlist": ["crossweave@mozilla.com"],
+    "notificationlist": ["crossweave@mozilla.com"]
+  },
+  "platform": "win32",
+  "os": "win7",
+  "es": "localhost:9200",
+  "testdir": "__TESTDIR__",
+  "extensiondir": "__EXTENSIONDIR__"
+}
+
--- a/testing/tps/setup.py
+++ b/testing/tps/setup.py
@@ -53,23 +53,26 @@ setup(name='tps',
       version=version,
       description='run automated multi-profile sync tests',
       long_description="""\
 """,
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Jonathan Griffin',
       author_email='jgriffin@mozilla.com',
-      url='http://hg.mozilla.org/services/tps',
+      url='http://hg.mozilla.org/services/services-central',
       license='MPL',
       dependency_links = [
          "http://people.mozilla.org/~jgriffin/packages/"
       ],
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,
       zip_safe=False,
       install_requires=deps,
       entry_points="""
       # -*- Entry points: -*-
       [console_scripts]
       runtps = tps.cli:main
       """,
+      data_files=[
+        ('tps', ['config/config.json.in']),
+      ],
       )
--- a/testing/tps/tps/cli.py
+++ b/testing/tps/tps/cli.py
@@ -33,16 +33,17 @@
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 import json
 import optparse
 import os
+import sys
 import logging
 
 from threading import RLock
 
 from tps import TPSFirefoxRunner, TPSPulseMonitor, TPSTestRunner
 
 def main():
   parser = optparse.OptionParser()
@@ -71,35 +72,53 @@ def main():
   parser.add_option("--binary",
                     action = "store", type = "string", dest = "binary",
                     default = None,
                     help = "path to the Firefox binary, specified either as "
                            "a local file or a url; if omitted, the PATH "
                            "will be searched;")
   parser.add_option("--configfile",
                     action = "store", type = "string", dest = "configfile",
-                    default = "config.json",
+                    default = None,
                     help = "path to the config file to use "
                            "[default: %default]")
   parser.add_option("--pulsefile",
                     action = "store", type = "string", dest = "pulsefile",
                     default = None,
                     help = "path to file containing a pulse message in "
                            "json format that you want to inject into the monitor")
   (options, args) = parser.parse_args()
 
+  configfile = options.configfile
+  if configfile is None:
+    if os.environ.get('VIRTUAL_ENV'):
+      configfile = os.path.join(os.path.dirname(__file__), 'config.json')
+    else:
+      raise Exception("Unable to find config.json in a VIRTUAL_ENV; you must "
+                      "specify a config file using the --configfile option")
+
   # load the config file
-  f = open(options.configfile, 'r')
+  f = open(configfile, 'r')
   configcontent = f.read()
   f.close()
   config = json.loads(configcontent)
 
   rlock = RLock()
  
-  extensionDir = os.path.join(os.getcwd(), "..", "..", "services", "sync", "tps")
+  extensionDir = config.get("extensiondir")
+  if not extensionDir or extensionDir == '__EXTENSIONDIR__':
+    extensionDir = os.path.join(os.getcwd(), "..", "..", "services", "sync", "tps")
+  else:
+    if sys.platform == 'win32':
+      # replace msys-style paths with proper Windows paths
+      import re
+      m = re.match('^\/\w\/', extensionDir)
+      if m:
+        extensionDir = "%s:/%s" % (m.group(0)[1:2], extensionDir[3:])
+        extensionDir = extensionDir.replace("/", "\\")
 
   if options.binary is None:
     # If no binary is specified, start the pulse build monitor, and wait
     # until we receive build notifications before running tests.
     monitor = TPSPulseMonitor(extensionDir,
                               config=config,
                               autolog=options.autolog,
                               emailresults=options.emailresults,