Commit 5d46680d authored by Benjamin Winger's avatar Benjamin Winger

Added support for whitelisting/blacklisting files in an installdir

parent 07739fa4
......@@ -5,6 +5,7 @@ from typing import AbstractSet, List
import os
import sys
import shutil
from urllib.parse import urlparse
from pathlib import Path
from distutils.dir_util import copy_tree
......@@ -30,6 +31,8 @@ class InstallDir:
self.PLUGINS = kwargs.get("PLUGINS", [])
self.ARCHIVES = kwargs.get("ARCHIVES", [])
self.SOURCE = kwargs.get("SOURCE", None)
self.WHITELIST = kwargs.get("WHITELIST", None)
self.BLACKLIST = kwargs.get("BLACKLIST", None)
class File:
......@@ -281,7 +284,24 @@ class Pybuild1(Pybuild):
):
os.remove(os.path.join(source, file.NAME))
copy_tree(source, dest)
if install_dir.BLACKLIST is not None:
for file in install_dir.BLACKLIST:
src_path = os.path.join(source, file)
if os.path.isdir(src_path):
shutil.rmtree(src_path)
else:
os.remove(src_path)
if install_dir.WHITELIST is not None:
for file in install_dir.WHITELIST:
src_path = os.path.join(source, file)
dst_path = os.path.join(dest, file)
if os.path.isdir(src_path):
copy_tree(src_path, dst_path)
else:
shutil.copy(src_path, dst_path)
else:
copy_tree(source, dest)
else:
print(
"Skipping directory {} due to unsatisfied use "
......@@ -349,6 +369,27 @@ class Pybuild1(Pybuild):
except Exception as e:
errors.append("Error processing dir {}: {}".format(install.PATH, e))
if install.WHITELIST is not None and type(install.WHITELIST) is not list:
errors.append("WHITELIST {} must be a list".format(install.WHITELIST))
elif install.WHITELIST is not None:
for string in install.WHITELIST:
if type(string) is not str:
errors.append(
"{} in InstallDir WHITELIST is not a string".format(string)
)
if install.BLACKLIST is not None and type(install.BLACKLIST) is not list:
errors.append("BLACKLIST {} must be a list".format(install.BLACKLIST))
elif install.BLACKLIST is not None:
for string in install.BLACKLIST:
if type(string) is not str:
errors.append(
"{} in InstallDir BLACKLIST is not a string".format(string)
)
if install.WHITELIST is not None and install.BLACKLIST is not None:
errors.append("WHITELIST and BLACKLIST are mutually exclusive")
global_use = get_global_use(self.__REPO_PATH)
metadata = get_mod_metadata(self)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment