예제 #1
0
파일: ImportHooks.py 프로젝트: se210/tracy
    def getmod(self, name):
        try:
            self._acquireLock()
            mod = DirOwner.getmod(self, name)
            if mod:
                return mod

            for ext in self.templateFileExtensions:
                tmplPath = os.path.join(self.path, name + ext)
                if os.path.exists(tmplPath):
                    try:
                        return self._compile(name, tmplPath)
                    except:
                        # @@TR: log the error
                        exc_txt = traceback.format_exc()
                        exc_txt = '  ' + ('  \n'.join(exc_txt.splitlines()))
                        raise ImportError(
                            'Error while compiling Cheetah module'
                            ' %(name)s, original traceback follows:\n%(exc_txt)s'
                            % locals())
            ##
            return None

        finally:
            self._releaseLock()
예제 #2
0
    def getmod(self, name):
        self._acquireLock()
        try:
            mod = DirOwner.getmod(self, name)
            if mod:
                return mod

            for ext in self.templateFileExtensions:
                tmplPath = os.path.join(self.path, name + ext)
                if os.path.exists(tmplPath):
                    try:
                        return self._compile(name, tmplPath)
                    except:
                        # @@TR: log the error
                        exc_txt = traceback.format_exc()
                        exc_txt = "  " + ("  \n".join(exc_txt.splitlines()))
                        raise ImportError(
                            "Error while compiling Cheetah module"
                            " %(name)s, original traceback follows:\n%(exc_txt)s" % locals()
                        )
            ##
            return None

        finally:
            self._releaseLock()
예제 #3
0
    def getmod(
        self, name, pathIsDir=os.path.isdir, join=os.path.join, newmod=imp.new_module, convertTmplPath=convertTmplPath
    ):

        tmplPath = os.path.join(self.path, name + ".tmpl")
        mod = DirOwner.getmod(self, name)
        if mod:
            return mod
        elif not os.path.exists(tmplPath):
            return None
        else:
            self._acquireLock()
            ## @@ consider adding an ImportError raiser here
            code = str(Compiler(file=tmplPath, moduleName=name, mainClassName=name))
            if _cacheDir:
                __file__ = join(_cacheDir[0], convertTmplPath(tmplPath)) + ".py"
                try:
                    open(__file__, "w").write(code)
                except OSError:
                    ## @@ TR: need to add some error code here
                    traceback.print_exc(file=sys.stderr)
                    __file__ = tmplPath
            else:
                __file__ = tmplPath
            co = compile(code + "\n", __file__, "exec")

            mod = newmod(name)
            mod.__file__ = co.co_filename
            if _cacheDir:
                mod.__orig_file__ = tmplPath  # @@TR: this is used in the WebKit
                # filemonitoring code
            mod.__co__ = co
            self._releaseLock()
            return mod
예제 #4
0
    def getmod(
        self,
        name,
        pathIsDir=os.path.isdir,
        join=os.path.join,
        newmod=imp.new_module,
        convertTmplPath=convertTmplPath,
    ):

        tmplPath = os.path.join(self.path, name + '.tmpl')
        mod = DirOwner.getmod(self, name)
        if mod:
            return mod
        elif not os.path.exists(tmplPath):
            return None
        else:
            self._acquireLock()
            ## @@ consider adding an ImportError raiser here
            code = str(
                Compiler(file=tmplPath, moduleName=name, mainClassName=name))
            if _cacheDir:
                __file__ = join(_cacheDir[0],
                                convertTmplPath(tmplPath)) + '.py'
                try:
                    open(__file__, 'w').write(code)
                except OSError:
                    ## @@ TR: need to add some error code here
                    traceback.print_exc(file=sys.stderr)
                    __file__ = tmplPath
            else:
                __file__ = tmplPath
            co = compile(code + '\n', __file__, 'exec')

            mod = newmod(name)
            mod.__file__ = co.co_filename
            if _cacheDir:
                mod.__orig_file__ = tmplPath  # @@TR: this is used in the WebKit
                # filemonitoring code
            mod.__co__ = co
            self._releaseLock()
            return mod