Add libexec support and migrate cdist-dump

This commit is contained in:
Darko Poljak 2019-12-20 23:10:47 +01:00
parent 9859080217
commit 7dddcb794b
7 changed files with 63 additions and 12 deletions

View file

@ -6,6 +6,7 @@ import collections
import functools
import cdist.configuration
import cdist.preos
import cdist.libexec as libexec
# set of beta sub-commands
@ -436,6 +437,9 @@ def get_parsers():
' should be POSIX compatible shell.'))
parser['shell'].set_defaults(func=cdist.shell.Shell.commandline)
# Libexec
libexec.create_parsers(parser, parser['sub'])
for p in parser:
parser[p].epilog = EPILOG

41
cdist/libexec.py Normal file
View 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)

View file

@ -48,17 +48,17 @@ Using debug dump helper script
------------------------------
Since cdist stores data to local cache that can be used for debugging there
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:
.. code-block:: sh
cdist-dump -h
cdist_dump -h
Or from cdist git cloned directory:
.. code-block:: sh
./scripts/cdist-dump -h
./bin/cdist dump -h

View file

@ -11,17 +11,17 @@ SYNOPSIS
::
cdist-dump [options] [host...]
cdist dump [options] [host...]
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
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.
@ -88,10 +88,10 @@ EXAMPLES
.. code-block:: sh
# Dump all
% cdist-dump -a
% cdist dump -a
# Dump only code-* output
% cdist-dump -c
% cdist dump -c
SEE ALSO

View file

@ -30,14 +30,20 @@ import cdist.config
import cdist.install
import cdist.shell
import cdist.inventory
import cdist.libexec as libexec
def commandline():
"""Parse command line"""
# preos subcommand hack
if len(sys.argv) > 1 and sys.argv[1] == 'preos':
return cdist.preos.PreOS.commandline(sys.argv[1:])
if len(sys.argv) > 1:
# preos subcommand hack
if sys.argv[1] == 'preos':
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:])
args = cfg.get_args()

View file

@ -56,7 +56,7 @@ setup(
name="cdist",
packages=["cdist", "cdist.core", "cdist.exec", "cdist.util", ],
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,
description="A Usable Configuration Management System",
author="Nico Schottelius",