from django.conf import settings import digitalocean as api from core import logging from lifecycle import models logger = logging.getLogger(__name__) class Lifecycle: """ Manage mark and sweep to servers using digitalocean """ name = 'camotes-scraper' def __init__(self, token=None, keep=None): self.token = token or settings.DO_TOKEN self.keep = keep or 4 def servers(self): manager = api.Manager(token=self.token) servers = [] for d in manager.get_all_droplets(): if not d.name.startswith(self.name): continue servers.append(d) return servers def next_version_number(self):
from core import logging log = logging.getLogger("PLATFORM_ESP32") log.setLevel(logging.INFO) #upy async def upy_awrite(writer, data, b=False): try: if isinstance(data, str): data = data.encode('utf-8') await writer.awrite(data) except Exception as e: log.debug("Error: write: {}".format(e)) pass async def upy_aclose(writer): try: await writer.aclose() except Exception as e: log.debug("close: {}".format(e)) pass def _try_alloc_byte_array(size): import gc for x in range(10): try: gc.collect() return bytearray(size)
try: import uasyncio as asyncio from uasyncio import Event except ImportError: import asyncio from asyncio import Event from threading import Thread from core import logging log = logging.getLogger("THREAD") class RunInThread(Thread): """ """ def __init__(self, action, *args, **kwargs): """Инициализация потока""" log.info("Init:") # print("Thread Init") Thread.__init__(self) self.result = None self.event = Event() self.action = action self._args = args self._kwargs = kwargs def run(self): """Запуск потока"""
from core.core import uCore import gc from core import logging log = logging.getLogger("LOADER") import sys from core.tools.tool import launch try: import uasyncio as asyncio except Exception: import asyncio as asyncio class uAction: def __init__(self, env, module): self.core = uCore.get_core() self.mbus = self.core.mbus self.uconf = self.core.uconf self.env = env self.module = module self.depend = module.depend self.wait_depend = None launch(self.start) # Humanize sub to topic def sub_h(self, topic, func): return self.mbus.sub_h(topic=topic, env=self.env, func=func)
import uasyncio as asyncio import machine, _thread import uos import gc from core import logging log = logging.getLogger('MAIN') logging.basicConfig(level=logging.INFO) # WDT async def run_wdt(): wdt = machine.WDT(timeout=120000) print("WDT RUN") while True: wdt.feed() # gc.collect() print("WDT RESET") await asyncio.sleep(30) # Core def core(): from core.core import uCore from core.mbus.mbus import MbusManager from core.config.config import ConfigManager # VFS SIZE fs_stat = uos.statvfs('/') fs_size = fs_stat[0] * fs_stat[2]
# Copyright (c) 2020 Viktor Vorobjov from core.tools.tool import launch, is_coro from core.tools.tool import DataClassArg try: import uasyncio as asyncio except Exception: import asyncio as asyncio pass from core import logging log = logging.getLogger("MBUS") class RpcEnv: def __init__(self, core): self.core = core @staticmethod def isgenerator(iterable): return hasattr(iterable, '__iter__') and not hasattr(iterable, '__len__') class IsClass(object): pass ''' Search method or arg in env by nema and path env_name = "mqtt" path = "client.status" / disconect
from core import logging log = logging.getLogger("BOARD") try: import ubinascii except Exception: import binascii as ubinascii import machine from core.loader.loader import uLoad from core.u_os import uname, mem_info from esp32 import Partition class BoardAction(uLoad): async def _activate(self): _mod = await self.uconf.call("select_one", "board_cfg", "default", True) if _mod: # BOARD ID self.board_id = ubinascii.hexlify(machine.unique_id()).decode() log.info("BOARD ID: {}".format(self.board_id)) _mod.uid = self.board_id await _mod.update() self.board = _mod self.core.board = self.board
except Exception: import os as uos import time as utime from collections import OrderedDict import json as ujson from os.path import isdir as _isdir # from os import listdir pass import builtins # from core.thread.thread import run_in_executer # result = await run_in_executer(self._call_cmd, method, param, *args, **kwargs) from core import logging log = logging.getLogger("FJSON") def isdir(dir_path): try: if _isdir(dir_path): return True else: return False except OSError as e: log.debug("IS DIR: {} - {}".format(e, dir_path)) return False def isfile(file_path): try:
try: import uasyncio as asyncio from ucollections import OrderedDict import ujson except ImportError: from collections import OrderedDict import json as ujson import asyncio #from core.thread.thread import run_in_executer from core import logging log = logging.getLogger("CONF") class ConfigManager(): # __slots__ = ('__dict__', 'db', '_tbl', '_sch') def __init__(self, store_path="u_config"): _sch_name = "_schema" _sch_conf = OrderedDict([ ("name", ("str", "")), ("sch", ("dict", ())), ]) self.store = uorm.Store(store_schema=_sch_name, store_path=store_path, store_config=_sch_conf)
try: import uasyncio as asyncio except ImportError: import asyncio from core import logging log = logging.getLogger("CORE") def call_try(elog=log.error): def decorate(f): def applicator(*args, **kwargs): try: return f(*args,**kwargs) except Exception as e: elog("error: {}".format(e)) pass return applicator return decorate call_try_error = call_try() call_try_debug = call_try(log.debug) call_try_info = call_try(log.info) @call_try_error def encode_UTF8(data): if isinstance(data, str): data = data.encode('utf-8')