text
stringlengths 0
828
|
|---|
if formula in LEGACY_MAPPINGS:
|
formula = LEGACY_MAPPINGS[formula]
|
formula_class, formula_url = formula, None
|
if ':' in formula:
|
formula_class, formula_url = formula.split("":"", 1)
|
if formula_class not in self._formula_dict:
|
try:
|
self._formula_dict[formula_class] = lib.get_subclass_from_module(formula_class, FormulaBase)
|
except (SprinterException, ImportError):
|
logger.info(""Downloading %s..."" % formula_class)
|
try:
|
self._pip.install_egg(formula_url or formula_class)
|
try:
|
self._formula_dict[formula_class] = lib.get_subclass_from_module(formula_class, FormulaBase)
|
except ImportError:
|
logger.debug(""FeatureDict import Error"", exc_info=sys.exc_info())
|
raise SprinterException(""Error: Unable to retrieve formula %s!"" % formula_class)
|
except PipException:
|
logger.error(""ERROR: Unable to download %s!"" % formula_class)
|
return self._formula_dict[formula_class]"
|
1126,"def is_backup_class(cls):
|
""""""Return true if given class supports back up. Currently this means a
|
gludb.data.Storable-derived class that has a mapping as defined in
|
gludb.config""""""
|
return True if (
|
isclass(cls) and
|
issubclass(cls, Storable) and
|
get_mapping(cls, no_mapping_ok=True)
|
) else False"
|
1127,"def add_package(
|
self,
|
pkg_name,
|
recurse=True,
|
include_bases=True,
|
parent_pkg=None
|
):
|
""""""Add all classes to the backup in the specified package (including
|
all modules and all sub-packages) for which is_backup_class returns
|
True. Note that self.add_class is used, so base classes will added as
|
well.
|
Parameters:
|
* pkg_name - a string representing the package name. It may be
|
relative _if_ parent_pkg is supplied as well
|
* recurse - (default value of True) if False, sub-packages will _not_
|
be examined
|
* include_bases - (default value of True) is passed directly to
|
add_class for every class added
|
* parent_pkg - a string representing the parent package of the relative
|
package specified in pkg_name. Note that you should specify
|
parent_pkg _only_ if pkg_name should be interpreted as relative
|
An an example of both relative and absolute package imports, these
|
are equivalent:
|
````
|
backup.add_package('toppackage.subpackage')
|
backup.add_package('subpackage', parent_pkg='toppackage')
|
````
|
""""""
|
if parent_pkg:
|
pkg = import_module('.' + pkg_name, parent_pkg)
|
else:
|
pkg = import_module(pkg_name)
|
for module_loader, name, ispkg in pkgutil.walk_packages(pkg.__path__):
|
if not ispkg:
|
# Module
|
mod = import_module('.' + name, pkg_name)
|
for name, member in getmembers(mod):
|
if is_backup_class(member):
|
self.add_class(member, include_bases=include_bases)
|
elif recurse:
|
# Package and we're supposed to recurse
|
self.add_package(
|
pkg_name + '.' + name,
|
recurse=True,
|
include_bases=include_bases,
|
parent_pkg=parent_pkg
|
)"
|
1128,"def add_class(self, cls, include_bases=True):
|
""""""Add the specified class (which should be a class object, _not_ a
|
string). By default all base classes for which is_backup_class returns
|
True will also be added. `include_bases=False` may be spcified to
|
suppress this behavior. The total number of classes added is returned.
|
Note that if is_backup_class does not return True for the class object
|
passed in, 0 will be returned. If you specify include_bases=False, then
|
the maximum value that can be returned is 1.""""""
|
if not is_backup_class(cls):
|
return 0
|
added = 0
|
cls_name = backup_name(cls)
|
if cls_name not in self.classes:
|
self.classes[cls_name] = cls
|
self.log(""Added class for backup: %s"", cls_name)
|
added = 1
|
if include_bases:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.