commit: a48532754eae8ea3dfa491968000313872b18241
Author: Florian Schmaus <flo <AT> geekplace <DOT> eu>
AuthorDate: Tue Aug 18 19:48:34 2020 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Aug 22 15:32:06 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a4853275
util: add portage.util.hooks.get_hooks_from_dir()
Signed-off-by: Florian Schmaus <flo <AT> geekplace.eu>
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
lib/portage/dispatch_conf.py | 1 +
lib/portage/sync/controller.py | 16 ++--------------
lib/portage/util/hooks.py | 31 +++++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/lib/portage/dispatch_conf.py b/lib/portage/dispatch_conf.py
index 0356ba7bc..3ef659852 100644
--- a/lib/portage/dispatch_conf.py
+++ b/lib/portage/dispatch_conf.py
@@ -18,6 +18,7 @@ from portage import _encodings, os, shutil
from portage.env.loaders import KeyValuePairFileLoader
from portage.localization import _
from portage.util import shlex_split, varexpand
+from portage.util.hooks import perform_hooks
from portage.util.path import iter_parents
RCS_BRANCH = '1.1.1'
diff --git a/lib/portage/sync/controller.py b/lib/portage/sync/controller.py
index 0f42b1da9..f1d706d7e 100644
--- a/lib/portage/sync/controller.py
+++ b/lib/portage/sync/controller.py
@@ -7,8 +7,6 @@ import grp
import pwd
import warnings
-from collections import OrderedDict
-
import portage
from portage import os
from portage.progress import ProgressBar
@@ -20,9 +18,9 @@ bad = create_color_func("BAD")
warn = create_color_func("WARN")
from portage.package.ebuild.doebuild import _check_temp_dir
from portage.metadata import action_metadata
+from portage.util.hooks import get_hooks_from_dir
from portage.util._async.AsyncFunction import AsyncFunction
from portage import _unicode_decode
-from portage import util
from _emerge.CompositeTask import CompositeTask
@@ -93,17 +91,7 @@ class SyncManager:
self.module_names = self.module_controller.module_names
self.hooks = {}
for _dir in ["repo.postsync.d", "postsync.d"]:
- postsync_dir =
os.path.join(self.settings["PORTAGE_CONFIGROOT"],
- portage.USER_CONFIG_PATH, _dir)
- hooks = OrderedDict()
- for filepath in util._recursive_file_list(postsync_dir):
- name =
filepath.split(postsync_dir)[1].lstrip(os.sep)
- if os.access(filepath, os.X_OK):
- hooks[filepath] = name
- else:
- writemsg_level(" %s %s hook: '%s' is
not executable\n"
- % (warn("*"), _dir,
_unicode_decode(name),),
- level=logging.WARN,
noiselevel=2)
+ hooks = get_hooks_from_dir(_dir,
prefix=self.settings["PORTAGE_CONFIGROOT"])
self.hooks[_dir] = hooks
def __getattr__(self, name):
diff --git a/lib/portage/util/hooks.py b/lib/portage/util/hooks.py
new file mode 100644
index 000000000..d10ec7a59
--- /dev/null
+++ b/lib/portage/util/hooks.py
@@ -0,0 +1,31 @@
+# Copyright 2014-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import logging
+
+from collections import OrderedDict
+
+import portage
+
+from portage import os
+from portage.output import create_color_func
+from portage.util import writemsg_level, _recursive_file_list
+from warnings import warn
+
+warn = create_color_func("WARN")
+
+
+def get_hooks_from_dir(rel_directory, prefix="/"):
+ directory = os.path.join(prefix, portage.USER_CONFIG_PATH,
rel_directory)
+
+ hooks = OrderedDict()
+ for filepath in _recursive_file_list(directory):
+ name = filepath.split(directory)[1].lstrip(portage.os.sep)
+ if portage.os.access(filepath, portage.os.X_OK):
+ hooks[filepath] = name
+ else:
+ writemsg_level(" %s %s hook: '%s' is not executable\n"
% \
+ (warn("*"), directory,
portage._unicode_decode(name),),
+ level=logging.WARN, noiselevel=2)
+
+ return hooks