mmgen-wallet/test/overlay/__init__.py

71 lines
2.2 KiB
Python
Raw Normal View History

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
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')
def overlay_setup(repo_root):
def process_srcdir(pkgname,d):
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)
fakemod_dir = os.path.join(fakemod_root,pkgname,*(relpath[1:]))
os.makedirs(destdir)
for fn in os.listdir(srcdir):
if (
fn.endswith('.py') or
d == f'{pkgname}.data' or
(d == f'mmgen.proto.secp256k1' and fn.startswith('secp256k1'))
):
if os.path.exists(os.path.join(fakemod_dir,fn)):
2021-10-10 20:18:14 +00:00
make_link(
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'
else:
link_fn = fn
2021-10-10 20:18:14 +00:00
make_link(
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)
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
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)
sys.path.insert(0,overlay_tree_dir)
2022-10-24 16:50:04 +00:00
return overlay_tree_dir