Пример #1
0
    def type(self, text, enter=False, next=False):
        """Input some text, this method has been tested not very stable on some device.
        "Hi world" maybe spell into "H iworld"

        Args:
            - text: string (text to input), better to be unicode
            - enter(bool): input enter at last
            - next(bool): perform editor action Next

        The android source code show that
        space need to change to %s
        insteresting thing is that if want to input %s, it is really unconvinent.
        android source code can be found here.
        https://android.googlesource.com/platform/frameworks/base/+/android-4.4.2_r1/cmds/input/src/com/android/commands/input/Input.java#159
        app source see here: https://github.com/openatx/android-unicode
        """
        utext = strutils.decode(text)
        if self.prepare_ime():
            estext = base64.b64encode(utext.encode('utf-7'))
            self.adb_shell([
                'am', 'broadcast', '-a', 'ADB_INPUT_TEXT', '--es', 'format',
                'base64', '--es', 'msg', estext
            ])
        else:
            self._shell_type(utext)

        if enter:
            self.keyevent('KEYCODE_ENTER')
        if next:
            # FIXME(ssx): maybe KEYCODE_NAVIGATE_NEXT
            self.adb_shell([
                'am', 'broadcast', '-a', 'ADB_EDITOR_CODE', '--ei', 'code', '5'
            ])
Пример #2
0
 def raw_cmd(self, *args, **kwargs):
     '''adb command. return the subprocess.Popen object.'''
     cmds = [self.adb_path()] + self._host_port_args + list(args)
     kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE)
     kwargs['stderr'] = kwargs.get('stderr', subprocess.PIPE)
     # if os.name != "nt":
     #     cmd_line = [" ".join(cmd_line)]
     cmds = [strutils.decode(v) for v in cmds]
     return subprocess.Popen(cmds, **kwargs)
Пример #3
0
def list_all_image(path, valid_exts=VALID_IMAGE_EXTS):
    """List all images under path

    @return unicode list
    """
    for filename in os.listdir(path):
        bname, ext = os.path.splitext(filename)
        if ext.lower() not in VALID_IMAGE_EXTS:
            continue
        filepath = os.path.join(path, filename)
        yield strutils.decode(filepath)
Пример #4
0
def list_all_image(path, valid_exts=VALID_IMAGE_EXTS):
    """List all images under path

    @return unicode list
    """
    for filename in os.listdir(path):
        bname, ext = os.path.splitext(filename)
        if ext.lower() not in VALID_IMAGE_EXTS:
            continue
        filepath = os.path.join(path, filename)
        yield strutils.decode(filepath)
Пример #5
0
def list_images(path=['.']):
    """ Return list of image files """
    for image_dir in set(path):
        if not os.path.isdir(image_dir):
            continue
        for filename in os.listdir(image_dir):
            bname, ext = os.path.splitext(filename)
            if ext.lower() not in VALID_IMAGE_EXTS:
                continue

            filepath = os.path.join(image_dir, filename)
            yield strutils.decode(filepath)
Пример #6
0
def list_images(path=['.']):
    """ Return list of image files """
    for image_dir in set(path):
        if not os.path.isdir(image_dir):
            continue
        for filename in os.listdir(image_dir):
            bname, ext = os.path.splitext(filename)
            if ext.lower() not in VALID_IMAGE_EXTS:
                continue

            filepath = os.path.join(image_dir, filename)
            yield strutils.decode(filepath)
Пример #7
0
def search_image(name=None, path=['.']):
    """
    look for the image real path, if name is None, then return all images under path.

    @return system encoded path string
    FIXME(ssx): this code is just looking wired.
    """
    name = strutils.decode(name)
    for image_dir in path:
        if not os.path.isdir(image_dir):
            continue
        image_dir = strutils.decode(image_dir)
        image_path = os.path.join(image_dir, name)
        if os.path.isfile(image_path):
            return strutils.encode(image_path)

        for image_path in list_all_image(image_dir):
            if not image_name_match(name, image_path):
                continue
            return strutils.encode(image_path)
    return None
Пример #8
0
def search_image(name=None, path=['.']):
    """
    look for the image real path, if name is None, then return all images under path.

    @return system encoded path string
    FIXME(ssx): this code is just looking wired.
    """
    name = strutils.decode(name)
    for image_dir in path:
        if not os.path.isdir(image_dir):
            continue
        image_dir = strutils.decode(image_dir)
        image_path = os.path.join(image_dir, name)
        if os.path.isfile(image_path):
            return strutils.encode(image_path)

        for image_path in list_all_image(image_dir):
            if not image_name_match(name, image_path):
                continue
            return strutils.encode(image_path)
    return None
Пример #9
0
    def type(self, text, enter=False, next_=False):
        utext = strutils.decode(text)
        if self.prepare_ime():
            estext = base64.b64encode(utext.encode('utf-7'))
            self.adb_shell([
                'am', 'broadcast', '-a', 'ADB_INPUT_TEXT', '--es', 'format',
                'base64', '--es', 'msg', estext
            ])
        else:
            self._shell_type(utext)

        if enter:
            self.keyevent('KEYCODE_ENTER')
        if next_:
            # FIXME(ssx): maybe KEYCODE_NAVIGATE_NEXT
            self.adb_shell([
                'am', 'broadcast', '-a', 'ADB_EDITOR_CODE', '--ei', 'code', '5'
            ])
Пример #10
0
    def _level_write(self, level, str_format, *args):
        if level < self._level:
            return

        levelname = logging.getLevelName(level)
        message = str_format % args if args else str_format
        message = strutils.decode(message)
        frame, filename, line_number, function_name, lines, index = inspect.stack()[2]
        props = dict(
            asctime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3],
            name=self._name,
            filename=os.path.basename(filename),
            lineno=line_number,
            message=message,
        )
        props['levelname'] = Logger.__alias.get(levelname, levelname)
        output = u'{asctime} {levelname:<5s} [{name}:{lineno:>4}] {message}'.format(**props)
        self._write(strutils.encode(output, 'utf-8'))
Пример #11
0
    def _level_write(self, level, str_format, *args):
        if level < self._level:
            return

        levelname = logging.getLevelName(level)
        message = str_format % args if args else str_format
        message = strutils.decode(message)
        frame, filename, line_number, function_name, lines, index = inspect.stack()[2]
        props = dict(
            asctime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3],
            name=self._name,
            filename=os.path.basename(filename),
            lineno=line_number,
            message=message,
        )
        props['levelname'] = Logger.__alias.get(levelname, levelname)
        output = u'{asctime} {levelname:<5s} [{name}:{lineno:>4}] {message}'.format(**props)
        self._write(output)
Пример #12
0
def clean_path(filepath):
    return os.path.normpath(os.path.relpath(strutils.decode(filepath)))
Пример #13
0
def clean_path(filepath):
    return os.path.normpath(os.path.relpath(strutils.decode(filepath)))