__init__.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import sys,os,shutil
  2. def overlay_setup(repo_root):
  3. def process_srcdir(d):
  4. srcdir = os.path.join(repo_root,*d.split('.'))
  5. destdir = os.path.join(overlay_dir,*d.split('.'))
  6. os.makedirs(destdir)
  7. for fn in os.listdir(srcdir):
  8. if (
  9. fn.endswith('.py') or
  10. d == 'mmgen.data' or
  11. d == 'mmgen' and fn.startswith('secp256k1')
  12. ):
  13. if fn in fakemods:
  14. make_link(
  15. os.path.join(fakemod_dir,fn),
  16. os.path.join(destdir,fn) )
  17. # link_fn = fn.removesuffix('.py') + '_orig.py' # Python 3.9
  18. link_fn = fn[:-3] + '_orig.py'
  19. else:
  20. link_fn = fn
  21. make_link(
  22. os.path.join(srcdir,fn),
  23. os.path.join(destdir,link_fn) )
  24. overlay_dir = os.path.join(repo_root,'test','overlay','tree')
  25. fakemod_dir = os.path.join(repo_root,'test','overlay','fakemods')
  26. fakemods = os.listdir(fakemod_dir)
  27. make_link = os.symlink if sys.platform == 'linux' else shutil.copy2
  28. if not os.path.exists(os.path.join(overlay_dir,'mmgen','main.py')):
  29. sys.stderr.write('Setting up overlay tree\n')
  30. shutil.rmtree(overlay_dir,ignore_errors=True)
  31. for d in (
  32. 'mmgen',
  33. 'mmgen.data',
  34. 'mmgen.share',
  35. 'mmgen.altcoins',
  36. 'mmgen.altcoins.eth',
  37. 'mmgen.altcoins.eth.pyethereum',
  38. 'mmgen.altcoins.eth.rlp',
  39. 'mmgen.altcoins.eth.rlp.sedes' ):
  40. process_srcdir(d)
  41. return overlay_dir