def fileExists(self, mibname, mtime, rebuild=False): if rebuild: debug.logger & debug.flagSearcher and debug.logger( 'pretend %s is very old' % mibname) return mibname = decode(mibname) pyfile = os.path.join(self._path, mibname) for fmt in imp.PY_COMPILED, imp.PY_SOURCE: for pySfx, pyMode in self.suffixes[fmt]: f = pyfile + pySfx if not os.path.exists(f) or not os.path.isfile(f): debug.logger & debug.flagSearcher and debug.logger( '%s not present or not a file' % f) continue if fmt == imp.PY_COMPILED: try: pyData = open(f, pyMode).read(8) except IOError: raise error.PySmiSearcherError( 'failure opening compiled file %s: %s' % (f, sys.exc_info()[1]), searcher=self) if pyData[:4] == imp.get_magic(): pyData = pyData[4:] pyTime = struct.unpack('<L', pyData[:4])[0] debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() else: raise error.PySmiFileNotFoundError( 'older file %s exists %s' % mibname, searcher=self) else: debug.logger & debug.flagSearcher and debug.logger( 'bad magic in %s' % f) continue else: try: pyTime = os.stat(f)[8] except OSError: raise error.PySmiSearcherError( 'failure opening compiled file %s: %s' % (f, sys.exc_info()[1]), searcher=self) debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() raise error.PySmiFileNotFoundError('no compiled file %s found' % mibname, searcher=self)
def fileExists(self, mibname, mtime, rebuild=False): if mibname in self._mibnames: debug.logger & debug.flagSearcher and debug.logger( 'pretend compiled %s exists and is very new' % mibname) raise error.PySmiFileNotModifiedError( 'compiled file %s is among %s' % (mibname, ', '.join(self._mibnames)), searcher=self) raise error.PySmiFileNotFoundError( 'no compiled file %s found among %s' % (mibname, ', '.join(self._mibnames)), searcher=self)
def fileExists(self, mibname, mtime, rebuild=False): if rebuild: debug.logger & debug.flagSearcher and debug.logger( 'pretend %s is very old' % mibname) return mibname = decode(mibname) basename = os.path.join(self._path, mibname) for sfx in self.exts: f = basename + sfx if not os.path.exists(f) or not os.path.isfile(f): debug.logger & debug.flagSearcher and debug.logger( '%s not present or not a file' % f) continue try: fileTime = os.stat(f)[8] except OSError: raise error.PySmiSearcherError( 'failure opening compiled file %s: %s' % (f, sys.exc_info()[1]), searcher=self) debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(fileTime)))) if fileTime >= mtime: raise error.PySmiFileNotModifiedError() raise error.PySmiFileNotFoundError('no compiled file %s found' % mibname, searcher=self)
def fileExists(self, mibname, mtime, rebuild=False): if rebuild: debug.logger & debug.flagSearcher and debug.logger('pretend %s is very old' % mibname) return mibname = decode(mibname) try: p = __import__(self._package, globals(), locals(), ['__init__']) if hasattr(p, '__loader__') and hasattr(p.__loader__, '_files'): self.__loader = p.__loader__ self._package = self._package.replace('.', os.sep) debug.logger & debug.flagSearcher and debug.logger( '%s is an importable egg at %s' % (self._package, os.path.split(p.__file__)[0])) elif hasattr(p, '__file__'): debug.logger & debug.flagSearcher and debug.logger( '%s is not an egg, trying it as a package directory' % self._package) return PyFileSearcher(os.path.split(p.__file__)[0]).fileExists(mibname, mtime, rebuild=rebuild) else: raise error.PySmiFileNotFoundError('%s is neither importable nor a file' % self._package, searcher=self) except ImportError: raise error.PySmiFileNotFoundError('%s is not importable, trying as a path' % self._package, searcher=self) for fmt in imp.PY_COMPILED, imp.PY_SOURCE: for pySfx, pyMode in self.suffixes[fmt]: f = os.path.join(self._package, mibname.upper()) + pySfx if f not in self.__loader._files: debug.logger & debug.flagSearcher and debug.logger('%s is not in %s' % (f, self._package)) continue if fmt == imp.PY_COMPILED: pyData = self.__loader.get_data(f) if pyData[:4] == imp.get_magic(): pyData = pyData[4:] pyTime = struct.unpack('<L', pyData[:4])[0] debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() else: raise error.PySmiFileNotFoundError('older file %s exists' % mibname, searcher=self) else: debug.logger & debug.flagSearcher and debug.logger('bad magic in %s' % f) continue else: pyTime = self._parseDosTime( self.__loader._files[f][6], self.__loader._files[f][5] ) debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() else: raise error.PySmiFileNotFoundError('older file %s exists' % mibname, searcher=self) raise error.PySmiFileNotFoundError('no file %s found' % mibname, searcher=self)
def fileExists(self, mibname, mtime, rebuild=False): if rebuild: debug.logger & debug.flagSearcher and debug.logger( 'pretend %s is very old' % mibname) return mibname = decode(mibname) pyfile = os.path.join(self._path, mibname) for pySfx in BYTECODE_SUFFIXES: f = pyfile + pySfx if not os.path.exists(f) or not os.path.isfile(f): debug.logger & debug.flagSearcher and debug.logger( '%s not present or not a file' % f) continue try: fp = open(f, 'rb') pyData = fp.read(8) fp.close() except IOError: raise error.PySmiSearcherError( 'failure opening compiled file %s: %s' % (f, sys.exc_info()[1]), searcher=self) if pyData[:4] == PY_MAGIC_NUMBER: pyData = pyData[4:] pyTime = struct.unpack('<L', pyData[:4])[0] debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() else: raise error.PySmiFileNotFoundError('older file %s exists' % mibname, searcher=self) else: debug.logger & debug.flagSearcher and debug.logger( 'bad magic in %s' % f) continue for pySfx in SOURCE_SUFFIXES: f = pyfile + pySfx if not os.path.exists(f) or not os.path.isfile(f): debug.logger & debug.flagSearcher and debug.logger( '%s not present or not a file' % f) continue try: pyTime = os.stat(f)[8] except OSError: raise error.PySmiSearcherError( 'failure opening compiled file %s: %s' % (f, sys.exc_info()[1]), searcher=self) debug.logger & debug.flagSearcher and debug.logger( 'found %s, mtime %s' % (f, time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(pyTime)))) if pyTime >= mtime: raise error.PySmiFileNotModifiedError() raise error.PySmiFileNotFoundError('no compiled file %s found' % mibname, searcher=self)