diff --git a/Makefile b/Makefile index fb892bcd..aaee5e61 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,13 @@ TAG = lorax-$(VERSION)-$(RELEASE) default: all +src/composer/version.py: lorax.spec + echo "num = '$(VERSION)-$(RELEASE)'" > src/composer/version.py + src/pylorax/version.py: lorax.spec echo "num = '$(VERSION)-$(RELEASE)'" > src/pylorax/version.py -all: src/pylorax/version.py +all: src/pylorax/version.py src/composer/version.py $(PYTHON) setup.py build install: all @@ -37,6 +40,7 @@ test: clean: -rm -rf build src/pylorax/version.py + -rm -rf build src/composer/version.py tag: git tag -f $(TAG) diff --git a/src/bin/composer-cli b/src/bin/composer-cli index 07c314e8..dc1f65ec 100755 --- a/src/bin/composer-cli +++ b/src/bin/composer-cli @@ -22,74 +22,13 @@ log = logging.getLogger("composer-cli") import os import sys -import argparse from composer import vernum from composer.cli import main +from composer.cli.cmdline import composer_cli_parser VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) -# Documentation for the commands -epilog = """ -compose start Start a compose using the selected blueprint and output type. - types List the supported output types. - status List the status of all running and finished composes. - log [kB] Show the last 1kB of the compose log. - cancel Cancel a running compose and delete any intermediate results. - delete Delete the listed compose results. - info Show detailed information on the compose. - metadata Download the metadata use to create the compose to -metadata.tar - logs Download the compose logs to -logs.tar - results Download all of the compose results; metadata, logs, and image to .tar - image Download the output image from the compose. Filename depends on the type. -blueprints list List the names of the available blueprints. - show Display the blueprint in TOML format. - changes Display the changes for each blueprint. - diff Display the differences between 2 versions of a blueprint. - Commit hash or NEWEST - Commit hash, NEWEST, or WORKSPACE - save Save the blueprint to a file, .toml - delete Delete a blueprint from the server - depsolve Display the packages needed to install the blueprint. - push Push a blueprint TOML file to the server. - freeze Display the frozen blueprint's modules and packages. - freeze show Display the frozen blueprint in TOML format. - freeze save Save the frozen blueprint to a file, .frozen.toml. - tag Tag the most recent blueprint commit as a release. - undo Undo changes to a blueprint by reverting to the selected commit. - workspace Push the blueprint TOML to the temporary workspace storage. -modules list List the available modules. -projects list List the available projects. -projects info Show details about the listed projects. -""" - -def get_parser(): - """ Return the ArgumentParser for composer-cli""" - - parser = argparse.ArgumentParser(description="Lorax Composer commandline tool", - epilog=epilog, - formatter_class=argparse.RawDescriptionHelpFormatter, - fromfile_prefix_chars="@") - - parser.add_argument("-j", "--json", action="store_true", default=False, - help="Output the raw JSON response instead of the normal output.") - parser.add_argument("-s", "--socket", default="/run/weldr/api.socket", metavar="SOCKET", - help="Path to the socket file to listen on") - parser.add_argument("--log", dest="logfile", default="./composer-cli.log", metavar="LOG", - help="Path to logfile (./composer-cli.log)") - parser.add_argument("-a", "--api", dest="api_version", default="0", metavar="APIVER", - help="API Version to use") - parser.add_argument("--test", dest="testmode", default=0, type=int, metavar="TESTMODE", - help="Pass test mode to compose. 1=Mock compose with fail. 2=Mock compose with finished.") - parser.add_argument("-V", action="store_true", dest="showver", - help="show program's version number and exit") - - # Commands are implemented by parsing the remaining arguments outside of argparse - parser.add_argument('args', nargs=argparse.REMAINDER) - - - return parser - def setup_logging(logfile): # Setup logging to console and to logfile log.setLevel(logging.DEBUG) @@ -108,7 +47,7 @@ def setup_logging(logfile): if __name__ == '__main__': # parse the arguments - opts = get_parser().parse_args() + opts = composer_cli_parser().parse_args() if opts.showver: print(VERSION) diff --git a/src/composer/cli/cmdline.py b/src/composer/cli/cmdline.py new file mode 100644 index 00000000..a60da2f9 --- /dev/null +++ b/src/composer/cli/cmdline.py @@ -0,0 +1,83 @@ +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . +# +import os +import sys +import argparse + +from composer import vernum + +VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) + +# Documentation for the commands +epilog = """ +compose start Start a compose using the selected blueprint and output type. + types List the supported output types. + status List the status of all running and finished composes. + log [kB] Show the last 1kB of the compose log. + cancel Cancel a running compose and delete any intermediate results. + delete Delete the listed compose results. + info Show detailed information on the compose. + metadata Download the metadata use to create the compose to -metadata.tar + logs Download the compose logs to -logs.tar + results Download all of the compose results; metadata, logs, and image to .tar + image Download the output image from the compose. Filename depends on the type. +blueprints list List the names of the available blueprints. + show Display the blueprint in TOML format. + changes Display the changes for each blueprint. + diff Display the differences between 2 versions of a blueprint. + Commit hash or NEWEST + Commit hash, NEWEST, or WORKSPACE + save Save the blueprint to a file, .toml + delete Delete a blueprint from the server + depsolve Display the packages needed to install the blueprint. + push Push a blueprint TOML file to the server. + freeze Display the frozen blueprint's modules and packages. + freeze show Display the frozen blueprint in TOML format. + freeze save Save the frozen blueprint to a file, .frozen.toml. + tag Tag the most recent blueprint commit as a release. + undo Undo changes to a blueprint by reverting to the selected commit. + workspace Push the blueprint TOML to the temporary workspace storage. +modules list List the available modules. +projects list List the available projects. +projects info Show details about the listed projects. +""" + +def composer_cli_parser(): + """ Return the ArgumentParser for composer-cli""" + + parser = argparse.ArgumentParser(description="Lorax Composer commandline tool", + epilog=epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + fromfile_prefix_chars="@") + + parser.add_argument("-j", "--json", action="store_true", default=False, + help="Output the raw JSON response instead of the normal output.") + parser.add_argument("-s", "--socket", default="/run/weldr/api.socket", metavar="SOCKET", + help="Path to the socket file to listen on") + parser.add_argument("--log", dest="logfile", default="./composer-cli.log", metavar="LOG", + help="Path to logfile (./composer-cli.log)") + parser.add_argument("-a", "--api", dest="api_version", default="0", metavar="APIVER", + help="API Version to use") + parser.add_argument("--test", dest="testmode", default=0, type=int, metavar="TESTMODE", + help="Pass test mode to compose. 1=Mock compose with fail. 2=Mock compose with finished.") + parser.add_argument("-V", action="store_true", dest="showver", + help="show program's version number and exit") + + # Commands are implemented by parsing the remaining arguments outside of argparse + parser.add_argument('args', nargs=argparse.REMAINDER) + + return parser diff --git a/src/pylorax/api/__init__.py b/src/pylorax/api/__init__.py index 5ee1ec8a..4ca8ccb8 100644 --- a/src/pylorax/api/__init__.py +++ b/src/pylorax/api/__init__.py @@ -18,4 +18,3 @@ from pylorax.api.crossdomain import crossdomain __all__ = ["crossdomain"] - diff --git a/src/pylorax/api/cmdline.py b/src/pylorax/api/cmdline.py new file mode 100644 index 00000000..5737136e --- /dev/null +++ b/src/pylorax/api/cmdline.py @@ -0,0 +1,58 @@ +# +# cmdline.py +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . +# +import os +import sys +import argparse + +from pylorax import vernum + +version = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) + +def lorax_composer_parser(): + """ Return the ArgumentParser for lorax-composer""" + + parser = argparse.ArgumentParser(description="Lorax Composer API Server", + fromfile_prefix_chars="@") + + parser.add_argument("--socket", default="/run/weldr/api.socket", metavar="SOCKET", + help="Path to the socket file to listen on") + parser.add_argument("--user", default="weldr", metavar="USER", + help="User to use for reduced permissions") + parser.add_argument("--group", default="weldr", metavar="GROUP", + help="Group to set ownership of the socket to") + parser.add_argument("--log", dest="logfile", default="/var/log/lorax-composer/composer.log", metavar="LOG", + help="Path to logfile (/var/log/lorax-composer/composer.log)") + parser.add_argument("--mockfiles", default="/var/tmp/bdcs-mockfiles/", metavar="MOCKFILES", + help="Path to JSON files used for /api/mock/ paths (/var/tmp/bdcs-mockfiles/)") + parser.add_argument("--sharedir", type=os.path.abspath, metavar="SHAREDIR", + help="Directory containing all the templates. Overrides config file sharedir") + parser.add_argument("-V", action="store_true", dest="showver", + help="show program's version number and exit") + parser.add_argument("-c", "--config", default="/etc/lorax/composer.conf", metavar="CONFIG", + help="Path to lorax-composer configuration file.") + parser.add_argument("--releasever", default=None, metavar="STRING", + help="Release version to use for $releasever in dnf repository urls") + parser.add_argument("--tmp", default="/var/tmp", + help="Top level temporary directory") + parser.add_argument("--proxy", default=None, metavar="PROXY", + help="Set proxy for DNF, overrides configuration file setting.") + parser.add_argument("BLUEPRINTS", metavar="BLUEPRINTS", + help="Path to the blueprints") + + return parser diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index 014ecfb0..251837e3 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -24,7 +24,6 @@ pylorax_log = logging.getLogger("pylorax") server_log = logging.getLogger("server") dnf_log = logging.getLogger("dnf") -import argparse import grp import os import pwd @@ -37,6 +36,7 @@ from gevent import socket from gevent.wsgi import WSGIServer from pylorax import vernum +from pylorax.api.cmdline import lorax_composer_parser from pylorax.api.config import configure, make_dnf_dirs, make_queue_dirs from pylorax.api.queue import start_queue_monitor from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory @@ -45,40 +45,6 @@ from pylorax.api.dnfbase import get_base_object VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) -def get_parser(): - """ Return the ArgumentParser for lorax-composer""" - - parser = argparse.ArgumentParser(description="Lorax Composer API Server", - fromfile_prefix_chars="@") - - parser.add_argument("--socket", default="/run/weldr/api.socket", metavar="SOCKET", - help="Path to the socket file to listen on") - parser.add_argument("--user", default="weldr", metavar="USER", - help="User to use for reduced permissions") - parser.add_argument("--group", default="weldr", metavar="GROUP", - help="Group to set ownership of the socket to") - parser.add_argument("--log", dest="logfile", default="/var/log/lorax-composer/composer.log", metavar="LOG", - help="Path to logfile (/var/log/lorax-composer/composer.log)") - parser.add_argument("--mockfiles", default="/var/tmp/bdcs-mockfiles/", metavar="MOCKFILES", - help="Path to JSON files used for /api/mock/ paths (/var/tmp/bdcs-mockfiles/)") - parser.add_argument("--sharedir", type=os.path.abspath, metavar="SHAREDIR", - help="Directory containing all the templates. Overrides config file sharedir") - parser.add_argument("-V", action="store_true", dest="showver", - help="show program's version number and exit") - parser.add_argument("-c", "--config", default="/etc/lorax/composer.conf", metavar="CONFIG", - help="Path to lorax-composer configuration file.") - parser.add_argument("--releasever", default=None, metavar="STRING", - help="Release version to use for $releasever in dnf repository urls") - parser.add_argument("--tmp", default="/var/tmp", - help="Top level temporary directory") - parser.add_argument("--proxy", default=None, metavar="PROXY", - help="Set proxy for DNF, overrides configuration file setting.") - parser.add_argument("BLUEPRINTS", metavar="BLUEPRINTS", - help="Path to the blueprints") - - return parser - - def setup_logging(logfile): # Setup logging to console and to logfile log.setLevel(logging.DEBUG) @@ -155,7 +121,7 @@ def make_pidfile(pid_path="/run/lorax-composer.pid"): if __name__ == '__main__': # parse the arguments - opts = get_parser().parse_args() + opts = lorax_composer_parser().parse_args() if opts.showver: print(VERSION)