use python-cliff for CLI
Shotgun now uses python-cliff to provide CLI like: shotgun2 snapshot --config /path/to/snopshot_config.yaml This change will allow us to add other subcommands like "shotgun2 report" that is to be used for gathering short report about the master node (instead of version.yaml) Previous version of shotgun CLI is still available and deprecated. Change-Id: I3bc1f711d0e0fcf06f9414df1533d641a0e46595 Related-Bug: #1515517
This commit is contained in:
parent
0496f04ff9
commit
b7224bd244
|
@ -1,2 +1,3 @@
|
|||
Fabric>=1.7.0
|
||||
six>=1.9.0
|
||||
cliff>=1.7.0
|
||||
|
|
7
setup.py
7
setup.py
|
@ -33,4 +33,9 @@ setuptools.setup(
|
|||
'Fabric >= 1.10.0'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'shotgun = shotgun.cli:main']})
|
||||
'shotgun = shotgun.cli:main',
|
||||
'shotgun2 = shotgun.cli2:main'],
|
||||
'shotgun': [
|
||||
'snapshot = shotgun.cli2:SnapshotCommand',
|
||||
]
|
||||
})
|
||||
|
|
|
@ -11,3 +11,10 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pkg_resources
|
||||
|
||||
try:
|
||||
__version__ = pkg_resources.require(__name__)[0].version
|
||||
except pkg_resources.DistributionNotFound as e:
|
||||
__version__ = "Unknown"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
from shotgun.logger import configure_logger
|
||||
configure_logger()
|
||||
|
@ -68,4 +69,6 @@ def make_snapshot(args):
|
|||
|
||||
def main():
|
||||
"""Entry point"""
|
||||
warnings.warn("This command is deprecated. "
|
||||
"Please use 'shotgun2' instead", DeprecationWarning)
|
||||
make_snapshot(parse_args())
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import yaml
|
||||
|
||||
from cliff.app import App
|
||||
from cliff.command import Command
|
||||
from cliff.commandmanager import CommandManager
|
||||
|
||||
import shotgun
|
||||
from shotgun.logger import configure_logger
|
||||
|
||||
from shotgun.config import Config
|
||||
from shotgun.manager import Manager
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Base(object):
|
||||
def initialize_cmd(self, parsed_args):
|
||||
with open(parsed_args.config, "r") as f:
|
||||
self.config = Config(yaml.safe_load(f))
|
||||
self.manager = Manager(self.config)
|
||||
|
||||
|
||||
class SnapshotCommand(Command, Base):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SnapshotCommand, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--config',
|
||||
required=True,
|
||||
help='Path to snapshot config file')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
"""Generates snapshot
|
||||
|
||||
:param parsed_args: argparse object
|
||||
"""
|
||||
self.initialize_cmd(parsed_args)
|
||||
snapshot_path = self.manager.snapshot()
|
||||
logger.info(u'Snapshot path: {0}'.format(snapshot_path))
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
configure_logger()
|
||||
return App(
|
||||
description="Shotgun CLI",
|
||||
version=shotgun.__version__,
|
||||
command_manager=CommandManager('shotgun')
|
||||
).run(argv)
|
|
@ -14,6 +14,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
|
|||
Prefix: %{_prefix}
|
||||
BuildArch: noarch
|
||||
Requires: postgresql
|
||||
Requires: python-cliff >= 1.7.0
|
||||
Requires: python-fabric >= 1.10.0
|
||||
Requires: python-argparse
|
||||
Requires: python-six >= 1.9.0
|
||||
|
|
Loading…
Reference in New Issue