Files
opm-common/python/install.py
T

47 lines
1.2 KiB
Python
Raw Normal View History

2019-10-06 17:05:05 +02:00
import sys
import os
import shutil
import compileall
import filecmp
2019-10-06 17:05:05 +02:00
src_root = sys.argv[1]
2019-10-06 17:08:05 +02:00
target_prefix = sys.argv[2]
2019-10-28 21:33:11 +01:00
install = int(sys.argv[3])
target_destdir = os.environ.get("DESTDIR", "")
if target_destdir != "":
target_prefix = target_destdir + target_prefix
2019-10-06 17:05:05 +02:00
if not os.path.isdir(src_root):
sys.exit("No such directory: {}".format(src_root))
2019-10-28 21:33:11 +01:00
2019-10-06 17:05:05 +02:00
path_offset = len(os.path.dirname(src_root))
for path,_ ,fnames in os.walk(src_root):
target_path = os.path.join(target_prefix, path[path_offset+1:])
if not os.path.isdir(target_path):
os.makedirs(target_path)
for f in fnames:
_, ext = os.path.splitext(f)
if ext == ".pyc":
continue
2019-10-28 21:33:11 +01:00
if ext == ".in":
continue
2019-10-06 17:05:05 +02:00
src_file = os.path.join(path, f)
target_file = os.path.join(target_path, f)
if not os.path.isfile(target_file):
shutil.copy(src_file, target_file)
elif not filecmp.cmp(src_file, target_file):
shutil.copy(src_file, target_file)
2019-10-06 17:05:05 +02:00
2019-10-28 21:33:11 +01:00
if install:
print("-- Installing: {}".format(target_file))
if install:
target_root = os.path.join(target_prefix, os.path.basename(src_root))
compileall.compile_dir(target_root)