Beispiel #1
0
def read_config(conf=CONF):
    v("[%s] Reading configuration file" % conf)

    config = configparser.ConfigParser()
    config.read(conf, encoding="UTF-8")

    return config
class init:
    __initialization_modules__ = []

    on_pre_exec = lambda self, session: v('[%s] preInitialization' % session.
                                          init_id)
    on_post_exec = lambda self, session: v('[%s] postInitialization' % session.
                                           init_id)

    class InitSession:
        adb = None
        config = None
        code = None

        init_id = None

        pre = None
        post = None

    def commit(self):
        if self.pre(self) < 0:
            raise RuntimeError("[%s]: ".format(
                self.init_id).join("Pre init failed"))

        if self.code(self) < 0:
            raise RuntimeError("[%s]: ".format(
                self.init_id).join("initialization failed"))

        if self.post(self) < 0:
            raise RuntimeError("[%s]: ".format(
                self.init_id).join("Post init failed"))

    def with_init_id(self, session_id):
        self.init_id = session_id

    def add_to_list(self):
        init.__initialization_modules__.append(self)

    def __init__(self,
                 code: staticmethod,
                 adb=adb_wrapper,
                 config=user_cfg) -> None:
        super().__init__()
        self.init_id = str(randint()).__hash__()
        self.adb = adb
        self.config = config
        self.code = code

        if not code:
            raise AttributeError("Init method object is invalid")

        self.pre = init.on_pre_exec
        self.post = init.on_post_exec

        self.add_to_list()
Beispiel #3
0
def create_default(conf=CONF):
    v("[%s] Creating default configuration file" % conf)

    config = configparser.ConfigParser(allow_no_value=True)
    config.add_section('global')

    root_dict = dict()

    for x in (dict_from_class(Config)):
        class_ = Config.__dict__[x]
        if issubclass(class_.__class__, Config.__base_section__.__class__):
            from_class = dict_from_class(Config.__dict__['__base_section__'],
                                         class_)

            v("Adding section %s with %s fields" % (x, len(from_class)))
            config.add_section(x)

            config[x] = from_class
        else:
            root_dict.update(dict({x: Config.__dict__[x]}))

    config['global'] = root_dict

    config.add_section("INFO")
    version = parameter.adb_wrapper.get_version()
    state = parameter.adb_wrapper.get_state()[0]
    connection_state = (
        "device date: %s" % parameter.adb_wrapper.shell_command("date")[0]
    ) if parameter.adb_wrapper.get_state()[0] == 'device' else "# Disconnected"

    text = '#\n#\n#\n# util for tweaking adb functionality\n#\n#\n#\n' \
           '# adb version: %s\n' \
           '# adb state: %s\n' \
           '# adb %s\n' \
           % (
                str(version),
                str(state),
                str(connection_state)
            )

    text += "#\n"
    text += "#\n"
    text += "#\n"

    config.set("INFO", "")
    config.set("INFO", text)

    with open(conf, "w") as x:
        config.write(x)
 def wipe_tmp(self):
     """directory"""
     if os.path.isdir(variables.tmp_directory):
         io.del_all_in_directory(variables.tmp_directory)
     else:
         v('directory is not exists')
 def wipe_logs(self):
     """logs"""
     if os.path.isdir(variables.logs_directory):
         io.del_all_in_directory(variables.logs_directory)
     else:
         v('directory is not exists')
Beispiel #6
0
def shell_adb(cmd, adb=ADB()):
    v("execute shell command: %s" % cmd)
    remote = adb.shell_command(cmd)
    return remote[0] if remote and len(remote) > 0 else -1
Beispiel #7
0
def connect_adb(wireless_address, adb=ADB()):
    v("Trying to connect to %s " % wireless_address)
    remote = adb.connect_remote(wireless_address)
    return remote[0] if remote and len(remote) > 0 else -1
Beispiel #8
0
def del_all_in_directory(dirpath):
    v('deleting %s ...')
    for file in os.listdir(dirpath):
        os.remove(file)
        v('%s%sremoved!' % (file, ' ' if path.exists(file) else ' not '))