Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH 2/2] portage/sync/controller.py: Make a per-repo postsync.d subdir
Date: Sun, 07 Dec 2014 04:52:08
Message-Id: 20141206205138.1a21411b.dolsen@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH 2/2] portage/sync/controller.py: Make a per-repo postsync.d subdir by Zac Medico
1 On Sat, 06 Dec 2014 18:04:28 -0800
2 Zac Medico <zmedico@g.o> wrote:
3
4 > On 12/06/2014 05:54 PM, Brian Dolbec wrote:
5 > > From b02b4dff30a7930d5308e400a46c3e59bbee0350 Mon Sep 17 00:00:00
6 > > 2001 From: Brian Dolbec <dolsen@g.o>
7 > > Date: Sat, 6 Dec 2014 14:54:36 -0800
8 > > Subject: [PATCH] portage/sync/controller.py: Make a repo.postsync.d
9 > > directory
10 > >
11 > > This then runs per-repo postsync hooks only on scripts in the
12 > > repo.postsync.d directory. This also maintains compatibility with
13 > > existing scripts in the postsync.d dir or other sub-directories.
14 > > Both postsync.d directories support subdirectories.
15 > > Scripts are run in sorted order.
16 >
17 > Thanks, LGTM.
18 >
19 > As an alternative to os.walk, we could use the
20 > portage.util._recursive_file_list function, which filters out VCS
21 > directories, hidden files, and files ending with ~. It yields the file
22 > names in sorted order, so it would make sense to store them in an
23 > OrderedDict so that they don't have to be sorted again later.
24
25 and again... ;) grumble, grumble
26
27 From c005006b290ff6b2c72c94aaa29b033a57c4414a Mon Sep 17 00:00:00 2001
28 From: Brian Dolbec <dolsen@g.o>
29 Date: Sat, 6 Dec 2014 14:54:36 -0800
30 Subject: [PATCH] portage/sync/controller.py: Make a repo.postsync.d directory
31
32 This then runs per-repo postsync hooks only on scripts in the repo.postsync.d directory.
33 This also maintains compatibility with existing scripts in the postsync.d dir or other
34 sub-directories.
35 Both postsync.d directories support subdirectories.
36 Scripts are run in sorted order.
37 ---
38 pym/portage/sync/controller.py | 36 ++++++++++++++++++++++--------------
39 1 file changed, 22 insertions(+), 14 deletions(-)
40
41 diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
42 index 21aa7a7..462b2c0 100644
43 --- a/pym/portage/sync/controller.py
44 +++ b/pym/portage/sync/controller.py
45 @@ -7,6 +7,7 @@ from __future__ import print_function
46 import sys
47 import logging
48 import pwd
49 +from collections import OrderedDict
50
51 import portage
52 from portage import os
53 @@ -21,6 +22,7 @@ warn = create_color_func("WARN")
54 from portage.package.ebuild.doebuild import _check_temp_dir
55 from portage.metadata import action_metadata
56 from portage import _unicode_decode
57 +from portage import util
58
59
60 class TaskHandler(object):
61 @@ -88,19 +90,21 @@ class SyncManager(object):
62
63 self.module_controller = portage.sync.module_controller
64 self.module_names = self.module_controller.module_names
65 - postsync_dir = os.path.join(self.settings["PORTAGE_CONFIGROOT"],
66 - portage.USER_CONFIG_PATH, "postsync.d")
67 - hooks = []
68 - for root, dirs, names in os.walk(postsync_dir, topdown=True):
69 - #print("root:", root, "dirs:", dirs, "names:", names)
70 - for name in names:
71 - filepath = os.path.join(root, name)
72 + self.hooks = {}
73 + for _dir in ["repo.postsync.d", "postsync.d"]:
74 + postsync_dir = os.path.join(self.settings["PORTAGE_CONFIGROOT"],
75 + portage.USER_CONFIG_PATH, _dir)
76 + hooks = OrderedDict()
77 + for filepath in util._recursive_file_list(postsync_dir):
78 + name = filepath.split(postsync_dir)[1].lstrip(os.sep)
79 if os.access(filepath, os.X_OK):
80 - hooks.append((filepath, name))
81 + hooks[filepath] = name
82 else:
83 - writemsg_level(" %s postsync.d hook: '%s' is not executable\n"
84 - % (warn("*"), _unicode_decode(name),), level=logging.WARN, noiselevel=2)
85 - self.hooks = hooks
86 + writemsg_level(" %s %s hook: '%s' is not executable\n"
87 + % (warn("*"), _dir, _unicode_decode(name),),
88 + level=logging.WARN, noiselevel=2)
89 + self.hooks[_dir] = hooks
90 + print(self.hooks)
91
92
93 def get_module_descriptions(self, mod):
94 @@ -159,15 +163,19 @@ class SyncManager(object):
95
96 def perform_post_sync_hook(self, reponame, dosyncuri='', repolocation=''):
97 succeeded = os.EX_OK
98 - for filepath, hook in self.hooks:
99 + if reponame:
100 + _hooks = self.hooks["repo.postsync.d"]
101 + else:
102 + _hooks = self.hooks["postsync.d"]
103 + for filepath in _hooks:
104 writemsg_level("Spawning post_sync hook: %s\n"
105 - % (_unicode_decode(hook)),
106 + % (_unicode_decode(_hooks[filepath])),
107 level=logging.ERROR, noiselevel=4)
108 retval = portage.process.spawn([filepath,
109 reponame, dosyncuri, repolocation], env=self.settings.environ())
110 if retval != os.EX_OK:
111 writemsg_level(" %s Spawn failed for: %s, %s\n" % (bad("*"),
112 - _unicode_decode(hook), filepath),
113 + _unicode_decode(_hooks[filepath]), filepath),
114 level=logging.ERROR, noiselevel=-1)
115 succeeded = retval
116 return succeeded
117 --
118 2.1.2
119
120
121
122
123 --
124 Brian Dolbec <dolsen>

Replies