forked from ungleich-public/cdist
Add libexec support and migrate cdist-dump
This commit is contained in:
parent
9859080217
commit
7dddcb794b
7 changed files with 63 additions and 12 deletions
|
@ -6,6 +6,7 @@ import collections
|
||||||
import functools
|
import functools
|
||||||
import cdist.configuration
|
import cdist.configuration
|
||||||
import cdist.preos
|
import cdist.preos
|
||||||
|
import cdist.libexec as libexec
|
||||||
|
|
||||||
|
|
||||||
# set of beta sub-commands
|
# set of beta sub-commands
|
||||||
|
@ -436,6 +437,9 @@ def get_parsers():
|
||||||
' should be POSIX compatible shell.'))
|
' should be POSIX compatible shell.'))
|
||||||
parser['shell'].set_defaults(func=cdist.shell.Shell.commandline)
|
parser['shell'].set_defaults(func=cdist.shell.Shell.commandline)
|
||||||
|
|
||||||
|
# Libexec
|
||||||
|
libexec.create_parsers(parser, parser['sub'])
|
||||||
|
|
||||||
for p in parser:
|
for p in parser:
|
||||||
parser[p].epilog = EPILOG
|
parser[p].epilog = EPILOG
|
||||||
|
|
||||||
|
|
41
cdist/libexec.py
Normal file
41
cdist/libexec.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import cdist.argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
libexec_delimiter = '-'
|
||||||
|
libexec_prefix = 'cdist' + libexec_delimiter
|
||||||
|
libexec_path = os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(cdist.__file__), 'conf', 'libexec'))
|
||||||
|
|
||||||
|
|
||||||
|
def scan():
|
||||||
|
if os.path.isdir(libexec_path):
|
||||||
|
with os.scandir(libexec_path) as it:
|
||||||
|
for entry in it:
|
||||||
|
if (entry.name.startswith(libexec_prefix) and
|
||||||
|
entry.is_file() and
|
||||||
|
os.access(entry.path, os.X_OK)):
|
||||||
|
start = entry.name.find(libexec_delimiter) + 1
|
||||||
|
yield entry.name[start:]
|
||||||
|
|
||||||
|
|
||||||
|
def is_libexec_command(name):
|
||||||
|
for x in scan():
|
||||||
|
if name == x:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def create_parsers(parser, parent_parser):
|
||||||
|
for name in scan():
|
||||||
|
parser[name] = parent_parser.add_parser(name, add_help=False)
|
||||||
|
|
||||||
|
|
||||||
|
def run(name, argv):
|
||||||
|
lib_name = libexec_prefix + name
|
||||||
|
lib_path = os.path.join(libexec_path, lib_name)
|
||||||
|
args = [lib_path, ]
|
||||||
|
args.extend(argv)
|
||||||
|
subprocess.check_call(args)
|
|
@ -48,17 +48,17 @@ Using debug dump helper script
|
||||||
------------------------------
|
------------------------------
|
||||||
Since cdist stores data to local cache that can be used for debugging there
|
Since cdist stores data to local cache that can be used for debugging there
|
||||||
is a helper script that dumps data from local cache,
|
is a helper script that dumps data from local cache,
|
||||||
`cdist-dump <man1/cdist-dump.html>`_.
|
`cdist dump <man1/cdist-dump.html>`_.
|
||||||
|
|
||||||
For more info see:
|
For more info see:
|
||||||
|
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
cdist-dump -h
|
cdist_dump -h
|
||||||
|
|
||||||
Or from cdist git cloned directory:
|
Or from cdist git cloned directory:
|
||||||
|
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
./scripts/cdist-dump -h
|
./bin/cdist dump -h
|
||||||
|
|
||||||
|
|
|
@ -11,17 +11,17 @@ SYNOPSIS
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
cdist-dump [options] [host...]
|
cdist dump [options] [host...]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
cdist-dump is a helper script that dumps data from local cdist cache for
|
cdist dump is a helper script that dumps data from local cdist cache for
|
||||||
specified hosts. If host is not specified then all data from cache directory
|
specified hosts. If host is not specified then all data from cache directory
|
||||||
is dumped. Default cache directory is '~/.cdist/cache'.
|
is dumped. Default cache directory is '~/.cdist/cache'.
|
||||||
|
|
||||||
cdist-dump can be used for debugging existing types, host configuration and
|
cdist dump can be used for debugging existing types, host configuration and
|
||||||
new types.
|
new types.
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,10 +88,10 @@ EXAMPLES
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
# Dump all
|
# Dump all
|
||||||
% cdist-dump -a
|
% cdist dump -a
|
||||||
|
|
||||||
# Dump only code-* output
|
# Dump only code-* output
|
||||||
% cdist-dump -c
|
% cdist dump -c
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
|
|
|
@ -30,14 +30,20 @@ import cdist.config
|
||||||
import cdist.install
|
import cdist.install
|
||||||
import cdist.shell
|
import cdist.shell
|
||||||
import cdist.inventory
|
import cdist.inventory
|
||||||
|
import cdist.libexec as libexec
|
||||||
|
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
# preos subcommand hack
|
# preos subcommand hack
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == 'preos':
|
if sys.argv[1] == 'preos':
|
||||||
return cdist.preos.PreOS.commandline(sys.argv[1:])
|
return cdist.preos.PreOS.commandline(sys.argv[1:])
|
||||||
|
# libexec subcommands hack
|
||||||
|
if libexec.is_libexec_command(sys.argv[1]):
|
||||||
|
return libexec.run(sys.argv[1], sys.argv[2:])
|
||||||
|
|
||||||
parser, cfg = cdist.argparse.parse_and_configure(sys.argv[1:])
|
parser, cfg = cdist.argparse.parse_and_configure(sys.argv[1:])
|
||||||
args = cfg.get_args()
|
args = cfg.get_args()
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -56,7 +56,7 @@ setup(
|
||||||
name="cdist",
|
name="cdist",
|
||||||
packages=["cdist", "cdist.core", "cdist.exec", "cdist.util", ],
|
packages=["cdist", "cdist.core", "cdist.exec", "cdist.util", ],
|
||||||
package_data={'cdist': package_data},
|
package_data={'cdist': package_data},
|
||||||
scripts=["scripts/cdist", "scripts/cdist-dump", "scripts/cdist-new-type"],
|
scripts=["scripts/cdist", "scripts/cdist-new-type"],
|
||||||
version=cdist.version.VERSION,
|
version=cdist.version.VERSION,
|
||||||
description="A Usable Configuration Management System",
|
description="A Usable Configuration Management System",
|
||||||
author="Nico Schottelius",
|
author="Nico Schottelius",
|
||||||
|
|
Loading…
Reference in a new issue