
Update copyright and licenses to note that code is HP proprietary and has not been approved by the OSRB. Add comments noting where code has been included from other projects and include the appropriate license terms in the file header. Change-Id: I2ce8c2d48e6f73d18d95fa073e5f962805121d1a
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
#
|
|
# Copyright (c) 2011 OpenStack LLC.
|
|
# Copyright (c) 2013 Hewlett-Packard
|
|
#
|
|
# 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 os
|
|
import sys
|
|
|
|
|
|
def get_subcommands(subparsers):
|
|
|
|
subcommands = _find_actions(subparsers, os.path.dirname(__file__))
|
|
|
|
return subcommands
|
|
|
|
|
|
# partially taken from python-keystoneclient
|
|
def _find_actions(subparsers, module_path):
|
|
subcommands = {}
|
|
for mod in (p[:-len('.py')] for p in os.listdir(module_path) if p.endswith('.py')):
|
|
__import__(__name__ + '.' + mod)
|
|
module = sys.modules[__name__ + '.' + mod]
|
|
for attr in (a for a in dir(module) if a.startswith('do_')):
|
|
command = attr[3:].replace('_', '-')
|
|
func = getattr(module, attr)
|
|
desc = func.__doc__ or ''
|
|
help = desc.strip().split('\n')[0]
|
|
args = getattr(func, 'arguments', [])
|
|
|
|
subparser = subparsers.add_parser(
|
|
command,
|
|
help=help,
|
|
description=desc)
|
|
|
|
for (args, kwargs) in args:
|
|
subparser.add_argument(*args, **kwargs)
|
|
subparser.set_defaults(func=func)
|
|
subcommands[command] = subparser
|
|
|
|
return subcommands
|