diff options
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -23,6 +23,11 @@ from error import NoSuchProjectError | |||
23 | from error import InvalidProjectGroupsError | 23 | from error import InvalidProjectGroupsError |
24 | 24 | ||
25 | 25 | ||
26 | # How many jobs to run in parallel by default? This assumes the jobs are | ||
27 | # largely I/O bound and do not hit the network. | ||
28 | DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8) | ||
29 | |||
30 | |||
26 | class Command(object): | 31 | class Command(object): |
27 | """Base class for any command line action in repo. | 32 | """Base class for any command line action in repo. |
28 | """ | 33 | """ |
@@ -32,6 +37,10 @@ class Command(object): | |||
32 | manifest = None | 37 | manifest = None |
33 | _optparse = None | 38 | _optparse = None |
34 | 39 | ||
40 | # Whether this command supports running in parallel. If greater than 0, | ||
41 | # it is the number of parallel jobs to default to. | ||
42 | PARALLEL_JOBS = None | ||
43 | |||
35 | def WantPager(self, _opt): | 44 | def WantPager(self, _opt): |
36 | return False | 45 | return False |
37 | 46 | ||
@@ -72,6 +81,11 @@ class Command(object): | |||
72 | def _Options(self, p): | 81 | def _Options(self, p): |
73 | """Initialize the option parser. | 82 | """Initialize the option parser. |
74 | """ | 83 | """ |
84 | if self.PARALLEL_JOBS is not None: | ||
85 | p.add_option( | ||
86 | '-j', '--jobs', | ||
87 | type=int, default=self.PARALLEL_JOBS, | ||
88 | help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) | ||
75 | 89 | ||
76 | def _RegisteredEnvironmentOptions(self): | 90 | def _RegisteredEnvironmentOptions(self): |
77 | """Get options that can be set from environment variables. | 91 | """Get options that can be set from environment variables. |