def get_instance(): MiConfig.__lock.acquire() if not MiConfig.__inst: MiConfig.__inst = object.__new__(MiConfig) object.__init__(MiConfig.__inst) printer.d('MiConfig.get_instance --> Create a MiConfig Instance\n') MiConfig.__inst.init() MiConfig.__lock.release() return MiConfig.__inst
def TestColorPrinter(): printer.i('Info test message\n') printer.d('Debug test message\n') printer.w('Warning test message\n') printer.e('Error test message\n') try: t = 1/0 except: printer.exception('Exception test message\n') printer.beep()
def TestColorPrinter(): printer.i('Info test message\n') printer.d('Debug test message\n') printer.w('Warning test message\n') printer.e('Error test message\n') try: t = 1 / 0 except: printer.exception('Exception test message\n') printer.beep()
def load_from_file(self, conf_file): printer.d('MiConfig.load_from_file --> %s\n' % conf_file) with open(conf_file, 'r') as configfile: self.__dict__['confobj'].clear() self.__dict__['confobj'].update(json.load(configfile)) confobj = self.__dict__['confobj'] secobjs = self.__dict__['secobjs'] secobjs.clear() for key in confobj.keys(): secobjs[key] = MiConfig_SubCategory(confobj, key)
def get_instance(Class, TAG): Class.__lock.acquire() if not Class.__insts.has_key(TAG): Class.__insts[TAG] = object.__new__(Class) object.__init__(Class.__insts[TAG]) printer.d('MiLogger.get_instance --> Create a MiLogger Instance: %s %s Class: %s\n' % (TAG, Class.__insts[TAG], hex(id(Class)))) Class.__lock.release() Class.__insts[TAG].init(TAG) Class.__lock.acquire() Class.__lock.release() return Class.__insts[TAG]
def openlog(self, filename): self.__lock.acquire() if self.__logf_opened: self.__logf_ref_c += 1 self.__lock.release() return if CONF_DOLOG: self.__logf = open(filename, 'a') self.__logf_opened = True printer.d('MiLogger.openlog --> Open file %s\n' % filename) self.__logf_ref_c += 1 self.__lock.release()
def closelog(self): self.__lock.acquire() if CONF_DOLOG: self.__logf_ref_c -= 1 if self.__logf_ref_c != 0: self.__lock.release() return else: if self.__logf: printer.d('MiLogger.closelog --> Close file %s\n' % self.__logpath) self.__logf.close() self.__lock.release()
def uninit(self): printer.d('MiLogger.uninit --> del %s\n' % self) self.closelog() ### some error to log file. remove it temporary.
def __del__(self): printer.d('MiConfig.__del__ --> %s' % self)
def load_from_file(self, conf_file): printer.d('MiConfig.load_from_file --> %s\n' % conf_file) confobj = self.__dict__['confobj'] confobj.read(conf_file)
def save_to_file(self, conf_file): printer.d('MiConfig.save_to_file --> %s\n' % conf_file) confobj = self.__dict__['confobj'] with open(conf_file, 'wb') as configfile: confobj.write(configfile)
def save_to_file(self, conf_file): printer.d('MiConfig.save_to_file --> %s\n' % conf_file) confobj = self.__dict__['confobj'] with open(conf_file, 'w') as configfile: json.dump(self.__dict__['confobj'], fp=configfile, indent=4)