コード例 #1
0
    def analyze_file(self, pyfile, use_cache=False):
        # don't analyze the file again if we've already done it and it hasn't
        # changed.  If `use_cache` is True then lookup/record in global cache.
        mtime = os.path.getmtime(pyfile)
        if pyfile in self.fileinfo:
            if mtime <= self.fileinfo[pyfile][1]:
                return self.fileinfo[pyfile][0]

        if use_cache:
            info = _FileInfoCache.lookup(pyfile)
            if info is not None and mtime <= info[1]:
                self.fileinfo[pyfile] = info
                return info[0]

        logger.info("analyzing %s", pyfile)

        myvisitor = PythonSourceFileAnalyser(pyfile, self)
        self.modinfo[get_module_path(pyfile)] = myvisitor
        self.fileinfo[myvisitor.fname] = (myvisitor,
                                          os.path.getmtime(myvisitor.fname))
        self.files_count += 1

        if use_cache:
            _FileInfoCache.record(
                pyfile, (myvisitor, os.path.getmtime(myvisitor.fname)))

        return myvisitor
コード例 #2
0
    def __init__(self, watchdir, use_observer=True, observer=None):
        super(ProjDirFactory, self).__init__()
        self._lock = threading.RLock()
        self.observer = None
        self.watchdir = watchdir
        self._files = {}  # mapping of file pathnames to _FileInfo objects
        self._classes = {}  # mapping of class names to _FileInfo objects
        try:
            added_set = set()
            changed_set = set()
            deleted_set = set()

            modeldir = watchdir + PROJ_DIR_EXT
            if modeldir not in sys.path:
                sys.path = [modeldir] + sys.path
                logger.info("added %s to sys.path" % modeldir)

            for pyfile in find_files(self.watchdir, "*.py"):
                self.on_modified(pyfile, added_set, changed_set, deleted_set)

            if use_observer:
                self._start_observer(observer)
                self.publish_updates(added_set, changed_set, deleted_set)
            else:
                # sometimes for debugging/testing it's easier to turn observer off
                self.observer = None
        except Exception as err:
            self._error(str(err))
            logger.error(str(err))
コード例 #3
0
ファイル: dep.py プロジェクト: hitej/meta-core
    def analyze_file(self, pyfile, use_cache=False):
        # don't analyze the file again if we've already done it and it hasn't
        # changed.  If `use_cache` is True then lookup/record in global cache.
        mtime = os.path.getmtime(pyfile)
        if pyfile in self.fileinfo:
            if mtime <= self.fileinfo[pyfile][1]:
                return self.fileinfo[pyfile][0]

        if use_cache:
            info = _FileInfoCache.lookup(pyfile)
            if info is not None and mtime <= info[1]:
                self.fileinfo[pyfile] = info
                return info[0]

        logger.info("analyzing %s", pyfile)

        myvisitor = PythonSourceFileAnalyser(pyfile, self)
        self.modinfo[get_module_path(pyfile)] = myvisitor
        self.fileinfo[myvisitor.fname] = (myvisitor, os.path.getmtime(myvisitor.fname))
        self.files_count += 1

        if use_cache:
            _FileInfoCache.record(pyfile, (myvisitor, os.path.getmtime(myvisitor.fname)))

        return myvisitor
コード例 #4
0
 def _initialize(self):
     if os.path.isfile(os.path.join(self.macrodir, self.macro)):
         logger.info('Reconstructing project using %s macro' % self.macro)
         self.load_macro(self.macro)
     else:
         self.command("# Auto-generated file - MODIFY AT YOUR OWN RISK")
         self.command("top = set_as_top(create('openmdao.main.assembly.Assembly'))")
コード例 #5
0
ファイル: projdirfactory.py プロジェクト: hitej/meta-core
    def __init__(self, watchdir, use_observer=True, observer=None):
        super(ProjDirFactory, self).__init__()
        self._lock = threading.RLock()
        self.observer = None
        self.watchdir = watchdir
        self._files = {}    # mapping of file pathnames to _FileInfo objects
        self._classes = {}  # mapping of class names to _FileInfo objects
        try:
            added_set = set()
            changed_set = set()
            deleted_set = set()

            modeldir = watchdir + PROJ_DIR_EXT
            if modeldir not in sys.path:
                sys.path = [modeldir] + sys.path
                logger.info("added %s to sys.path" % modeldir)

            for pyfile in find_files(self.watchdir, "*.py"):
                self.on_modified(pyfile, added_set, changed_set, deleted_set)

            if use_observer:
                self._start_observer(observer)
                self.publish_updates(added_set, changed_set, deleted_set)
            else:
                # sometimes for debugging/testing it's easier to turn observer off
                self.observer = None
        except Exception as err:
            self._error(str(err))
            logger.error(str(err))
コード例 #6
0
def register_class_factory(factory):
    """Add a Factory to the factory list."""
    global _factories
    with _factory_lock:
        if factory not in _factories:
            logger.info("adding new factory: %s" % factory)
            _factories.append(factory)
コード例 #7
0
 def _initialize(self):
     if os.path.isfile(os.path.join(self.macrodir, self.macro)):
         logger.info('Reconstructing project using %s macro' % self.macro)
         self.load_macro(self.macro)
     else:
         self.command("# Auto-generated file - MODIFY AT YOUR OWN RISK")
         self.command(
             "top = set_as_top(create('openmdao.main.assembly.Assembly'))")
コード例 #8
0
def remove_class_factory(factory):
    """Remove a Factory from the factory list."""
    with _factory_lock:
        for fct in _factories:
            if fct is factory:
                if hasattr(factory, 'cleanup'):
                    factory.cleanup()
                logger.info("removing factory: %s" % factory)
                _factories.remove(factory)
                return
コード例 #9
0
 def _reload(self):
     mtime = os.path.getmtime(self.fpath)
     if self.modtime < mtime:
         cmpfname = os.path.splitext(self.fpath)[0] + '.pyc'
         # unless we remove the .pyc file, reload will just use it and won't
         # see any source updates.  :(
         if os.path.isfile(cmpfname):
             os.remove(cmpfname)
         logger.info("reloading module %s" % self.modpath)
         reload(sys.modules[self.modpath])
         self.modtime = mtime
     self._update_class_info()
コード例 #10
0
ファイル: projdirfactory.py プロジェクト: hitej/meta-core
 def _reload(self):
     mtime = os.path.getmtime(self.fpath)
     if self.modtime < mtime:
         cmpfname = os.path.splitext(self.fpath)[0] + '.pyc'
         # unless we remove the .pyc file, reload will just use it and won't
         # see any source updates.  :(
         if os.path.isfile(cmpfname):
             os.remove(cmpfname)
         logger.info("reloading module %s" % self.modpath)
         reload(sys.modules[self.modpath])
         self.modtime = mtime
     self._update_class_info()
コード例 #11
0
ファイル: project.py プロジェクト: cephdon/meta-core
 def _initialize(self):
     if os.path.isfile(os.path.join(self.macrodir, self.macro)):
         logger.info('Reconstructing project using %s macro' % self.macro)
         self.load_macro(self.macro)
     else:
         self.command("# Auto-generated file - MODIFY AT YOUR OWN RISK")