Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
add python -matx webide
Browse files Browse the repository at this point in the history
  • Loading branch information
shengxiang committed Mar 20, 2016
1 parent 4492cea commit 9afddaa
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 13 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
CHANGES
=======

* opencv install add win amd64 easy install method
* add resolution for Pattern, close #3
* depreciated sleep, use delay instead
* move all cli command to direcotry cmds
* fix instance bug
* watch object add func:do
* fix #1
* update secure of travis

1.0.6
-----

* Add desc how to install from source
* better uidump tkgui support
* UI detect update
* support ui dump in ide, which looks very nice
* add gui
* make tkgui save kindly
* add event listener
* update readme example resolution
* analysis all current screen size
* fix gui run code bug
* add parse ui node dump_nodes() function
* update desc
* add auto refresh support
* add screenshot button and d
* update change log

1.0.5
-----

Expand Down
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

4 changes: 0 additions & 4 deletions TODO → TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@

- bounds
- region(left, right, top, bottom)
2. Patten

- filename
- offset
21 changes: 16 additions & 5 deletions atx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# USAGE
# python -matx -s ESLKJXX gui

import functools
import argparse

from atx.cmds import tkgui, minicap, tcpproxy
from atx.cmds import tkgui, minicap, tcpproxy, webide
from atx.cmds import minicap

def _gui(args):
Expand All @@ -20,25 +21,35 @@ def _tcpproxy(args):
tcpproxy.main(local_port=args.forward, listen_port=args.listen)


def _webide(args):
webide.main(open_browser=(not args.no_browser), port=args.web_port)

def main():
ap = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
ap.add_argument("-s", "--serial", required=False, help="Android SerialNo")
ap.add_argument("-H", "--host", required=False, default='127.0.0.1', help="Adb host")
ap.add_argument("-P", "--port", required=False, type=int, default=5037, help="Adb port")

subparsers = ap.add_subparsers()
parser_gui = subparsers.add_parser('gui')
add_parser = functools.partial(subparsers.add_parser,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser_gui = add_parser('gui')
parser_gui.set_defaults(func=_gui)

parser_minicap = subparsers.add_parser('minicap')
parser_minicap = add_parser('minicap')
parser_minicap.set_defaults(func=_minicap)

parser_tcpproxy = subparsers.add_parser('tcpproxy')
parser_tcpproxy = add_parser('tcpproxy')
parser_tcpproxy.add_argument('-l', '--listen', default=5555, type=int, help='Listen port')
parser_tcpproxy.add_argument('-f', '--forward', default=26944, type=int, help='Forwarded port')
parser_tcpproxy.set_defaults(func=_tcpproxy)

parser_webide = add_parser('webide')
parser_webide.add_argument('--no-browser', dest='no_browser', default=False, type=bool, help='Not open browser')
parser_webide.add_argument('--port', dest='web_port', default=None, type=int, help='web listen port')
parser_webide.set_defaults(func=_webide)

args = ap.parse_args()
args.func(args)

Expand Down
3 changes: 3 additions & 0 deletions atx/cmds/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<h1>Hello AirtestX</h1>
</html>
58 changes: 58 additions & 0 deletions atx/cmds/webide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# coding: utf-8

import os
import logging
import webbrowser
import socket

import tornado.ioloop
import tornado.web
from atx import logutils

__dir__ = os.path.dirname(os.path.abspath(__file__))

log = logutils.getLogger("webide")
log.setLevel(logging.DEBUG)


def get_valid_port():
for port in range(10010, 10100):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1', port))
if result != 0:
return port

raise SystemError("Can not find a unused port, amazing!")

class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')


def make_app(settings={}):
application = tornado.web.Application([
(r"/", MainHandler),
], **settings)
return application


def main(**kws):
application = make_app({
'static_path': os.path.join(__dir__, 'static'),
'template_path': os.path.join(__dir__, 'static'),
})
port = kws.get('port', None)
if not port:
port = get_valid_port()

open_browser = kws.get('open_browser', True)
if open_browser:
url = 'http://127.0.0.1:{}'.format(port)
webbrowser.open(url, new=2) # 2: open new tab if possible

application.listen(port)
log.info("Listening port on 127.0.0.1:{}".format(port))
tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
main()

0 comments on commit 9afddaa

Please sign in to comment.