1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/lantsang-smart-dtu

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
bluestone_common.py 2.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
dongzhenguo Отправлено 27.04.2021 14:13 196f49e
'''
File: bluestone_common.py
Project: bluestone
Author: daniel dong
Email: dongzhenguo@lantsang.cn
Copyright 2021 - 2021 bluestone tech
'''
import uos
import ure
import modem
import log
import ujson
import _thread
log.basicConfig(level = log.INFO)
_common_log = log.getLogger("COMMON")
class BluestoneCommon(object):
inst = None
_network_state = 1
_lock = _thread.allocate_lock()
def __init__(self):
BluestoneCommon.inst = self
@staticmethod
def get_network_state():
return BluestoneCommon._network_state
@staticmethod
def set_network_state(state = 1):
BluestoneCommon._lock.acquire()
BluestoneCommon._network_state = state
BluestoneCommon._lock.release()
@staticmethod
def get_imei():
return modem.getDevImei()
@staticmethod
def get_sn():
return modem.getDevSN()
@staticmethod
def generate_random_str():
random_str = ''.join([('0' + hex(ord(uos.urandom(1)))[2:])[-2:] for x in range(8)])
return random_str
@staticmethod
def check_file_exist(file_name):
if not file_name:
return False
file_list = uos.listdir('usr')
if file_name in file_list:
return True
else:
return False
@staticmethod
def is_url(url):
#pattern = ure.compile('http[s]://.+')
return ure.match('https?://.+', url)
@staticmethod
def is_json(content):
if not content:
return False
try:
ujson.loads(content)
return True
except Exception as err:
return False
@staticmethod
def get_range(start, end, step = 1):
result = []
index = start
while True:
if start < end:
if index <= end:
result.push(index)
else:
break
index = index + step
else:
if index >= end:
result.push(index)
else:
break
index = index - step
return result

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/lantsang-smart-dtu.git
git@api.gitlife.ru:oschina-mirror/lantsang-smart-dtu.git
oschina-mirror
lantsang-smart-dtu
lantsang-smart-dtu
master