Skip to content

Commit

Permalink
Fixed(server-info): human-oriented error in case of no command specif…
Browse files Browse the repository at this point in the history
…ied (#191)

* Fixed(server-info): human-oriented error in case of no command specified.
* Release(v2.7.3)

#170
  • Loading branch information
strizhechenko committed Jan 14, 2018
1 parent 5d64088 commit 1f7c6fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions netutils_linux_hardware/cli.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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='[email protected]',
license='MIT',
Expand Down

0 comments on commit 1f7c6fd

Please sign in to comment.