Commit 3a5c6f95 authored by Godefroid Chapelle's avatar Godefroid Chapelle

avoid explicit list of commands

as suggested by @leorochael
parent 0d56ba28
......@@ -50,6 +50,19 @@ if PY3:
else:
text_type = unicode
def command(method):
method.buildout_command = True
return method
def commands(cls):
for name, method in cls.__dict__.items():
if hasattr(method, "buildout_command"):
cls.COMMANDS.add(name)
return cls
def _print_options(sep=' ', end='\n', file=None):
return sep, end, file
......@@ -289,8 +302,11 @@ _buildout_default_options = _annotate_section({
}, 'DEFAULT_VALUE')
@commands
class Buildout(DictMixin):
COMMANDS = set()
def __init__(self, config_file, cloptions,
user_defaults=True,
command=None, args=()):
......@@ -555,6 +571,7 @@ class Buildout(DictMixin):
return name
return os.path.join(self._buildout_dir, name)
@command
def bootstrap(self, args):
__doing__ = 'Bootstrapping.'
......@@ -628,11 +645,13 @@ class Buildout(DictMixin):
f.write('[buildout]\nparts =\n')
f.close()
@command
def init(self, args):
self.bootstrap(())
if args:
self.install(())
@command
def install(self, install_args):
__doing__ = 'Installing.'
......@@ -1210,6 +1229,7 @@ class Buildout(DictMixin):
print_("Picked versions have been written to " +
self.update_versions_file)
@command
def setup(self, args):
if not args:
raise zc.buildout.UserError(
......@@ -1236,8 +1256,11 @@ class Buildout(DictMixin):
os.close(fd)
os.remove(tsetup)
runsetup = setup # backward compat.
@command
def runsetup(self, args):
self.setup(args)
@command
def query(self, args=None):
if args is None or len(args) != 1:
_error('The query command requires a single argument.')
......@@ -1259,6 +1282,7 @@ class Buildout(DictMixin):
else:
_error('Section not found:', section)
@command
def annotate(self, args=None):
verbose = self['buildout'].get('verbosity', 0) != 0
section = None
......@@ -2138,10 +2162,7 @@ def main(args=None):
if args:
command = args.pop(0)
if command not in (
'install', 'bootstrap', 'runsetup', 'setup', 'init',
'annotate', 'query',
):
if command not in Buildout.COMMANDS:
_error('invalid command:', command)
else:
command = 'install'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment