1 |
commit: a48532754eae8ea3dfa491968000313872b18241 |
2 |
Author: Florian Schmaus <flo <AT> geekplace <DOT> eu> |
3 |
AuthorDate: Tue Aug 18 19:48:34 2020 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Aug 22 15:32:06 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a4853275 |
7 |
|
8 |
util: add portage.util.hooks.get_hooks_from_dir() |
9 |
|
10 |
Signed-off-by: Florian Schmaus <flo <AT> geekplace.eu> |
11 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
12 |
|
13 |
lib/portage/dispatch_conf.py | 1 + |
14 |
lib/portage/sync/controller.py | 16 ++-------------- |
15 |
lib/portage/util/hooks.py | 31 +++++++++++++++++++++++++++++++ |
16 |
3 files changed, 34 insertions(+), 14 deletions(-) |
17 |
|
18 |
diff --git a/lib/portage/dispatch_conf.py b/lib/portage/dispatch_conf.py |
19 |
index 0356ba7bc..3ef659852 100644 |
20 |
--- a/lib/portage/dispatch_conf.py |
21 |
+++ b/lib/portage/dispatch_conf.py |
22 |
@@ -18,6 +18,7 @@ from portage import _encodings, os, shutil |
23 |
from portage.env.loaders import KeyValuePairFileLoader |
24 |
from portage.localization import _ |
25 |
from portage.util import shlex_split, varexpand |
26 |
+from portage.util.hooks import perform_hooks |
27 |
from portage.util.path import iter_parents |
28 |
|
29 |
RCS_BRANCH = '1.1.1' |
30 |
|
31 |
diff --git a/lib/portage/sync/controller.py b/lib/portage/sync/controller.py |
32 |
index 0f42b1da9..f1d706d7e 100644 |
33 |
--- a/lib/portage/sync/controller.py |
34 |
+++ b/lib/portage/sync/controller.py |
35 |
@@ -7,8 +7,6 @@ import grp |
36 |
import pwd |
37 |
import warnings |
38 |
|
39 |
-from collections import OrderedDict |
40 |
- |
41 |
import portage |
42 |
from portage import os |
43 |
from portage.progress import ProgressBar |
44 |
@@ -20,9 +18,9 @@ bad = create_color_func("BAD") |
45 |
warn = create_color_func("WARN") |
46 |
from portage.package.ebuild.doebuild import _check_temp_dir |
47 |
from portage.metadata import action_metadata |
48 |
+from portage.util.hooks import get_hooks_from_dir |
49 |
from portage.util._async.AsyncFunction import AsyncFunction |
50 |
from portage import _unicode_decode |
51 |
-from portage import util |
52 |
from _emerge.CompositeTask import CompositeTask |
53 |
|
54 |
|
55 |
@@ -93,17 +91,7 @@ class SyncManager: |
56 |
self.module_names = self.module_controller.module_names |
57 |
self.hooks = {} |
58 |
for _dir in ["repo.postsync.d", "postsync.d"]: |
59 |
- postsync_dir = os.path.join(self.settings["PORTAGE_CONFIGROOT"], |
60 |
- portage.USER_CONFIG_PATH, _dir) |
61 |
- hooks = OrderedDict() |
62 |
- for filepath in util._recursive_file_list(postsync_dir): |
63 |
- name = filepath.split(postsync_dir)[1].lstrip(os.sep) |
64 |
- if os.access(filepath, os.X_OK): |
65 |
- hooks[filepath] = name |
66 |
- else: |
67 |
- writemsg_level(" %s %s hook: '%s' is not executable\n" |
68 |
- % (warn("*"), _dir, _unicode_decode(name),), |
69 |
- level=logging.WARN, noiselevel=2) |
70 |
+ hooks = get_hooks_from_dir(_dir, prefix=self.settings["PORTAGE_CONFIGROOT"]) |
71 |
self.hooks[_dir] = hooks |
72 |
|
73 |
def __getattr__(self, name): |
74 |
|
75 |
diff --git a/lib/portage/util/hooks.py b/lib/portage/util/hooks.py |
76 |
new file mode 100644 |
77 |
index 000000000..d10ec7a59 |
78 |
--- /dev/null |
79 |
+++ b/lib/portage/util/hooks.py |
80 |
@@ -0,0 +1,31 @@ |
81 |
+# Copyright 2014-2021 Gentoo Authors |
82 |
+# Distributed under the terms of the GNU General Public License v2 |
83 |
+ |
84 |
+import logging |
85 |
+ |
86 |
+from collections import OrderedDict |
87 |
+ |
88 |
+import portage |
89 |
+ |
90 |
+from portage import os |
91 |
+from portage.output import create_color_func |
92 |
+from portage.util import writemsg_level, _recursive_file_list |
93 |
+from warnings import warn |
94 |
+ |
95 |
+warn = create_color_func("WARN") |
96 |
+ |
97 |
+ |
98 |
+def get_hooks_from_dir(rel_directory, prefix="/"): |
99 |
+ directory = os.path.join(prefix, portage.USER_CONFIG_PATH, rel_directory) |
100 |
+ |
101 |
+ hooks = OrderedDict() |
102 |
+ for filepath in _recursive_file_list(directory): |
103 |
+ name = filepath.split(directory)[1].lstrip(portage.os.sep) |
104 |
+ if portage.os.access(filepath, portage.os.X_OK): |
105 |
+ hooks[filepath] = name |
106 |
+ else: |
107 |
+ writemsg_level(" %s %s hook: '%s' is not executable\n" % \ |
108 |
+ (warn("*"), directory, portage._unicode_decode(name),), |
109 |
+ level=logging.WARN, noiselevel=2) |
110 |
+ |
111 |
+ return hooks |