Browse files

Change parallel to concurrency and fix optparsing

The way I parse the various possibilities is really ugly and I hate it
but it works and I haven't been able to figure out a better way.
  • Loading branch information...
1 parent 0b088f4 commit 294dad603eb3816079142025090ebb4db3b80240 @philk philk committed Jan 24, 2013
Showing with 26 additions and 13 deletions.
  1. +20 −7 fix
  2. +1 −2 littlechef/__init__.py
  3. +5 −4 littlechef/runner.py
View
27 fix
@@ -67,11 +67,12 @@ parser.add_option(
help="Using a certain chef environment"
)
parser.add_option(
- "--parallel", dest="parallel", default=False,
- help="Executes commands in parallel"
+ "--concurrency", dest="concurrency", default=False,
+ help="Executes commands concurrently"
)
(options, args) = parser.parse_args()
+
## Process args list and call fabric's main() ##
if not sys.argv:
print(NO_ORDER)
@@ -95,13 +96,25 @@ else:
if options.whyrun:
littlechef.whyrun = True
sys.argv.remove('--why-run')
- if options.parallel:
- littlechef.parallel = True
+ if options.concurrency:
+ # --concurrency 5
+ # --concurrency=5
try:
- sys.argv.remove('--parallel={0}'.format(options.parallel))
- littlechef.pool_size = options.parallel
+ c = int(options.concurrency)
+ littlechef.concurrency = c
+ try:
+ sys.argv.remove('--concurrency={0}'.format(options.concurrency))
+ except ValueError:
+ sys.argv.remove('--concurrency'.format(options.concurrency))
+ sys.argv.remove(options.concurrency)
except ValueError:
- sys.argv.remove('--parallel')
+ # --concurrency node:nodename
+ try:
+ sys.argv.remove('--concurrency')
+ littlechef.concurrency = 0
+ except ValueError:
+ pass
+
if options.verbose:
littlechef.verbose = True
sys.argv.remove('--verbose')
View
3 littlechef/__init__.py
@@ -26,8 +26,7 @@
enable_logs = True
LOGFILE = '/var/log/chef/solo.log'
whyrun = False
-parallel = False
-pool_size = False
+concurrency = False
node_work_path = '/tmp/chef-solo'
cookbook_paths = ['site-cookbooks', 'cookbooks']
View
9 littlechef/runner.py
@@ -33,10 +33,14 @@
import fabric
fabric.state.output['running'] = False
env.loglevel = "info"
-if littlechef.parallel:
+
+if isinstance(littlechef.concurrency, int):
env.output_prefix = True
+ env.parallel = True
+ env.pool_size = littlechef.concurrency
else:
env.output_prefix = False
+
__testing__ = False
@@ -436,9 +440,6 @@ def _readconfig():
env.loglevel = littlechef.loglevel
env.verbose = littlechef.verbose
env.node_work_path = littlechef.node_work_path
-env.parallel = littlechef.parallel
-if littlechef.pool_size:
- env.pool_size = int(littlechef.pool_size)
if littlechef.__cooking__:
# Called from command line

0 comments on commit 294dad6

Please sign in to comment.