Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed(server-info): human-oriented error in case of no command specified #191

Merged
merged 4 commits into from Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 29 additions & 24 deletions netutils_linux_hardware/cli.py
Expand Up @@ -16,39 +16,44 @@ class ServerInfo(object):
subsystems = ('cpu', 'memory', 'net', 'disk', 'system')

def __init__(self):
self.parser = argparse.ArgumentParser()
self.__parse_args()
self.__check_args()
self.main()

def __parse_args(self):
default_directory = '/tmp/netutils_server_info/'
parser = argparse.ArgumentParser()
parser.add_argument('--directory', type=str, help="Specify a data directory or a tarball",
default=default_directory)
parser.add_argument('--collect', action='store_true', help='Collect the data about the server', default=False)
parser.add_argument('--gzip', action='store_true', help="Compress the data", default=False)
parser.add_argument('--show', action='store_true', help='Shows data about the server in YAML', default=False)
parser.add_argument('--rate', action='store_true', help='Rates data about the server', default=False)
parser.add_argument('-f', '--folding', action='count', help='-f - device, -ff - subsystem, -fff - server',
default=FOLDING_NO)
parser.add_argument('--device', action='store_const', const=FOLDING_DEVICE, dest='folding',
help='Folds rates details to entire devices')
parser.add_argument('--subsystem', action='store_const', const=FOLDING_SUBSYSTEM, dest='folding',
help='Folds rates details to entire subsystems')
parser.add_argument('--server', action='store_const', const=FOLDING_SERVER, dest='folding',
help='Folds rates details to entire server')
parser.add_argument('--cpu', action='store_true', help='Show information about CPU', default=False)
parser.add_argument('--memory', action='store_true', help='Show information about RAM', default=False)
parser.add_argument('--net', action='store_true', help='Show information about network devices', default=False)
parser.add_argument('--disk', action='store_true', help='Show information about disks', default=False)
parser.add_argument('--system', action='store_true', help='Show information about system overall (rate only)',
default=False)
self.args = parser.parse_args()
self.parser.add_argument('--directory', type=str, help="Specify a data directory or a tarball",
default=default_directory)
self.parser.add_argument('--collect', action='store_true', help='Collect the data about the server',
default=False)
self.parser.add_argument('--gzip', action='store_true', help="Compress the data", default=False)
self.parser.add_argument('--show', action='store_true', help='Shows data about the server in YAML',
default=False)
self.parser.add_argument('--rate', action='store_true', help='Rates data about the server', default=False)
self.parser.add_argument('-f', '--folding', action='count', help='-f - device, -ff - subsystem, -fff - server',
default=FOLDING_NO)
self.parser.add_argument('--device', action='store_const', const=FOLDING_DEVICE, dest='folding',
help='Folds rates details to entire devices')
self.parser.add_argument('--subsystem', action='store_const', const=FOLDING_SUBSYSTEM, dest='folding',
help='Folds rates details to entire subsystems')
self.parser.add_argument('--server', action='store_const', const=FOLDING_SERVER, dest='folding',
help='Folds rates details to entire server')
self.parser.add_argument('--cpu', action='store_true', help='Show information about CPU', default=False)
self.parser.add_argument('--memory', action='store_true', help='Show information about RAM', default=False)
self.parser.add_argument('--net', action='store_true', help='Show information about network devices',
default=False)
self.parser.add_argument('--disk', action='store_true', help='Show information about disks', default=False)
self.parser.add_argument('--system', action='store_true',
help='Show information about system overall (rate only)', default=False)
self.args = self.parser.parse_args()

def __check_args(self):
""" Maybe they should be positional arguments, not options. But subparsers/groups are stupid """
assert any([self.args.collect, self.args.rate, self.args.show]), "Specify command: {0}".format(self.commands)

if not any([self.args.collect, self.args.rate, self.args.show]):
print('Error: please, specify --rate, --show or --collect command')
self.parser.print_help()
exit(1)
if not any(getattr(self.args, subsystem) for subsystem in self.subsystems):
for subsystem in self.subsystems:
setattr(self.args, subsystem, True)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,7 +16,7 @@ def read(*paths):

setuptools.setup(
name='netutils-linux',
version='2.7.2',
version='2.7.3',
author='Oleg Strizhechenko',
author_email='oleg.strizhechenko@gmail.com',
license='MIT',
Expand Down