Esempio n. 1
0
def set_boot_mode():
    print(print_as_a_list_item(0, '清除模式', '注意: 清除引导程序 boot.py, 这将导致程序无法启动!'))
    print(print_as_a_list_item(1, 'WiFi模式', '此选项适合稳定程序使用!'))
    print(print_as_a_list_item(2, '开发者模式', '启动连接WIFI热点,并开启WebREPL开发模式'))

    mode = selection('请选择模式 [0-2]: ', 2)

    with open('boot.py', 'w') as f:
        if mode == BOOT_MODE.WITH_NOTHING:
            boot_code = ''
            f.write(boot_code)
            print(rainbow('已设置为清除模式', color='green'))
        elif mode == BOOT_MODE.WITH_WIFI_STARTUP:
            boot_code = BOOT_MODE.WITH_WIFI_STARTUP_CODE
            f.write(boot_code)
            print(rainbow('已设置为WiFi模式', color='green'))

        elif mode == BOOT_MODE.EASY_DEVELOP:
            config_path()
            if not 'webrepl.pass' in os.listdir('config'):
                with open('config/webrepl.pass', 'w') as c:
                    c.write('123456')
            boot_code = BOOT_MODE.EASY_DEVELOP_CODE
            f.write(boot_code)
            print(rainbow('已设置为开发者模式', color='green'))

    reboot()
Esempio n. 2
0
    def set_default(cls, essid):
        config = cls.read_config()
        records = config.get('records')

        for index, item in enumerate(records):
            print(print_as_a_list_item(index, item))

        default = selection('请选择一个选项作为默认wifi连接 [0-%s]' % str(len(records - 1)),
                            len(records - 1))

        config['default'] = records[default]
        cls.update_profile(config)
Esempio n. 3
0
    def set_default(self, essid=None):
        if essid is None:
            records = list(self.get_records().keys())
            for index, item in enumerate(records):
                print(list_item(index, item))

            option = selection(
                'Please select an option as default wifi connection [0-%s]' %
                str(len(records) - 1),
                len(records) - 1)

            default = {'default': {'essid': records[option]}}
            self.update_profile(default)
        else:
            default = {'default': {'essid': essid}}
            self.update_profile(default)
Esempio n. 4
0
    def connect(self, essid=None, passwd=None, noreturn=True, apexist=None):

        if essid is not None:
            if apexist is None:
                apexist = essid in [
                    i['essid'] for i in self.scan(noreturn=False, noprint=True)
                ]

            if apexist:
                if passwd is not None:
                    result = self._do_connect(essid, passwd)
                    if not noreturn:
                        return result
                else:
                    # 只传入essid 便去查找记录以获得密码
                    passwd = self.get_passwd(essid)
                    if passwd is not None:
                        result = self._do_connect(essid,
                                                  self.get_passwd(essid))
                        if not noreturn:
                            return result
                    else:
                        print(
                            rainbow('!!! The record was not found.',
                                    color='red'))
                        if not noreturn:
                            return False
            else:
                print(rainbow('!!! AP[ %s ] not found.' % essid, color='red'))
                if not noreturn:
                    return False

        else:
            networks = [i['essid'] for i in self.scan(noreturn=False)]
            select = selection('Choose a WiFi to connect', len(networks) - 1)
            passwd = input('Password: ')
            essid = networks[select]
            result = self._do_connect(essid, passwd)
            if not noreturn:
                return result
Esempio n. 5
0
def set_boot_mode():

    print(
        print_as_a_list_item(
            0, 'Boot with nothing',
            'attention: this option will clear up boot.py, careful!'))
    print(
        print_as_a_list_item(
            1, 'Boot with wifi startup',
            'this mode will auto start wifi connect program.'))
    print(
        print_as_a_list_item(
            2, 'Easy to develop',
            'this mode is for developers.In this mode you can develop much easier via EMP-IDE(emp.1zlab.com)'
        ))

    mode = selection('Please input your choice [0-2]: ', 2)

    with open('boot.py', 'w') as f:
        if mode == BOOT_MODE.WITH_NOTHING:
            boot_code = ''
            f.write(boot_code)
            print(rainbow('Boot mode set to WITH_NOTHING', color='green'))
        elif mode == BOOT_MODE.WITH_WIFI_STARTUP:
            boot_code = BOOT_MODE.WITH_WIFI_STARTUP_CODE
            f.write(boot_code)
            print(rainbow('Boot mode set to WITH_WIFI_STARTUP', color='green'))

        elif mode == BOOT_MODE.EASY_DEVELOP:
            config_path()
            if not 'webrepl.pass' in os.listdir('config'):
                with open('config/webrepl.pass', 'w') as c:
                    c.write('1zlab')
            boot_code = BOOT_MODE.EASY_DEVELOP_CODE
            f.write(boot_code)
            print(rainbow('Boot mode set to EASY_DEVELOP', color='green'))

    reboot()
Esempio n. 6
0
    def del_record(self, essid=None):
        if essid is None:
            records = self.get_records()
            essids = [i for i in records.keys()]
            for index, item in enumerate(essids):
                print(list_item(index, item))

            option = selection(
                'Please select an option to delete [0-%s]' %
                str(len(list(records.keys())) - 1),
                len(list(records.keys())) - 1)

            essid = essids[option]
            records.pop(essid)
            records = {'records': records}
            self.update_profile(records)
        elif self.is_in_records(essid):
            records.pop(essid)
            records = {'records': records}
            self.update_profile(records)

        else:
            print(rainbow('The record was not found', color='red'))