Back to index

enigmail  1.4.3
profileserver.py
Go to the documentation of this file.
00001 #literal #!/usr/bin/python
00002 #
00003 # ***** BEGIN LICENSE BLOCK *****
00004 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005 #
00006 # The contents of this file are subject to the Mozilla Public License Version
00007 # 1.1 (the "License"); you may not use this file except in compliance with
00008 # the License. You may obtain a copy of the License at
00009 # http://www.mozilla.org/MPL/
00010 #
00011 # Software distributed under the License is distributed on an "AS IS" basis,
00012 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 # for the specific language governing rights and limitations under the
00014 # License.
00015 #
00016 # The Original Code is mozilla.org code.
00017 #
00018 # The Initial Developer of the Original Code is
00019 # the Mozilla Foundation.
00020 # Portions created by the Initial Developer are Copyright (C) 1998
00021 # the Initial Developer. All Rights Reserved.
00022 #
00023 # Contributor(s):
00024 #   Robert Sayre <sayrer@gmail.com>
00025 #   Jeff Walden <jwalden+bmo@mit.edu>
00026 #
00027 # Alternatively, the contents of this file may be used under the terms of
00028 # either the GNU General Public License Version 2 or later (the "GPL"), or
00029 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030 # in which case the provisions of the GPL or the LGPL are applicable instead
00031 # of those above. If you wish to allow use of your version of this file only
00032 # under the terms of either the GPL or the LGPL, and not to allow others to
00033 # use your version of this file under the terms of the MPL, indicate your
00034 # decision by deleting the provisions above and replace them with the notice
00035 # and other provisions required by the GPL or the LGPL. If you do not delete
00036 # the provisions above, a recipient may use your version of this file under
00037 # the terms of any one of the MPL, the GPL or the LGPL.
00038 #
00039 # ***** END LICENSE BLOCK *****
00040 
00041 import SimpleHTTPServer
00042 import SocketServer
00043 import socket
00044 import threading
00045 import os
00046 import sys
00047 import shutil
00048 from datetime import datetime
00049 
00050 SCRIPT_DIR = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
00051 sys.path.insert(0, SCRIPT_DIR)
00052 from automation import Automation
00053 from automationutils import getDebuggerInfo, addCommonOptions
00054 
00055 PORT = 8888
00056 PROFILE_DIRECTORY = os.path.abspath(os.path.join(SCRIPT_DIR, "./pgoprofile"))
00057 MOZ_JAR_LOG_DIR = os.path.abspath(os.getenv("JARLOG_DIR"))
00058 os.chdir(SCRIPT_DIR)
00059 
00060 class EasyServer(SocketServer.TCPServer):
00061   allow_reuse_address = True
00062 
00063 if __name__ == '__main__':
00064   from optparse import OptionParser
00065   automation = Automation()
00066 
00067   parser = OptionParser()
00068   addCommonOptions(parser)
00069 
00070   options, args = parser.parse_args()
00071 
00072   debuggerInfo = getDebuggerInfo(".", options.debugger, options.debuggerArgs,
00073           options.debuggerInteractive)
00074 
00075   httpd = EasyServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
00076   t = threading.Thread(target=httpd.serve_forever)
00077   t.setDaemon(True) # don't hang on exit
00078   t.start()
00079   
00080   automation.setServerInfo("localhost", PORT)
00081   automation.initializeProfile(PROFILE_DIRECTORY)
00082   browserEnv = automation.environment()
00083   browserEnv["XPCOM_DEBUG_BREAK"] = "warn"
00084   browserEnv["MOZ_JAR_LOG_DIR"] = MOZ_JAR_LOG_DIR
00085 
00086   url = "http://localhost:%d/index.html" % PORT
00087   appPath = os.path.join(SCRIPT_DIR, automation.DEFAULT_APP)
00088   status = automation.runApp(url, browserEnv, appPath, PROFILE_DIRECTORY, {},
00089                              debuggerInfo=debuggerInfo,
00090                              # the profiling HTML doesn't output anything,
00091                              # so let's just run this without a timeout
00092                              timeout = None)
00093   sys.exit(status)