def perspective_getPlugEntry(self, plugType, entryType): """ Get the entry point for a piece of bundled code in a plug by type. @param plugType: the plug @type plugType: a string @param entryType: location of the entry point @type entryType: a string Returns: a (filename, methodName) tuple, or raises:: - NoBundleError if the entry location does not exist """ assert plugType is not None self.debug('getting entry of type %s for plug type %s', entryType, plugType) try: plugRegistryEntry = registry.getRegistry().getPlug(plugType) entry = plugRegistryEntry.getEntryByType(entryType) except KeyError: self.warning("Could not find bundle for %s(%s)" % ( plugType, entryType)) raise errors.NoBundleError("entry type %s in plug type %s" % (entryType, plugType)) self.debug('entry point is in file path %s and function %s' % ( entry.location, entry.function)) return (entry.location, entry.function)
def perspective_getScenarioByType(self, scenarioType, entryType): """ Remote method that gets the scenario of a given type. @param scenarioType: the component @type scenarioType: a string Returns: a (filename, methodName) tuple, or raises:: - NoBundleError if the entry location does not exist """ assert scenarioType is not None self.debug('getting entry of type %s for scenario type %s', entryType, scenarioType) try: scenarioRegistryEntry = registry.getRegistry().getScenarioByType( scenarioType) # FIXME: add logic here for default entry points and functions entry = scenarioRegistryEntry.getEntryByType(entryType) except KeyError: self.warning("Could not find bundle for %s(%s)" % ( scenarioType, entryType)) raise errors.NoBundleError("entry type %s in component type %s" % (entryType, scenarioType)) filename = os.path.join(scenarioRegistryEntry.getBase(), entry.getLocation()) self.debug('entry point is in file path %s and function %s' % ( filename, entry.function)) return (filename, entry.getFunction())
def perspective_getEntryByType(self, componentType, entryType): """ Get the entry point for a piece of bundled code in a component by type. @param componentType: the component @type componentType: a string @param entryType: location of the entry point @type entryType: a string Returns: a (filename, methodName) tuple, or raises:: - NoBundleError if the entry location does not exist """ assert componentType is not None self.debug('getting entry of type %s for component type %s', entryType, componentType) try: componentRegistryEntry = registry.getRegistry().getComponent( componentType) # FIXME: add logic here for default entry points and functions entry = componentRegistryEntry.getEntryByType(entryType) except KeyError: self.warning("Could not find bundle for %s(%s)" % ( componentType, entryType)) raise errors.NoBundleError("entry type %s in component type %s" % (entryType, componentType)) filename = os.path.join(componentRegistryEntry.base, entry.location) self.debug('entry point is in file path %s and function %s' % ( filename, entry.function)) return (filename, entry.function)
def unpackAndRegister((zips, toFetch, sums)): for name in toFetch: if name not in zips: msg = "Missing bundle %s was not received" self.warning(msg, name) raise errors.NoBundleError(msg % name) b = bundle.Bundle(name) b.setZip(zips[name]) path = self._unbundler.unbundle(b) # register all package paths; to do so we need to reverse sums sums.reverse() ret = [] for name, md5 in sums: self.log('registerPackagePath for %s' % name) path = os.path.join(configure.cachedir, name, md5) if not os.path.exists(path): self.warning("path %s for bundle %s does not exist", path, name) else: package.getPackager().registerPackagePath(path, name) ret.append((name, path)) return ret
def getDependencies(self, bundlerName): """ Return names of all the dependencies of this bundle, including this bundle itself. The dependencies are returned in a correct depending order. """ if not bundlerName in self._bundlers: raise errors.NoBundleError('Unknown bundle %s' % bundlerName) elif not self._graph.hasNode(bundlerName): return [bundlerName] else: return [bundlerName] + self._graph.getOffspring(bundlerName)
def perspective_getBundleZips(self, bundles): """ Get the zip files for the given list of bundles. @param bundles: the names of the bundles to get @type bundles: list of str @returns: dictionary of bundleName -> zipdata @rtype: dict of str -> str """ basket = self.vishnu.getBundlerBasket() zips = {} for name in bundles: bundler = basket.getBundlerByName(name) if not bundler: raise errors.NoBundleError( 'The bundle named "%s" was not found' % (name, )) zips[name] = bundler.bundle().getZip() return zips
def perspective_getBundleSumsByFile(self, filename): """ Get a list of (bundleName, md5sum) of all dependency bundles, starting with this bundle, in the correct order. @param filename: the name of the file in a bundle @type filename: str @returns: list of (bundleName, md5sum) tuples @rtype: list of (str, str) tuples """ self.debug('asked to get bundle sums for file %s' % filename) basket = self.vishnu.getBundlerBasket() bundleName = basket.getBundlerNameByFile(filename) if not bundleName: self.warning('Did not find a bundle for file %s' % filename) raise errors.NoBundleError("for file %s" % filename) return self.perspective_getBundleSums(bundleName)
def perspective_getBundleSums(self, bundleName=None, fileName=None, moduleName=None): """ Get a list of (bundleName, md5sum) of all dependency bundles, starting with this bundle, in the correct order. Any of bundleName, fileName, moduleName may be given. @type bundleName: str or list of str @param bundleName: the name of the bundle for fetching @type fileName: str or list of str @param fileName: the name of the file requested for fetching @type moduleName: str or list of str @param moduleName: the name of the module requested for import @rtype: list of (str, str) tuples of (bundleName, md5sum) """ bundleNames = [] fileNames = [] moduleNames = [] if bundleName: if isinstance(bundleName, str): bundleNames.append(bundleName) else: bundleNames.extend(bundleName) self.debug('asked to get bundle sums for bundles %r' % bundleName) if fileName: if isinstance(fileName, str): fileNames.append(fileName) else: fileNames.extend(fileName) self.debug('asked to get bundle sums for files %r' % fileNames) if moduleName: if isinstance(moduleName, str): moduleNames.append(moduleName) else: moduleNames.extend(moduleName) self.debug('asked to get bundle sums for modules %r' % moduleNames) basket = self.vishnu.getBundlerBasket() # will raise an error if bundleName not known for fileName in fileNames: bundleName = basket.getBundlerNameByFile(fileName) if not bundleName: msg = 'containing ' + fileName self.warning('No bundle %s' % msg) raise errors.NoBundleError(msg) else: bundleNames.append(bundleName) for moduleName in moduleNames: bundleName = basket.getBundlerNameByImport(moduleName) if not bundleName: msg = 'for module ' + moduleName self.warning('No bundle %s' % msg) raise errors.NoBundleError(msg) else: bundleNames.append(bundleName) deps = [] for bundleName in bundleNames: thisdeps = basket.getDependencies(bundleName) self.debug('dependencies of %s: %r' % (bundleName, thisdeps[1:])) deps.extend(thisdeps) sums = [] for dep in deps: bundler = basket.getBundlerByName(dep) if not bundler: self.warning('Did not find bundle with name %s' % dep) else: sums.append((dep, bundler.bundle().md5sum)) self.debug('requested bundles: %r' % [x[0] for x in sums]) return sums