summaryrefslogtreecommitdiffstats
path: root/ogcli
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-05-20 10:22:42 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-05-20 10:22:42 +0200
commitd90ab82cec328004e743b2bfbb7c25b32eb299ea (patch)
treefcfbfd01f3517631119b7f41ae8363e1259177bd /ogcli
parentf88bcf78ac9ffefcedfb4e108b703dac40ca5839 (diff)
format: use autopep8
Use autopep8 for coding format, and only for whitespace changes. This change drops use of tabs in favor of spaces. Doesn't use autopep8 --aggresive option. Format command: $ autopep8 --inline --recursive . When using git-blame, use --ignore-rev in order to ignore this reformatting commit.
Diffstat (limited to 'ogcli')
-rwxr-xr-xogcli66
1 files changed, 34 insertions, 32 deletions
diff --git a/ogcli b/ogcli
index 4cfe339..078a07e 100755
--- a/ogcli
+++ b/ogcli
@@ -14,39 +14,41 @@ import argparse
import json
import sys
-OG_CLI_CFG_PATH="/opt/opengnsys/etc/ogcli.json"
+OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json"
+
class CLI():
- def __init__(self):
- try:
- with open(OG_CLI_CFG_PATH, 'r') as json_file:
- self.cfg = json.load(json_file)
- except json.JSONDecodeError:
- sys.exit(f'ERROR: Failed parse malformed JSON file '
- f'{OG_CLI_CFG_PATH}')
- except:
- sys.exit(f'ERROR: cannot open {OG_CLI_CFG_PATH}')
-
- required_cfg_params = {'api_token', 'ip', 'port'}
- difference_cfg_params = required_cfg_params - self.cfg.keys()
- if len(difference_cfg_params) > 0:
- sys.exit(f'Missing {difference_cfg_params} key in '
- f'json config file')
-
- self.ogcli = OgCLI(self.cfg)
-
- parser = argparse.ArgumentParser(prog='ogcli')
- parser.add_argument('command', help='Subcommand to run', nargs='?',
- choices=[attr for attr, _ in getmembers(self.ogcli, lambda x: ismethod(x))
- if not attr.startswith('_')])
- args = parser.parse_args(sys.argv[1:2])
-
- if not hasattr(self.ogcli, args.command):
- parser.print_help()
- sys.exit('Unknown command')
-
- # Call the command with the same name.
- getattr(self.ogcli, args.command)(sys.argv[2:])
+ def __init__(self):
+ try:
+ with open(OG_CLI_CFG_PATH, 'r') as json_file:
+ self.cfg = json.load(json_file)
+ except json.JSONDecodeError:
+ sys.exit(f'ERROR: Failed parse malformed JSON file '
+ f'{OG_CLI_CFG_PATH}')
+ except:
+ sys.exit(f'ERROR: cannot open {OG_CLI_CFG_PATH}')
+
+ required_cfg_params = {'api_token', 'ip', 'port'}
+ difference_cfg_params = required_cfg_params - self.cfg.keys()
+ if len(difference_cfg_params) > 0:
+ sys.exit(f'Missing {difference_cfg_params} key in '
+ f'json config file')
+
+ self.ogcli = OgCLI(self.cfg)
+
+ parser = argparse.ArgumentParser(prog='ogcli')
+ parser.add_argument('command', help='Subcommand to run', nargs='?',
+ choices=[attr for attr, _ in getmembers(self.ogcli, lambda x: ismethod(x))
+ if not attr.startswith('_')])
+ args = parser.parse_args(sys.argv[1:2])
+
+ if not hasattr(self.ogcli, args.command):
+ parser.print_help()
+ sys.exit('Unknown command')
+
+ # Call the command with the same name.
+ getattr(self.ogcli, args.command)(sys.argv[2:])
+
if __name__ == "__main__":
- CLI()
+ CLI()