Esempio n. 1
0
 def clear(self):
     if self._controller is not None:
         try:
             self._controller.close()
         except:
             logging.exception_warning("controller close: {!r}".format(self._controller))
         self._controller = None
     if self._init_controller is not None:
         try:
             self._init_controller.close()
         except:
             logging.exception_warning("initial controller close: {!r}".format(self._init_controller))
         self._init_controller = None
Esempio n. 2
0
 def clear(self):
     if self._controller is not None:
         try:
             self._controller.close()
         except:
             logging.exception_warning("controller close: {!r}".format(
                 self._controller))
         self._controller = None
     if self._init_controller is not None:
         try:
             self._init_controller.close()
         except:
             logging.exception_warning(
                 "initial controller close: {!r}".format(
                     self._init_controller))
         self._init_controller = None
Esempio n. 3
0
 def get_logfile(self):
     from pycopia import logfile
     if self._cache._logfile is None:
         logfilename = self.get_logfilename()
         try:
             lf = logfile.ManagedLog(logfilename, self.get("logfilesize", 1000000))
             if self.flags.VERBOSE:
                 logging.info("Logging to: {}".format(logfilename))
         except:
             logging.exception_warning("get_logfile: Could not open log file")
             self._cache._logfile = None
             return None
         else:
             self._cache._logfile = lf
             return lf
     else:
         return self._cache._logfile
Esempio n. 4
0
 def clear(self):
     """Close any attached controllers.
     """
     if self._controller is not None:
         try:
             self._controller.close()
         except:
             logging.exception_warning("controller close: {!r}".format(
                 self._controller))
         self._controller = None
     if self._init_controller is not None:
         try:
             self._init_controller.close()
         except:
             logging.exception_warning(
                 "Initial controller close: {!r}".format(
                     self._init_controller))
         self._init_controller = None
Esempio n. 5
0
 def clear(self):
     if self._eqcache:
         eqc = self._eqcache
         self._eqcache = {}
         while eqc:
             name, obj = eqc.popitem()
             try:
                 obj.clear()
             except:
                 logging.exception_error("environment clear: {!r}".format(obj))
     gc.collect()
     for obj in gc.garbage:
         try:
             obj.close()
         except:
             logging.exception_warning("environment garbage collect: {!r}".format(obj))
     del gc.garbage[:]
     scheduler.sleep(2) # some devices need time to fully clear or disconnect
Esempio n. 6
0
 def clear(self):
     """Close any attached controllers.
     """
     if self._controller is not None:
         try:
             self._controller.close()
         except:
             logging.exception_warning(
                 "controller close: {!r}".format(self._controller))
         self._controller = None
     if self._init_controller is not None:
         try:
             self._init_controller.close()
         except:
             logging.exception_warning(
                 "Initial controller close: {!r}".format(
                     self._init_controller))
         self._init_controller = None
Esempio n. 7
0
 def get_logfile(self):
     from pycopia import logfile
     if self._cache._logfile is None:
         logfilename = self.get_logfilename()
         try:
             lf = logfile.ManagedLog(logfilename,
                                     self.get("logfilesize", 1000000))
             if self.flags.VERBOSE:
                 logging.info("Logging to: {}".format(logfilename))
         except:
             logging.exception_warning(
                 "get_logfile: Could not open log file")
             self._cache._logfile = None
             return None
         else:
             self._cache._logfile = lf
             return lf
     else:
         return self._cache._logfile
Esempio n. 8
0
 def clear(self, delay=0):
     if self._eqcache:
         eqc = self._eqcache
         self._eqcache = {}
         while eqc:
             name, obj = eqc.popitem()
             try:
                 obj.clear()
             except:
                 logging.exception_error(
                     "environment clear: {!r}".format(obj))
     gc.collect()
     for obj in gc.garbage:
         try:
             obj.close()
         except:
             logging.exception_warning(
                 "environment garbage collect: {!r}".format(obj))
     del gc.garbage[:]
     if delay:
         scheduler.sleep(delay)
Esempio n. 9
0
 def clear(self):
     if self._eqcache:
         eqc = self._eqcache
         self._eqcache = {}
         while eqc:
             name, obj = eqc.popitem()
             try:
                 obj.clear()
             except:
                 logging.exception_error(
                     "environment clear: {!r}".format(obj))
     gc.collect()
     for obj in gc.garbage:
         try:
             obj.close()
         except:
             logging.exception_warning(
                 "environment garbage collect: {!r}".format(obj))
     del gc.garbage[:]
     scheduler.sleep(
         2)  # some devices need time to fully clear or disconnect
Esempio n. 10
0
 def clear(self, delay=0):
     if self._eqcache:
         eqc = self._eqcache
         self._eqcache = {}
         while eqc:
             name, obj = eqc.popitem()
             try:
                 obj.clear()
             except:
                 logging.exception_error(
                     "environment clear: {!r}".format(obj))
     gc.collect()
     for obj in gc.garbage:
         try:
             obj.close()
         except:
             logging.exception_warning(
                 "environment garbage collect: {!r}".format(obj))
     del gc.garbage[:]
     if delay:
         scheduler.sleep(delay)
Esempio n. 11
0
def get_config(storageurl=None, _extrafiles=None, initdict=None, **kwargs):
    """Get primary configuration.

    Returns a RootContainer instance containing configuration parameters.  An
    extra dictionary may be merged in with the 'initdict' parameter.  And
    finally, extra options may be added with keyword parameters when calling
    this.
    """
    models.connect(storageurl)
    files = []

    if type(_extrafiles) is str:
        _extrafiles = [_extrafiles]
    if _extrafiles:
        files.extend(_extrafiles)
    try:
        rootnode = config.get_root()
    except models.OperationalError:
        logging.exception_warning(
            "Could not connect to database. Configuration not available.")
        return get_mock_config(files, initdict, kwargs)
    cache = AttrDict()
    flags = AttrDict()
    # copy flag values to cache so changes don't persist.
    flagsnode = Config.select().where(
        (Config.parent == rootnode) & (Config.name == "flags")).get()
    for valnode in flagsnode.children:
        flags[valnode.name] = valnode.value
    cache.flags = flags
    cf = RootContainer(rootnode, cache)
    for f in files:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    return cf
Esempio n. 12
0
def get_config(storageurl=None, _extrafiles=None, initdict=None, **kwargs):
    """Get primary configuration.

    Returns a RootContainer instance containing configuration parameters.  An
    extra dictionary may be merged in with the 'initdict' parameter.  And
    finally, extra options may be added with keyword parameters when calling
    this.
    """
    models.connect(storageurl)
    files = []

    if type(_extrafiles) is str:
        _extrafiles = [_extrafiles]
    if _extrafiles:
        files.extend(_extrafiles)
    try:
        rootnode = config.get_root()
    except models.OperationalError:
        logging.exception_warning(
            "Could not connect to database. Configuration not available.")
        return get_mock_config(files, initdict, kwargs)
    cache = AttrDict()
    flags = AttrDict()
    # copy flag values to cache so changes don't persist.
    flagsnode = Config.select().where((Config.parent == rootnode)
                                      & (Config.name == "flags")).get()
    for valnode in flagsnode.children:
        flags[valnode.name] = valnode.value
    cache.flags = flags
    cf = RootContainer(rootnode, cache)
    for f in files:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    return cf