Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Subject: Re: [gentoo-catalyst] Re: [PATCH] Fix autoresume file paths to only be configured once.
Date: Wed, 05 Mar 2014 05:07:19
Message-Id: 20140304210703.1fae17d0.dolsen@gentoo.org
In Reply to: [gentoo-catalyst] Re: [PATCH] Fix autoresume file paths to only be configured once. by "W. Trevor King"
1 On Tue, 4 Mar 2014 20:35:28 -0800
2
3 Well for starters this patch was not part of the 3.0 branch. When
4 working with patches in the pending branch I was running into some
5 troubles fixed in 3.0 that of course were going to be awhile before
6 coming to pending. So when I started fixing a couple, I thought what
7 the hell, and did them all. The unfortunate part is that a bunch of
8 these changes will be replaced by other code later in the patch series.
9
10
11
12 "W. Trevor King" <wking@×××××××.us> wrote:
13
14 > On Sun, Mar 02, 2014 at 03:05:35PM -0800, Brian Dolbec wrote:
15 > > Use: pjoin as a shorter alias to os.path.join()
16 >
17 > I think the saved characters are not worth the mental overhead of an
18 > additional layer of indirection.
19 >
20 > > - if "AUTORESUME" in self.settings\
21 > > - and os.path.exists(self.settings["autoresume_path"]+\
22 > > - "setup_target_path"):
23 > > + setup_target_path_resume = pjoin(self.settings["autoresume_path"],
24 > > + "setup_target_path")
25 > > + if "AUTORESUME" in self.settings and \
26 > > + os.path.exists(setup_target_path_resume):
27 >
28 > How about:
29 >
30 > setup_target_path_resume = os.path.join(
31 > self.settings["autoresume_path"],
32 > "setup_target_path")
33 > if ("AUTORESUME" in self.settings and
34 > os.path.exists(setup_target_path_resume)):
35 >
36 > I don't think that's particularly unweildy, it avoids the need for
37 > line-continuation characters [1], and doesn't leave new readers
38 > wondering “what's pjoin?”.
39
40 pjoin is something from snakeoil too, depending on the python version
41 being run, it does some optimization changes if I remember correctly.
42 But yes, it is a minor change.
43
44
45 >
46 > That's all minor stuff though. I think the creation of a
47 > setup_target_path_resume variable is good.
48 >
49 > > - self.settings["autoresume_path"]=normpath(self.settings["storedir"]+\
50 > > - "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\
51 > > - self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
52 > > - self.settings["version_stamp"]+"/")
53 > > + self.settings["autoresume_path"] = normpath(pjoin(
54 > > + self.settings["storedir"], "tmp", self.settings["rel_type"],
55 > > + ".autoresume-%s-%s-%s"
56 > > + %(self.settings["target"], self.settings["subarch"],
57 > > + self.settings["version_stamp"])
58 > > + ))
59 >
60 > +1. My personal preference is for:
61 >
62 > '.autoresume-{}-{}-{}'.format(
63 > self.settings['target'],
64 > self.settings['subarch'],
65 > self.settings['version_stamp'])))
66 >
67 > but whatever ;).
68 >
69
70 I never think of the new .format method. My brain is used to %s, so is
71 stuck there.
72
73
74 > > if os.path.isdir(self.settings["source_path"]) \
75 > > - and os.path.exists(self.settings["autoresume_path"]+"unpack"):
76 > > + and os.path.exists(unpack_resume):
77 >
78 > Another place where I'd follow PEP8 [1,2] and use:
79 >
80 > if (os.path.isdir(self.settings["source_path"]) and
81 > and os.path.exists(unpack_resume)):
82 >
83 > > elif os.path.isdir(self.settings["source_path"]) \
84 > > - and not os.path.exists(self.settings["autoresume_path"]+\
85 > > - "unpack"):
86 > > + and not os.path.exists(unpack_resume):
87 >
88 > I'd use:
89 >
90 > elif (os.path.isdir(self.settings["source_path"]) and
91 > not os.path.exists(unpack_resume)):
92 >
93
94 To be honest, I never thought about that during these changes, I was
95 just doing what was needed to fix some old issues I had fixed
96 differently in 3.0, but were going to be awhile.
97
98 Easy to fix...
99
100
101 > > @@ -876,9 +881,10 @@ class generic_stage_target(generic_target):
102 > > self.snapshot_lock_object.unlock()
103 > >
104 > > def config_profile_link(self):
105 > > + config_protect_link_resume = pjoin(self.settings["autoresume_path"],
106 > > + "config_profile_link")
107 > > if "AUTORESUME" in self.settings \
108 > > - and os.path.exists(self.settings["autoresume_path"]+\
109 > > - "config_profile_link"):
110 > > + and os.path.exists():
111 >
112 > Oops, you dropped the argument from exists().
113
114 oops, missed that :/ hmm, why did I not discover that in testing...
115 I must not have run the right combination of things to discover it.
116
117 > How about:
118 >
119 > def config_profile_link(self):
120 > config_profile_link_resume = pjoin(
121 > self.settings['autoresume_path'], 'config_profile_link')
122 > if ('AUTORESUME' in self.settings and
123 > os.path.exists(config_profile_link_resume)):
124 >
125 > I also switched 'protect' to 'profile' to match the method name, but I
126 > don't actually know what this file is marking ;).
127 >
128 > > - touch(self.settings["autoresume_path"]+"config_profile_link")
129 > > + touch(config_protect_link_resume)
130 >
131 > Here's another place I'd use 'profile' over 'protect'.
132
133 Yeah, My brain must have been stuck in "config_protect" which is a
134 common portage variable and control.
135
136 >
137 > There are a whole lot of these things with very boilerplate code. Can
138 > we abstract this out to reduce that repetition? I'm not sure what
139 > that would look like at the moment though, and a larger overhaul
140 > shouldn't stand in the way of this patch.
141 >
142 > Cheers,
143 > Trevor
144
145 Like I said at the top of the reply.
146 The autoresume stuff is later replaced with a self contained class.
147 I was never sure if I should submit it, but it did fix a couple small
148 issues. I can go either way with this one.
149
150
151 >
152 > [1]: In PEP 8 [3]:
153 >
154 > The preferred way of wrapping long lines is by using Python's
155 > implied line continuation inside parentheses, brackets and
156 > braces. Long lines can be broken over multiple lines by
157 > wrapping expressions in parentheses. These should be used in
158 > preference to using a backslash for line continuation.
159 >
160 > [2]: In PEP 8 [3]:
161 >
162 > The preferred place to break around a binary operator is after
163 > the operator, not before it.
164 >
165 > [3]: http://legacy.python.org/dev/peps/pep-0008/#maximum-line-length
166 >
167
168
169
170 --
171 Brian Dolbec <dolsen>

Replies

Subject Author
[gentoo-catalyst] Re: [PATCH] Fix autoresume file paths to only be configured once. "W. Trevor King" <wking@×××××××.us>