2022-11-14 09:54:07 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
#
|
|
|
|
|
# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
|
2023-01-03 10:36:07 +00:00
|
|
|
# Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
|
2022-11-14 09:54:07 +00:00
|
|
|
# Licensed under the GNU General Public License, Version 3:
|
|
|
|
|
# https://www.gnu.org/licenses
|
|
|
|
|
# Public project repositories:
|
|
|
|
|
# https://github.com/mmgen/mmgen
|
|
|
|
|
# https://gitlab.com/mmgen/mmgen
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
test.overlay.__init__: Initialize the MMGen test suite overlay tree
|
|
|
|
|
"""
|
|
|
|
|
|
2021-10-10 20:18:14 +00:00
|
|
|
import sys,os,shutil
|
2021-10-03 17:40:02 +00:00
|
|
|
|
2022-10-24 16:50:04 +00:00
|
|
|
def get_overlay_tree_dir(repo_root):
|
2022-02-03 20:40:41 +00:00
|
|
|
return os.path.join(repo_root,'test','overlay','tree')
|
|
|
|
|
|
2021-10-05 11:57:34 +00:00
|
|
|
def overlay_setup(repo_root):
|
2021-10-03 17:40:02 +00:00
|
|
|
|
2022-10-24 16:50:05 +00:00
|
|
|
def process_srcdir(pkgname,d):
|
2022-02-06 13:28:45 +00:00
|
|
|
relpath = d.split('.')
|
|
|
|
|
srcdir = os.path.join(repo_root,*relpath)
|
2022-10-24 16:50:04 +00:00
|
|
|
destdir = os.path.join(overlay_tree_dir,*relpath)
|
2022-10-24 16:50:05 +00:00
|
|
|
fakemod_dir = os.path.join(fakemod_root,pkgname,*(relpath[1:]))
|
2021-10-03 17:40:02 +00:00
|
|
|
os.makedirs(destdir)
|
|
|
|
|
for fn in os.listdir(srcdir):
|
|
|
|
|
if (
|
|
|
|
|
fn.endswith('.py') or
|
2022-10-24 16:50:05 +00:00
|
|
|
d == f'{pkgname}.data' or
|
|
|
|
|
(d == f'mmgen.proto.secp256k1' and fn.startswith('secp256k1'))
|
2021-10-03 17:40:02 +00:00
|
|
|
):
|
2022-02-06 13:28:45 +00:00
|
|
|
if os.path.exists(os.path.join(fakemod_dir,fn)):
|
2021-10-10 20:18:14 +00:00
|
|
|
make_link(
|
2021-10-03 17:40:02 +00:00
|
|
|
os.path.join(fakemod_dir,fn),
|
|
|
|
|
os.path.join(destdir,fn) )
|
2021-10-13 20:44:43 +00:00
|
|
|
# link_fn = fn.removesuffix('.py') + '_orig.py' # Python 3.9
|
|
|
|
|
link_fn = fn[:-3] + '_orig.py'
|
2021-10-03 17:40:02 +00:00
|
|
|
else:
|
|
|
|
|
link_fn = fn
|
2021-10-10 20:18:14 +00:00
|
|
|
make_link(
|
2021-10-03 17:40:02 +00:00
|
|
|
os.path.join(srcdir,fn),
|
|
|
|
|
os.path.join(destdir,link_fn) )
|
|
|
|
|
|
2022-10-24 16:50:04 +00:00
|
|
|
overlay_tree_dir = get_overlay_tree_dir(repo_root)
|
2022-10-24 16:50:05 +00:00
|
|
|
fakemod_root = os.path.join(repo_root,'test','overlay','fakemods')
|
|
|
|
|
common_path = os.path.join(os.path.sep,'test','overlay','fakemods')
|
|
|
|
|
pkgdata = ((
|
|
|
|
|
os.path.realpath(e.path)[:-len(os.path.join(common_path,e.name))], # Python 3.9: removesuffix()
|
|
|
|
|
e.name
|
|
|
|
|
) for e in os.scandir(fakemod_root) if e.is_dir() )
|
2021-10-10 20:18:14 +00:00
|
|
|
|
2022-10-24 16:50:05 +00:00
|
|
|
for repodir,pkgname in pkgdata:
|
|
|
|
|
if not os.path.exists(os.path.join(overlay_tree_dir,pkgname)):
|
|
|
|
|
|
|
|
|
|
sys.stderr.write(f'Setting up overlay tree: {pkgname}\n')
|
|
|
|
|
|
|
|
|
|
make_link = os.symlink if sys.platform == 'linux' else shutil.copy2
|
|
|
|
|
shutil.rmtree(os.path.join(overlay_tree_dir,pkgname),ignore_errors=True)
|
|
|
|
|
|
|
|
|
|
import configparser
|
|
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
|
cfg.read(os.path.join(repodir,'setup.cfg'))
|
|
|
|
|
|
|
|
|
|
for d in cfg.get('options','packages').split():
|
|
|
|
|
process_srcdir(pkgname,d)
|
2021-10-03 17:40:02 +00:00
|
|
|
|
2023-09-26 09:40:12 +00:00
|
|
|
sys.path.insert(0,overlay_tree_dir)
|
|
|
|
|
|
2022-10-24 16:50:04 +00:00
|
|
|
return overlay_tree_dir
|