class Downloader(PonydCommand): __subcommand__ = 'update-devtools' dirname = Arg(nargs='?', help='path to download and extract devtools (default: %s)' % DEFAULT_DEVTOOLS_PATH, default=DEFAULT_DEVTOOLS_PATH) latest = Arg('-l', '--latest', help='install the lastest dev tools instead of a known good version', action='store_true') def __call__(self): if self.latest: version = urllib2.urlopen(LATEST_URL).read() else: version = 338332 tools_url = TOOLS_URL_TEMPLATE.format(version) print "Downloading %s" % tools_url tools_stream = StringIO(urllib2.urlopen(tools_url).read()) if os.path.exists(self.dirname): print "Removing existing devtools installation at %s" % self.dirname shutil.rmtree(self.dirname) extract_dir = self.dirname print "Extracting to %s" % extract_dir tools_zip = zipfile.ZipFile(tools_stream, 'r') names_to_extract = [n for n in tools_zip.namelist() if n.startswith(INSPECTOR_PATH_PREFIX)] with tempdir() as d: tools_zip.extractall(path=d, members=names_to_extract) os.rename(os.path.join(d, INSPECTOR_PATH_PREFIX), extract_dir)
class Downloader(PonydCommand): __subcommand__ = 'update-devtools' dirname = Arg(nargs='?', help='path to download and extract devtools (default: %s)' % DEFAULT_DEVTOOLS_PATH, default=DEFAULT_DEVTOOLS_PATH) latest = Arg( '-l', '--latest', help='install the lastest dev tools instead of a known good version', action='store_true') def __call__(self): if self.latest: version = urllib2.urlopen(LATEST_URL).read() else: version = 152100 tools_url = TOOLS_URL_TEMPLATE % version print "Downloading %s" % tools_url tools_stream = StringIO(urllib2.urlopen(tools_url).read()) if os.path.exists(self.dirname): print "Removing existing devtools installation at %s" % self.dirname shutil.rmtree(self.dirname) extract_dir = self.dirname print "Extracting to %s" % extract_dir tools_zip = zipfile.ZipFile(tools_stream, 'r') tools_zip.extractall(path=extract_dir)
class Gateway(PonydCommand): """Runs PonyDebugger's gateway""" __subcommand__ = 'serve' default_static_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'web')) verbose = Arg('-v', '--verbose', help='verbose logging', action='store_true') static_path = Arg('-s', '--static-path', help='path for static files [default: %(default)s]', default=default_static_path) devtools_path = Arg('-d', '--devtools-path', help='path for dev tools/inspector [default: %(default)s]', default=DEFAULT_DEVTOOLS_PATH) listen_port = Arg('-p', '--listen-port', help='port to listen on [default: %(default)s]', default=9000, type=int, metavar='PORT') listen_interface = Arg('-i', '--listen-interface', help='interface to listen on. [default: %(default)s]', default='127.0.0.1', metavar='IFACE') bonjour_name = Arg('-b', '--bonjour-name', help='name of the bonjour service. [default: %(default)s]', default='Pony Gateway') def __call__(self): if not os.path.exists(self.devtools_path): print "Error: devtools directory %s does not exist. Use 'ponyd update-devtools' to download a compatible version of Chrome Developer Tools." % self.devtools_path return if self.verbose: tornado.options.options.logging = 'debug' tornado.log.enable_pretty_logging(options=tornado.options.options) logger = logging.getLogger() logger.setLevel(logging.DEBUG) application = tornado.web.Application([ (r"/devtools/page/([0-9]*)/?", DevToolsHandler), (r"/lobby", LobbyHandler), (r"/device", DeviceHandler), (r"/devtools/(.*)", tornado.web.StaticFileHandler, {"path": self.devtools_path}), (r"/(.*)", tornado.web.StaticFileHandler, {"path": self.static_path, "default_filename": 'index.html'}), ]) print "PonyGateway starting. Listening on http://%s:%s" % (self.listen_interface, self.listen_port) bonjour.register_service(self.bonjour_name, "_ponyd._tcp", self.listen_port) application.listen(self.listen_port, self.listen_interface) ioloop = tornado.ioloop.IOLoop.instance() ioloop.start()
class Downloader(PonydCommand): __subcommand__ = 'update-devtools' dirname = Arg(nargs='?', help='path to download and extract devtools (default: %s)' % DEFAULT_DEVTOOLS_PATH, default=DEFAULT_DEVTOOLS_PATH) latest = Arg('-l', '--latest', help='install the lastest dev tools instead of a known good version', action='store_true') def __call__(self): if self.latest: version = urllib2.urlopen(LATEST_URL).read() else: # Protocol: https://chromium.googlesource.com/chromium/src/+/6f91eb9692b1fbb8839a0dbf9b0f3c5b10117b62/third_party/WebKit/Source/core/inspector/browser_protocol.json version = 464644 tools_url = TOOLS_URL_TEMPLATE.format(version) print "Downloading %s" % tools_url tools_stream = StringIO(urllib2.urlopen(tools_url).read()) if os.path.exists(self.dirname): print "Removing existing devtools installation at %s" % self.dirname shutil.rmtree(self.dirname) extract_dir = self.dirname print "Extracting to %s" % extract_dir tools_zip = zipfile.ZipFile(tools_stream, 'r') names_to_extract = [n for n in tools_zip.namelist() if n.startswith(INSPECTOR_PATH_PREFIX)] with tempdir() as d: tools_zip.extractall(path=d, members=names_to_extract) os.rename(os.path.join(d, INSPECTOR_PATH_PREFIX), extract_dir)