Пример #1
0
 def __init__(self, path, glob_dict={}, local_dict={}, name=None, doc=""):
     fn = Filename(path, absolute=1)
     self.path = fn.name
     self.name = name or fn.base
     self.dir = fn.directory
     self.gd = glob_dict
     self.ld = local_dict
     self.gauge = local_dict.get("gauge")
     if not self.gauge:
         self.gauge = Gauge_Logger()
     self.old_path = []
     self._sys_pth = sys.path[:]
     self.__doc__   = \
         (  doc.replace ("script-name", self.name)
         or ("Run script `%s'" % self.name)
         )
     self.error = None
Пример #2
0
 def __init__ (self, path, glob_dict = {}, local_dict = {}, name = None, doc = "") :
     fn             = Filename (path, absolute = 1)
     self.path      = fn.name
     self.name      = name or fn.base
     self.dir       = fn.directory
     self.gd        = glob_dict
     self.ld        = local_dict
     self.gauge     = local_dict.get ("gauge")
     if not self.gauge :
         self.gauge = Gauge_Logger ()
     self.old_path  = []
     self._sys_pth  = sys.path [:]
     self.__doc__   = \
         (  doc.replace ("script-name", self.name)
         or ("Run script `%s'" % self.name)
         )
     self.error     = None
Пример #3
0
 def entity_iter_gauge(self,
                       gauge=Gauge_Logger(),
                       sort_key=None,
                       label=None):
     """Yields all entities alive in `self` in the
        order specified by `sort_key`.
     """
     gauge.reset \
         ( g_delta = 100
         , g_range = self.ems.count (self.MOM.Id_Entity, strict = False)
         , label   = label
         )
     entities = iter(self.ems)
     if sort_key:
         entities = sorted(entities, key=sort_key)
     i = 1
     for e in entities:
         yield e
         if i == 100:
             gauge.inc(100)
             i = 0
         i += 1
Пример #4
0
 def r_incorrect(self, gauge=Gauge_Logger(), eiter=None):
     """Returns all objects which are region-wise incorrect (i.e., violating
        the object's `region` predicates).
     """
     with self.as_active():
         return self._check_inv(gauge, "region", eiter)
Пример #5
0
 def i_incorrect(self, gauge=Gauge_Logger()):
     """Returns all objects which are object-wise incorrect (i.e., violating
        the object's `object` predicates).
     """
     with self.as_active():
         return self._check_inv(gauge, "object")
Пример #6
0
 def g_incorrect(self, gauge=Gauge_Logger()):
     """Returns all objects which are globally incorrect (i.e., violating
        the object's `system` predicates).
     """
     with self.as_active():
         return self._check_inv(gauge, "system")
Пример #7
0
class Script (TFL.Meta.Object) :

    def __init__ (self, path, glob_dict = {}, local_dict = {}, name = None, doc = "") :
        fn             = Filename (path, absolute = 1)
        self.path      = fn.name
        self.name      = name or fn.base
        self.dir       = fn.directory
        self.gd        = glob_dict
        self.ld        = local_dict
        self.gauge     = local_dict.get ("gauge")
        if not self.gauge :
            self.gauge = Gauge_Logger ()
        self.old_path  = []
        self._sys_pth  = sys.path [:]
        self.__doc__   = \
            (  doc.replace ("script-name", self.name)
            or ("Run script `%s'" % self.name)
            )
        self.error     = None
    # end def __init__

    def __call__ (self, ld = {}) :
        self.error = None
        gd = self.gd.copy ()
        gd.update         (self.ld)
        gd.update         (ld)
        gd.update \
            ({ "add_to_python_path" : self.add_to_python_path
             , "reset_python_path"  : self.reset_python_path
             }
            )
        try :
            self.old_path = sys.path [:]
            try     :
                sys.path  [0:0] = [self.dir]
                self.gauge.echo   ("Running script %s\n" % self.path)
                execfile          (self.path, gd)
                self.gauge.echo   ("Finished execution of %s\n" % self.path)
            finally :
                sys.path  = self.old_path
        except KeyboardInterrupt as exc :
            raise
        except Exception :
            print ("Error during execution of", self.path)
            traceback.print_exc ()
            self.error = sys.exc_info () [1]
    # end def __call__

    def add_to_python_path (self, path, index = -1) :
        """Add `path' to `sys.path'"""
        sys.path      [index+1 : index+1] = [path]
        self.old_path [index   : index] = [path]
    # end def add_to_python_path

    def reset_python_path (self) :
        """Reset `sys.path' to original value."""
        self.old_path = self._sys_pth [:]
        sys.path      = self._sys_pth [:]
    # end def reset_python_path

    def __eq__ (self, other) :
        return self.name == getattr (other, "name", other)
    # end def __eq__

    def __hash__ (self) :
        return hash (self.name)
    # end def __hash__

    def __lt__ (self, other) :
        return self.name < getattr (other, "name", other)
Пример #8
0
class Script(TFL.Meta.Object):
    def __init__(self, path, glob_dict={}, local_dict={}, name=None, doc=""):
        fn = Filename(path, absolute=1)
        self.path = fn.name
        self.name = name or fn.base
        self.dir = fn.directory
        self.gd = glob_dict
        self.ld = local_dict
        self.gauge = local_dict.get("gauge")
        if not self.gauge:
            self.gauge = Gauge_Logger()
        self.old_path = []
        self._sys_pth = sys.path[:]
        self.__doc__   = \
            (  doc.replace ("script-name", self.name)
            or ("Run script `%s'" % self.name)
            )
        self.error = None

    # end def __init__

    def __call__(self, ld={}):
        self.error = None
        gd = self.gd.copy()
        gd.update(self.ld)
        gd.update(ld)
        gd.update \
            ({ "add_to_python_path" : self.add_to_python_path
             , "reset_python_path"  : self.reset_python_path
             }
            )
        try:
            self.old_path = sys.path[:]
            try:
                sys.path[0:0] = [self.dir]
                self.gauge.echo("Running script %s\n" % self.path)
                execfile(self.path, gd)
                self.gauge.echo("Finished execution of %s\n" % self.path)
            finally:
                sys.path = self.old_path
        except KeyboardInterrupt as exc:
            raise
        except Exception:
            print("Error during execution of", self.path)
            traceback.print_exc()
            self.error = sys.exc_info()[1]

    # end def __call__

    def add_to_python_path(self, path, index=-1):
        """Add `path' to `sys.path'"""
        sys.path[index + 1:index + 1] = [path]
        self.old_path[index:index] = [path]

    # end def add_to_python_path

    def reset_python_path(self):
        """Reset `sys.path' to original value."""
        self.old_path = self._sys_pth[:]
        sys.path = self._sys_pth[:]

    # end def reset_python_path

    def __eq__(self, other):
        return self.name == getattr(other, "name", other)

    # end def __eq__

    def __hash__(self):
        return hash(self.name)

    # end def __hash__

    def __lt__(self, other):
        return self.name < getattr(other, "name", other)