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

Commit

Permalink
fix stupid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 14, 2016
1 parent f92459a commit ef8b9b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion atx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
def main():
ap = argparse.ArgumentParser()
ap.add_argument("-s", "--serial", required=False, help="Android serialno")
ap.add_argument("-H", "--host", required=False, default='127.0.0.1', help="Android serialno")
args = ap.parse_args()
tkgui.main(args.serial)
tkgui.main(args.serial, host=args.host)

if __name__ == '__main__':
main()
Expand Down
15 changes: 10 additions & 5 deletions atx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import logging
import threading

random.seed(time.time())

def id_generator(n=5):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))


def dirname(name):
if os.path.isabs(name):
return os.path.dirname(name)
Expand All @@ -34,18 +40,18 @@ def exec_cmd(*cmds, **kwargs):
shell = kwargs.get('shell', False)
try:
import sh
log.debug('RUN(timeout=%ds): %s'%(timeout, ' '.join(cmds)))
# log.debug('RUN(timeout=%ds): %s'%(timeout, ' '.join(cmds)))
if shell:
cmds = list(cmds)
cmds[:0] = ['bash', '-c']
c = sh.Command(cmds[0])
try:
r = c(*cmds[1:], _err_to_out=True, _out=sys.stdout, _env=env, _timeout=timeout)
except:
log.error('EXEC_CMD error, cmd: %s'%(' '.join(cmds)))
# log.error('EXEC_CMD error, cmd: %s'%(' '.join(cmds)))
raise
except ImportError:
log.debug('RUN(timeout=XX): %s'%(' '.join(cmds)))
# log.debug('RUN(timeout=XX): %s'%(' '.join(cmds)))
if shell:
cmds = ' '.join(cmds)
r = subprocess.Popen(cmds, env=env, stdout=sys.stdout, stderr=sys.stderr, shell=shell)
Expand All @@ -58,5 +64,4 @@ def random_name(name):
if c == 'X':
c = random.choice(string.ascii_lowercase)
out.append(c)
return ''.join(out)

return ''.join(out)
8 changes: 5 additions & 3 deletions atx/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from atx import consts
from atx import errors
from atx import patch
from atx import base
from atx import logutils
from atx import imutils

Expand Down Expand Up @@ -243,7 +244,7 @@ def click_image(self, img, timeout=20.0, wait_change=False):
Raises:
ImageNotFoundError: An error occured when img not found in current screen.
"""
search_img = self._read_img(img)
search_img = imutils.open(img)
log.info('touch image: %s', img)
start_time = time.time()
found = False
Expand Down Expand Up @@ -293,6 +294,7 @@ def __init__(self, serialno=None, **kwargs):
UiaDevice.__init__(self, serialno, **kwargs)
CommonWrap.__init__(self)

self._randid = base.id_generator(5)
self._serial = serialno
self._uiauto = super(AndroidDevice, self)

Expand Down Expand Up @@ -346,9 +348,9 @@ def _minicap_params(self):
x=self.display.width,
y=self.display.height,
r=rotation*90)

def _screenshot_minicap(self):
phone_tmp_file = '/data/local/tmp/_atx_screen.jpg'
phone_tmp_file = '/data/local/tmp/_atx_screen-{}.jpg'.format(self._randid)
local_tmp_file = tempfile.mktemp(prefix='atx-tmp-', suffix='.jpg')
command = 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {} -s > {}'.format(
self._minicap_params(), phone_tmp_file)
Expand Down
1 change: 1 addition & 0 deletions atx/imutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def open(image):
img = cv2.imread(name)
if img is None:
raise IOError("Image format error: %s" % name)
return img
raise IOError("Open image(%s) not found" % name)

return image
Expand Down
4 changes: 2 additions & 2 deletions atx/tkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def mainloop(self):
self._root.mainloop()


def main(serial):
d = atx.connect(serial)
def main(serial, **kwargs):
d = atx.connect(serial, **kwargs)
gui = CropIDE('AirtestX IDE SN: %s' % serial, screenshot=d.screenshot)
gui.draw_image(d.screenshot())
gui.mainloop()
Expand Down

0 comments on commit ef8b9b6

Please sign in to comment.