Ejemplo n.º 1
0
def getCache():
    results = []

    for moduleObj in getSearchDirectories():
        componentPath = moduleObj.filePath
        dropinPath = componentPath.parent().child('components.cache')

        # Look for cache
        try:
            lastCached = dropinPath.getModificationTime()
            collection = pickle.load(dropinPath.open('r'))
        # FIXME: what kind of error do we expect?
        except:
            stale = True
        else:
            stale = False
            for path in componentPath.parent().walk():
                if path.isfile() and path.splitext()[-1] == '.py':
                    try:
                        lastModified = path.getModificationTime()
                    except:
                        log.err("Could not stat {:s}".format(
                            str(componentPath)))
                    else:
                        if lastModified > lastCached:
                            stale = True
                            break

        if stale:
            try:
                module = moduleObj.load()

                if type(module.__components__) is dict:

                    def loaded(collection):
                        try:
                            dropinPath.setContent(pickle.dumps(collection))
                        except OSError as e:
                            log.err("Unable to write cache file {:s}".format(
                                dropinPath))

                        return collection

                    results.append(
                        _generateCacheEntry(module).addCallback(loaded))
            except (KeyError, AttributeError) as e:
                log.err("Component module {:s} failed to load".format(
                    componentPath))
            except:
                log.err()
        else:
            results.append(defer.succeed(collection))

    d = defer.Deferred()
    defer.gatherResults(results).addCallbacks(d.callback, d.errback)
    return d
Ejemplo n.º 2
0
def getCache ():
	results = []

	for moduleObj in getSearchDirectories():

		componentPath = moduleObj.filePath
		dropinPath = componentPath.parent().child('components.cache')

		try:
			lastModified = componentPath.getModificationTime()
		except:
			log.err("Could not stat {:s}".format(str(componentPath)))
			continue

		# Look for cache
		try:
			lastCached = dropinPath.getModificationTime()
			collection = pickle.load(dropinPath.open('r'))
		except:
			lastCached = 0

		
		if lastCached < lastModified:
			stale = True
		else:
			stale = False
			for component in collection.components:
				if FilePath(component.fileName).getModificationTime() > lastCached:
					stale = True

		if stale:
			try:
				module = moduleObj.load()

				if type(module.__components__) is dict:
					def loaded (collection):
						try:
							dropinPath.setContent(pickle.dumps(collection))
						except OSError as e:
							log.err("Unable to write cache file {:s}".format(dropinPath))

						return collection

					results.append(_generateCacheEntry(module).addCallback(loaded))
			except KeyError as e:
				log.err("Component module {:s} failed to load".format(componentPath))
			except:
				log.err()
		else:
			results.append(defer.succeed(collection))

	d = defer.Deferred()
	defer.gatherResults(results).addCallbacks(d.callback, d.errback)
	return d
Ejemplo n.º 3
0
def getCache ():
	results = []

	for moduleObj in getSearchDirectories():
		componentPath = moduleObj.filePath
		dropinPath = componentPath.parent().child('components.cache')

		# Look for cache
		try:
			lastCached = dropinPath.getModificationTime()
			collection = pickle.load(dropinPath.open('r'))
		# FIXME: what kind of error do we expect?
		except:
			stale = True
		else:
			stale = False
			for path in componentPath.parent().walk():
				if path.isfile() and path.splitext()[-1] == '.py':
					try:
						lastModified = path.getModificationTime()
					except:
						log.err("Could not stat {:s}".format(str(componentPath)))
					else:
						if lastModified > lastCached:
							stale = True
							break

		if stale:
			try:
				module = moduleObj.load()

				if type(module.__components__) is dict:
					def loaded (collection):
						try:
							dropinPath.setContent(pickle.dumps(collection))
						except OSError as e:
							log.err("Unable to write cache file {:s}".format(dropinPath))

						return collection

					results.append(_generateCacheEntry(module).addCallback(loaded))
			except (KeyError, AttributeError) as e:
				log.err("Component module {:s} failed to load".format(componentPath))
			except:
				log.err()
		else:
			results.append(defer.succeed(collection))

	d = defer.Deferred()
	defer.gatherResults(results).addCallbacks(d.callback, d.errback)
	return d