Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_config_file():
tcf = tempfile.TemporaryFile(mode="w+")
tcf.write(EXAMPLE_CONFIG.format(
build_root = build_root,
cache_root = cache_root,
cores_root = cores_root,
library_root = library_root
)
)
tcf.seek(0)
conf = Config(file=tcf)
assert conf.build_root == build_root
def test_config_libraries():
tcf = tempfile.NamedTemporaryFile(mode="w+")
tcf.write(EXAMPLE_CONFIG.format(
build_root = build_root,
cache_root = cache_root,
cores_root = cores_root,
library_root = library_root
)
)
tcf.seek(0)
conf = Config(path=tcf.name)
lib = None
for library in conf.libraries:
if library.name == 'test_lib':
lib = library
assert lib
assert lib.location == os.path.join(library_root, 'test_lib')
assert lib.sync_uri == 'https://github.com/fusesoc/fusesoc-cores'
assert not lib.auto_sync
def test_config_path():
tcf = tempfile.NamedTemporaryFile(mode="w+")
tcf.write(EXAMPLE_CONFIG.format(
build_root = build_root,
cache_root = cache_root,
cores_root = cores_root,
library_root = library_root
)
)
tcf.seek(0)
conf = Config(path=tcf.name)
assert conf.library_root == library_root
if sync_type == 'local':
logger.info("Interpreting sync-uri '{}' as location for local provider.".format(sync_uri))
location = os.path.abspath(sync_uri)
auto_sync = not args.no_auto_sync
library = Library(args.name, location, sync_type, sync_uri, auto_sync)
if args.config:
config = Config(file=args.config)
elif vars(args)['global']:
xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
os.path.join(os.path.expanduser('~'), '.config')
config_file = os.path.join(xdg_config_home, 'fusesoc', 'fusesoc.conf')
config = Config(path=config_file)
else:
config = Config(path="fusesoc.conf")
try:
config.add_library(library)
except RuntimeError as e:
logger.error("`add library` failed: " + str(e))
exit(1)
#Check if it's a dir. Otherwise fall back to git repo
if not sync_type:
if os.path.isdir(sync_uri):
sync_type = 'local'
else:
sync_type = 'git'
if sync_type == 'local':
logger.info("Interpreting sync-uri '{}' as location for local provider.".format(sync_uri))
location = os.path.abspath(sync_uri)
auto_sync = not args.no_auto_sync
library = Library(args.name, location, sync_type, sync_uri, auto_sync)
if args.config:
config = Config(file=args.config)
elif vars(args)['global']:
xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
os.path.join(os.path.expanduser('~'), '.config')
config_file = os.path.join(xdg_config_home, 'fusesoc', 'fusesoc.conf')
config = Config(path=config_file)
else:
config = Config(path="fusesoc.conf")
try:
config.add_library(library)
except RuntimeError as e:
logger.error("`add library` failed: " + str(e))
exit(1)
def main():
args = parse_args()
if not args:
exit(0)
logger.debug("Command line arguments: " + str(sys.argv))
init_logging(args.verbose, args.monochrome, args.log_file)
config = Config(file=args.config)
cm = init_coremanager(config, args.cores_root)
# Run the function
args.func(cm, args)
def run(args):
cm = CoreManager()
config = Config()
# Get the environment variable for further cores
env_cores_root = []
if os.getenv("FUSESOC_CORES"):
env_cores_root = os.getenv("FUSESOC_CORES").split(":")
env_cores_root.reverse()
for cores_root in [config.cores_root,
config.systems_root,
env_cores_root,
args.cores_root]:
try:
cm.add_cores_root(cores_root)
except (RuntimeError, IOError) as e:
pr_warn("Failed to register cores root '{}'".format(str(e)))
# Process global options
def configure(self, args):
if os.path.exists(self.work_root):
for f in os.listdir(self.work_root):
if os.path.isdir(os.path.join(self.work_root, f)):
shutil.rmtree(os.path.join(self.work_root, f))
else:
os.remove(os.path.join(self.work_root, f))
else:
os.makedirs(self.work_root)
for name in self.cores:
pr_info("Preparing " + str(name))
core = self.cm.get_core(name)
dst_dir = os.path.join(Config().build_root, self.system.sanitized_name, 'src', core.sanitized_name)
try:
core.setup()
except URLError as e:
raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
except HTTPError as e:
raise RuntimeError("Problem while fetching '" + core.name + "': " + str(e.reason))
core.export(dst_dir)
def pr_err(msg):
if Config().monochrome:
print('ERROR: ' + msg)
else:
print('\033[1;31m' + 'ERROR: ' + msg + '\033[0m')
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Config, cls).__new__(cls, *args, **kwargs)
return cls._instance