Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _resolve(self, query, default):
# :* -> non-recursive
# :** -> recursive
query = ":".join(p if p else "*" for p in query.strip().split(":"))
try:
qquery = ":" + query.replace(":**", "")
if self.root._type == self.Type.PARSER:
qquery = ":lbuild" + qquery
found_modules = BaseNode.resolver.glob(self.root, qquery)
except (anytree.resolver.ChildResolverError, anytree.resolver.ResolverError):
return default
modules = found_modules
if query.endswith(":**"):
for module in found_modules:
modules.extend(module.descendants)
return modules if modules else default
self._format_short_description = lbuild.format.format_short_description
self._submodules = []
self._options = []
self._filters = []
self._queries = []
self._ignore_patterns = []
self._configurations = []
def init(self):
lbuild.utils.with_forward_exception(self,
lambda: self._functions['init'](lf.RepositoryInitFacade(self)))
return Repository(self)
class Repository(BaseNode):
"""
A repository is a set of modules.
"""
def __init__(self, repo: RepositoryInit):
"""
Construct a new repository object.
At the construction time of the object, the name of repository may not
be known e.g. if the repository is loaded from a `repo.lb` file.
"""
BaseNode.__init__(self, repo.name, self.Type.REPOSITORY, self)
self._filename = repo._filename
self._description = repo.description
self._functions = repo._functions
import sys
import glob
import logging
import fnmatch
import lbuild.utils
import lbuild.exception as le
import lbuild.facade as lf
from .node import BaseNode
LOGGER = logging.getLogger('lbuild.repository')
class Configuration(BaseNode):
def __init__(self, name, path, description):
BaseNode.__init__(self, name, BaseNode.Type.CONFIG)
self._config = path
if description is None:
description = ""
self._description = description
def load_repository_from_file(parser, filename):
repo = RepositoryInit(parser, filename)
try:
repo._functions = lbuild.node.load_functions_from_file(
repo, filename,
required=['init', 'prepare'], optional=['build'])
except FileNotFoundError as error:
raise le.LbuildParserAddRepositoryNotFoundException(parser, filename)
msg += "\n\n{}".format(root.render(lambda n: n.type in lbuild.node.BaseNode.Type))
return msg
for submodule in self._submodules:
if isinstance(submodule, str):
modules = load_module_from_file(repository=self.repository,
filename=os.path.join(self.filepath, submodule),
parent=self.fullname)
else:
modules = load_module_from_object(repository=self.repository,
module_obj=submodule,
filename=self.filename,
parent=self.fullname)
all_modules.extend(modules)
return all_modules
class Module(BaseNode):
def __init__(self, module: ModuleInit):
"""
Create new module definition.
Args:
repository: Parent repository of the module.
filename: Full path of the module file.
path: Path to the module file. Used as base for relative paths
during the building step of the module.
"""
BaseNode.__init__(self, module.name, self.Type.MODULE, module.repository)
self._filename = module.filename
self._functions = module.functions
self._description = module.description
def ansi_escape(obj=None):
if PLAIN:
# The terminal does not support color
return ""
COLORFUL_REPLACEMENT = {
"reset": "\033[0m",
"bold": "\033[1m",
"underlined": "\033[4m",
"no_bold": "\033[22m",
"no_underlined": "\033[24m",
"close_fg_color": "\033[39m",
}
name = obj
if isinstance(obj, lbuild.node.BaseNode):
name = obj.type.name.lower()
col = COLOR_SCHEME.get(name, "nope")
if col == "nope":
col = COLORFUL_REPLACEMENT.get(name, None)
return str(col) if col is not None else ""
def _dump(node):
msg = ""
if isinstance(node, lbuild.node.BaseNode):
root = node.root
msg = "\n\n\n{}".format(_hl("Current project configuration:"))
# Render configuration if we know it
if isinstance(root, lbuild.parser.Parser):
msg += "\n\n{}".format(root._config.root.render())
# Render as much tree in developer view as possible
msg += "\n\n{}".format(root.render(lambda n: n.type in lbuild.node.BaseNode.Type))
return msg