mmgen-wallet/test/overlay/__init__.py

70 lines
2.2 KiB
Python
Raw Normal View History

2022-11-14 09:54:07 +00:00
#!/usr/bin/env python3
#
2024-10-18 10:32:06 +00:00
# MMGen Wallet, a terminal-based cryptocurrency wallet
2026-02-11 13:02:12 +00:00
# Copyright (C)2013-2026 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-wallet
# https://gitlab.com/mmgen/mmgen-wallet
2022-11-14 09:54:07 +00:00
"""
test.overlay.__init__: Initialize the MMGen test suite overlay tree
"""
2024-10-18 10:32:13 +00:00
import sys, os, shutil
2022-10-24 16:50:04 +00:00
def get_overlay_tree_dir(repo_root):
2024-10-18 10:32:13 +00:00
return os.path.join(repo_root, 'test', 'overlay', 'tree')
2022-02-03 20:40:41 +00:00
def overlay_setup(repo_root):
2024-10-18 10:32:13 +00:00
def process_srcdir(pkgname, d):
relpath = d.split('.')
2024-10-18 10:32:13 +00:00
srcdir = os.path.join(repo_root, *relpath)
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 == 'mmgen.proto.secp256k1' and fn.startswith('secp256k1'))
):
2024-10-18 10:32:13 +00:00
if fn.endswith('.py') and os.path.exists(os.path.join(fakemod_dir, fn)):
2021-10-10 20:18:14 +00:00
make_link(
2024-10-18 10:32:13 +00:00
os.path.join(fakemod_dir, fn),
os.path.join(destdir, fn))
2024-02-10 15:10:43 +00:00
link_fn = fn.removesuffix('.py') + '_orig.py'
else:
link_fn = fn
2021-10-10 20:18:14 +00:00
make_link(
2024-10-18 10:32:13 +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)
2024-10-18 10:32:13 +00:00
fakemod_root = os.path.join(repo_root, 'test', 'overlay', 'fakemods')
common_path = os.path.join(os.path.sep, 'test', 'overlay', 'fakemods')
pkgdata = ((
2024-10-18 10:32:13 +00:00
os.path.realpath(e.path).removesuffix(os.path.join(common_path, e.name)),
e.name
2024-10-18 10:32:13 +00:00
) for e in os.scandir(fakemod_root) if e.is_dir())
2021-10-10 20:18:14 +00:00
2024-10-18 10:32:13 +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 in ('linux', 'darwin') else shutil.copy2
2024-10-18 10:32:13 +00:00
shutil.rmtree(os.path.join(overlay_tree_dir, pkgname), ignore_errors=True)
import configparser
cfg = configparser.ConfigParser()
2024-10-18 10:32:13 +00:00
cfg.read(os.path.join(repodir, 'setup.cfg'))
2024-10-18 10:32:13 +00:00
for d in cfg.get('options', 'packages').split():
process_srcdir(pkgname, d)
2024-10-18 10:32:13 +00:00
sys.path.insert(0, overlay_tree_dir)
2022-10-24 16:50:04 +00:00
return overlay_tree_dir