|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# 2010-2016 Nico Schottelius (nico-cdist at schottelius.org)
|
|
|
|
# 2016 Darko Poljak (darko.poljak at gmail.com)
|
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
def commandline():
|
|
|
|
"""Parse command line"""
|
|
|
|
|
|
|
|
import cdist.argparse
|
|
|
|
import cdist.banner
|
|
|
|
import cdist.config
|
|
|
|
import cdist.install
|
|
|
|
import cdist.shell
|
|
|
|
import cdist.inventory
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
|
|
|
|
parser = cdist.argparse.get_parsers()
|
|
|
|
args = parser['main'].parse_args(sys.argv[1:])
|
|
|
|
|
|
|
|
# Loglevels are handled globally in here
|
|
|
|
cdist.argparse.handle_loglevel(args)
|
|
|
|
|
|
|
|
log.verbose("version %s" % cdist.VERSION)
|
|
|
|
log.trace(args)
|
Remove ugly argumentparser bug
Before:
[21:09] bento:~% cdist
Traceback (most recent call last):
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 232, in <module>
commandline()
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 106, in commandline
args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
After:
[21:11] bento:~% cdist
usage: cdist [-h] [-d] [-v] [-V] {banner,config} ...
cdist 2.1.1-48-gfd72c60
optional arguments:
-h, --help show this help message and exit
-d, --debug Set log level to debug
-v, --verbose Set log level to info, be more verbose
-V, --version Show version
Commands:
{banner,config}
Get cdist at http://www.nico.schottelius.org/software/cdist/
[21:11] bento:~%
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
12 years ago
|
|
|
|
|
|
|
# Work around python 3.3 bug:
|
|
|
|
# http://bugs.python.org/issue16308
|
|
|
|
# http://bugs.python.org/issue9253
|
|
|
|
|
|
|
|
# FIXME: catching AttributeError also hides
|
|
|
|
# real problems.. try a different way
|
|
|
|
|
|
|
|
# FIXME: we always print main help, not
|
|
|
|
# the help of the actual parser being used!
|
Remove ugly argumentparser bug
Before:
[21:09] bento:~% cdist
Traceback (most recent call last):
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 232, in <module>
commandline()
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 106, in commandline
args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
After:
[21:11] bento:~% cdist
usage: cdist [-h] [-d] [-v] [-V] {banner,config} ...
cdist 2.1.1-48-gfd72c60
optional arguments:
-h, --help show this help message and exit
-d, --debug Set log level to debug
-v, --verbose Set log level to info, be more verbose
-V, --version Show version
Commands:
{banner,config}
Get cdist at http://www.nico.schottelius.org/software/cdist/
[21:11] bento:~%
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
12 years ago
|
|
|
try:
|
|
|
|
getattr(args, "func")
|
Remove ugly argumentparser bug
Before:
[21:09] bento:~% cdist
Traceback (most recent call last):
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 232, in <module>
commandline()
File "/home/users/nico/p/cdist/cdist/bin/../scripts/cdist", line 106, in commandline
args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
After:
[21:11] bento:~% cdist
usage: cdist [-h] [-d] [-v] [-V] {banner,config} ...
cdist 2.1.1-48-gfd72c60
optional arguments:
-h, --help show this help message and exit
-d, --debug Set log level to debug
-v, --verbose Set log level to info, be more verbose
-V, --version Show version
Commands:
{banner,config}
Get cdist at http://www.nico.schottelius.org/software/cdist/
[21:11] bento:~%
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
12 years ago
|
|
|
except AttributeError:
|
|
|
|
parser['main'].print_help()
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
cdist.argparse.check_beta(vars(args))
|
|
|
|
args.func(args)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
|
|
|
|
cdistpythonversion = '3.2'
|
|
|
|
if sys.version < cdistpythonversion:
|
|
|
|
print('Python >= {} is required on the source host.'.format(
|
|
|
|
cdistpythonversion), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
exit_code = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import cdist
|
|
|
|
|
|
|
|
log = logging.getLogger("cdist")
|
|
|
|
|
|
|
|
if re.match("__", os.path.basename(sys.argv[0])):
|
|
|
|
import cdist.emulator
|
|
|
|
emulator = cdist.emulator.Emulator(sys.argv)
|
|
|
|
emulator.run()
|
|
|
|
else:
|
|
|
|
commandline()
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
exit_code = 2
|
|
|
|
|
|
|
|
except cdist.Error as e:
|
|
|
|
log.error(e)
|
|
|
|
exit_code = 1
|
|
|
|
|
|
|
|
sys.exit(exit_code)
|