Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r11261 - in main/trunk: man pym/_emerge
Date: Tue, 29 Jul 2008 12:05:48
Message-Id: E1KNnxZ-0003ph-7j@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-07-29 12:05:43 +0000 (Tue, 29 Jul 2008)
3 New Revision: 11261
4
5 Modified:
6 main/trunk/man/emerge.1
7 main/trunk/pym/_emerge/__init__.py
8 main/trunk/pym/_emerge/help.py
9 Log:
10 Add support for the --jobs option to be specified without an
11 argument, and also support -j as a short option. Since optparse
12 doesn't natively support options with non-required args, create an
13 insert_optional_args() function that inserts the required argument
14 into the args so that optparse is happy. The function inserts the
15 string True as a substitute for the argument that is required. This
16 string is later converted to the True constant when stored in
17 the emerge opts dict (similar to how normal boolean options are
18 stored). The PollScheduler and SequentialTaskQueue classes recognize
19 the meaning of the True constant to mean unlimited concurrent jobs.
20
21
22 Modified: main/trunk/man/emerge.1
23 ===================================================================
24 --- main/trunk/man/emerge.1 2008-07-29 10:29:59 UTC (rev 11260)
25 +++ main/trunk/man/emerge.1 2008-07-29 12:05:43 UTC (rev 11261)
26 @@ -323,9 +323,10 @@
27 .BR "\-\-ignore-default-opts"
28 Causes \fIEMERGE_DEFAULT_OPTS\fR (see \fBmake.conf\fR(5)) to be ignored.
29 .TP
30 -.BR \-\-jobs=JOBS
31 -Specifies the number of packages to build simultaneously. Also see
32 -the related \fB\-\-load\-average\fR option.
33 +.BR "-j [JOBS], \-\-jobs[=JOBS]"
34 +Specifies the number of packages to build simultaneously. If this option is
35 +given without an argument, emerge will not limit the number of jobs that can
36 +run simultaneously. Also see the related \fB\-\-load\-average\fR option.
37 .TP
38 .BR "\-\-keep\-going"
39 Continue as much as possible after an error. When an error occurs,
40
41 Modified: main/trunk/pym/_emerge/__init__.py
42 ===================================================================
43 --- main/trunk/pym/_emerge/__init__.py 2008-07-29 10:29:59 UTC (rev 11260)
44 +++ main/trunk/pym/_emerge/__init__.py 2008-07-29 12:05:43 UTC (rev 11261)
45 @@ -8153,7 +8153,8 @@
46 if task.poll() is not None:
47 state_changed = True
48
49 - while task_queue and (len(running_tasks) < max_jobs):
50 + while task_queue and \
51 + (max_jobs is True or len(running_tasks) < max_jobs):
52 task = task_queue.popleft()
53 cancelled = getattr(task, "cancelled", None)
54 if not cancelled:
55 @@ -8271,10 +8272,12 @@
56 max_jobs = self._max_jobs
57 max_load = self._max_load
58
59 - if self._running_job_count() >= self._max_jobs:
60 + if self._max_jobs is not True and \
61 + self._running_job_count() >= self._max_jobs:
62 return False
63
64 - if max_load is not None and max_jobs > 1 and \
65 + if max_load is not None and \
66 + (max_jobs is True or max_jobs > 1) and \
67 self._running_job_count() > 1:
68 try:
69 avg1, avg5, avg15 = os.getloadavg()
70 @@ -8911,7 +8914,8 @@
71 @rtype: bool
72 @returns: True if background mode is enabled, False otherwise.
73 """
74 - background = (self._max_jobs > 1 or "--quiet" in self.myopts) and \
75 + background = (self._max_jobs is True or \
76 + self._max_jobs > 1 or "--quiet" in self.myopts) and \
77 not bool(self._opts_no_background.intersection(self.myopts))
78
79 self._status_display.quiet = \
80 @@ -12723,6 +12727,61 @@
81 sys.stderr.write("!!! '%s' or '%s'\n\n" % (action1, action2))
82 sys.exit(1)
83
84 +def insert_optional_args(args):
85 + """
86 + Parse optional arguments and insert a value if one has
87 + not been provided. This is done before feeding the args
88 + to the optparse parser since that parser does not support
89 + this feature natively.
90 + """
91 +
92 + new_args = []
93 + jobs_opts = ("-j", "--jobs")
94 + for i, arg in enumerate(args):
95 +
96 + short_job_opt = bool("j" in arg and arg[:1] == "-" and arg[:2] != "--")
97 + if not (short_job_opt or arg in jobs_opts):
98 + new_args.append(arg)
99 + continue
100 +
101 + # Insert an empty placeholder in order to
102 + # satisfy the requirements of optparse.
103 +
104 + new_args.append("--jobs")
105 + job_count = None
106 + saved_opts = None
107 + if short_job_opt and len(arg) > 2:
108 + if arg[:2] == "-j":
109 + try:
110 + job_count = int(arg[2:])
111 + except ValueError:
112 + saved_opts = arg[2:]
113 + else:
114 + job_count = "True"
115 + saved_opts = arg[1:].replace("j", "")
116 +
117 + if job_count is None and \
118 + i < len(args) - 1:
119 + try:
120 + job_count = int(args[i+1])
121 + except ValueError:
122 + pass
123 + else:
124 + # The next loop iteration will append
125 + # the validated job count to new_args.
126 + continue
127 +
128 + if job_count is None:
129 + # unlimited number of jobs
130 + new_args.append("True")
131 + else:
132 + new_args.append(str(job_count))
133 +
134 + if saved_opts is not None:
135 + new_args.append("-" + saved_opts)
136 +
137 + return new_args
138 +
139 def parse_opts(tmpcmdline, silent=False):
140 myaction=None
141 myopts = {}
142 @@ -12793,15 +12852,22 @@
143 parser.add_option(myopt,
144 dest=myopt.lstrip("--").replace("-", "_"), **kwargs)
145
146 + tmpcmdline = insert_optional_args(tmpcmdline)
147 +
148 myoptions, myargs = parser.parse_args(args=tmpcmdline)
149
150 if myoptions.jobs:
151 - try:
152 - jobs = int(myoptions.jobs)
153 - except ValueError:
154 - jobs = 0
155 + jobs = None
156 + if myoptions.jobs == "True":
157 + jobs = True
158 + else:
159 + try:
160 + jobs = int(myoptions.jobs)
161 + except ValueError:
162 + jobs = -1
163
164 - if jobs < 1:
165 + if jobs is not True and \
166 + jobs < 1:
167 jobs = None
168 if not silent:
169 writemsg("!!! Invalid --jobs parameter: '%s'\n" % \
170
171 Modified: main/trunk/pym/_emerge/help.py
172 ===================================================================
173 --- main/trunk/pym/_emerge/help.py 2008-07-29 10:29:59 UTC (rev 11260)
174 +++ main/trunk/pym/_emerge/help.py 2008-07-29 12:05:43 UTC (rev 11261)
175 @@ -14,7 +14,7 @@
176 print " "+turquoise("emerge")+" < "+turquoise("--sync")+" | "+turquoise("--metadata")+" | "+turquoise("--info")+" >"
177 print " "+turquoise("emerge")+" "+turquoise("--resume")+" [ "+green("--pretend")+" | "+green("--ask")+" | "+green("--skipfirst")+" ]"
178 print " "+turquoise("emerge")+" "+turquoise("--help")+" [ "+green("system")+" | "+green("world")+" | "+green("--sync")+" ] "
179 - print bold("Options:")+" "+green("-")+"["+green("abBcCdDefgGhkKlnNoOpqPsStuvV")+"]"
180 + print bold("Options:")+" "+green("-")+"["+green("abBcCdDefgGhjkKlnNoOpqPsStuvV")+"]"
181 print " [ " + green("--color")+" < " + turquoise("y") + " | "+ turquoise("n")+" > ] [ "+green("--columns")+" ]"
182 print " [ "+green("--complete-graph")+" ] [ "+green("--deep")+" ]"
183 print " [ "+green("--jobs") + " " + turquoise("JOBS")+" ] [ "+green("--keep-going")+" ] [ " + green("--load-average")+" " + turquoise("LOAD") + " ]"
184 @@ -305,9 +305,12 @@
185 print " downloaded from the remote server without consulting packages"
186 print " existing in the packages directory."
187 print
188 - print " " + green("--jobs") + " " + turquoise("JOBS")
189 + print " " + green("--jobs") + " " + turquoise("[JOBS]") + " ("+green("-j")+" short option)"
190 desc = "Specifies the number of packages " + \
191 - "to build simultaneously. Also see " + \
192 + "to build simultaneously. If this option is " + \
193 + "given without an argument, emerge will not " + \
194 + "limit the number of jobs that " + \
195 + "can run simultaneously. Also see " + \
196 "the related --load-average option."
197 for line in wrap(desc, desc_width):
198 print desc_indent + line