1 |
> |
2 |
> Please move this sys.exit to the main(). So this should just return |
3 |
> a list of the rcodes to match the tasks it was passed. |
4 |
> TaskHandler can be used easily via api, so we don't want it to exit out |
5 |
> of someone else's code. That will also keep main() as the primary cli |
6 |
> interface. There process the list of rcodes and exit appropriately. |
7 |
|
8 |
|
9 |
This was an oversight on my part, I will make the necessary changes. |
10 |
|
11 |
Alexandru, I tend to not prefer using numbers to indicate success/fail. |
12 |
> They can be confusing at times. In this case 1 means fail, 0 means |
13 |
> success. Which is the opposite of True/False. It would be different |
14 |
> if there were multiple return code values. Then they would be |
15 |
> meaningful. |
16 |
|
17 |
|
18 |
Sure, I understand your point, we are only interested in success of |
19 |
failure of the modules, so having True or False as return values makes |
20 |
sense. I got the idea to use 1 as a failure return code because that's how |
21 |
the portage sync modules work (for example: |
22 |
https://gitweb.gentoo.org/proj/portage.git/tree/pym/portage/sync/modules/git/git.py#n46). |
23 |
That's also why I chose to return (returncode, message) and not (message, |
24 |
returncode). |
25 |
|
26 |
|
27 |
|
28 |
On Tue, Jan 17, 2017 at 8:23 PM, Brian Dolbec <dolsen@g.o> wrote: |
29 |
|
30 |
> On Tue, 17 Jan 2017 19:48:16 +0200 |
31 |
> Alexandru Elisei <alexandru.elisei@×××××.com> wrote: |
32 |
> |
33 |
> > Currently module functions return a message to emaint after |
34 |
> > invocation. Emaint prints this message then exits normally (with a |
35 |
> > success return code) even if the module encountered an error. This |
36 |
> > patch aims to change this by having each module public function |
37 |
> > return a tuple of (returncode, message). Emaint will inspect the |
38 |
> > return code and will exit unsuccessfully if necessary. |
39 |
> > --- |
40 |
> > pym/portage/emaint/main.py | 11 +++++++++-- |
41 |
> > pym/portage/emaint/modules/binhost/binhost.py | 6 ++++-- |
42 |
> > pym/portage/emaint/modules/config/config.py | 8 ++++++-- |
43 |
> > pym/portage/emaint/modules/logs/logs.py | 9 +++++---- |
44 |
> > pym/portage/emaint/modules/merges/merges.py | 18 +++++++++++------- |
45 |
> > pym/portage/emaint/modules/move/move.py | 9 +++++++-- |
46 |
> > pym/portage/emaint/modules/resume/resume.py | 4 +++- |
47 |
> > pym/portage/emaint/modules/sync/sync.py | 19 |
48 |
> > +++++++++++++------ pym/portage/emaint/modules/world/world.py | |
49 |
> > 8 ++++++-- 9 files changed, 64 insertions(+), 28 deletions(-) |
50 |
> > |
51 |
> > diff --git a/pym/portage/emaint/main.py b/pym/portage/emaint/main.py |
52 |
> > index 65e3545..ef4383a 100644 |
53 |
> > --- a/pym/portage/emaint/main.py |
54 |
> > +++ b/pym/portage/emaint/main.py |
55 |
> > @@ -115,6 +115,7 @@ class TaskHandler(object): |
56 |
> > """Runs the module tasks""" |
57 |
> > if tasks is None or func is None: |
58 |
> > return |
59 |
> > + returncode = os.EX_OK |
60 |
> > for task in tasks: |
61 |
> > inst = task() |
62 |
> > show_progress = self.show_progress_bar and |
63 |
> > self.isatty @@ -135,14 +136,20 @@ class TaskHandler(object): |
64 |
> > # them for other tasks if there is |
65 |
> > more to do. 'options': options.copy() |
66 |
> > } |
67 |
> > - result = getattr(inst, func)(**kwargs) |
68 |
> > + rcode, msgs = getattr(inst, func)(**kwargs) |
69 |
> > if show_progress: |
70 |
> > # make sure the final progress is |
71 |
> > displayed self.progress_bar.display() |
72 |
> > print() |
73 |
> > self.progress_bar.stop() |
74 |
> > if self.callback: |
75 |
> > - self.callback(result) |
76 |
> > + self.callback(msgs) |
77 |
> > + # Keep the last error code when using the |
78 |
> > 'all' command. |
79 |
> > + if rcode != os.EX_OK: |
80 |
> > + returncode = rcode |
81 |
> > + |
82 |
> > + if returncode != os.EX_OK: |
83 |
> > + sys.exit(returncode) |
84 |
> > |
85 |
> |
86 |
> |
87 |
> Please move this sys.exit to the main(). So this should just return |
88 |
> a list of the rcodes to match the tasks it was passed. |
89 |
> TaskHandler can be used easily via api, so we don't want it to exit out |
90 |
> of someone else's code. That will also keep main() as the primary cli |
91 |
> interface. There process the list of rcodes and exit appropriately. |
92 |
> |
93 |
> |
94 |
> |
95 |
> > |
96 |
> > def print_results(results): |
97 |
> > diff --git a/pym/portage/emaint/modules/binhost/binhost.py |
98 |
> > b/pym/portage/emaint/modules/binhost/binhost.py |
99 |
> > index cf1213e..8cf3da6 100644 |
100 |
> > --- a/pym/portage/emaint/modules/binhost/binhost.py |
101 |
> > +++ b/pym/portage/emaint/modules/binhost/binhost.py |
102 |
> > @@ -86,7 +86,9 @@ class BinhostHandler(object): |
103 |
> > stale = set(metadata).difference(cpv_all) |
104 |
> > for cpv in stale: |
105 |
> > errors.append("'%s' is not in the |
106 |
> > repository" % cpv) |
107 |
> > - return errors |
108 |
> > + if errors: |
109 |
> > + return (1, errors) |
110 |
> > + return (os.EX_OK, None) |
111 |
> > |
112 |
> |
113 |
> Alexandru, I tend to not prefer using numbers to indicate success/fail. |
114 |
> They can be confusing at times. In this case 1 means fail, 0 means |
115 |
> success. Which is the opposite of True/False. It would be different |
116 |
> if there were multiple return code values. Then they would be |
117 |
> meaningful. I want to keep these modules pythonic in the sense that |
118 |
> they return standard True/False for API use. In this case returning |
119 |
> True/False would also make it easy to process the list of rcodes |
120 |
> returned to main() |
121 |
> |
122 |
> sys.exit(False in rcodes) |
123 |
> |
124 |
> which will reverse the True/False to 0/1 automatically for us and make |
125 |
> it super simple to process a variable length list success/fail results. |
126 |
> |
127 |
> -- |
128 |
> Brian Dolbec <dolsen> |
129 |
> |
130 |
> |
131 |
> |