瀏覽代碼

commands: fix pep8 errors

Victor Seva 5 年之前
父節點
當前提交
b2cea1519a

+ 44 - 45
kamcli/commands/cmd_address.py

@@ -1,32 +1,23 @@
 import click
 import click
-import hashlib
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('address', help='Manage permissions address records')
 @click.group('address', help='Manage permissions address records')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new record to address table')
 @cli.command('add', short_help='Add a new record to address table')
 @click.option('mask', '--mask', type=int, default=32,
 @click.option('mask', '--mask', type=int, default=32,
-            help='Mask value (default 32)')
+              help='Mask value (default 32)')
 @click.option('port', '--port', type=int, default=0,
 @click.option('port', '--port', type=int, default=0,
-            help='Port value (default 0)')
+              help='Port value (default 0)')
 @click.option('tag', '--tag', default='',
 @click.option('tag', '--tag', default='',
-            help='Tag value (default: "")')
+              help='Tag value (default: "")')
 @click.argument('group', metavar='<group>', type=int)
 @click.argument('group', metavar='<group>', type=int)
 @click.argument('address', metavar='<address>')
 @click.argument('address', metavar='<address>')
 @pass_context
 @pass_context
@@ -40,17 +31,20 @@ def address_add(ctx, mask, port, tag, group, address):
     """
     """
     ctx.vlog('Adding to group id [%d] address [%s]', group, address)
     ctx.vlog('Adding to group id [%d] address [%s]', group, address)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into address (grp, ip_addr, mask, port, tag) values ({0}, {1!r}, {2}, {3}, {4!r})'.format(group, address.encode('ascii','ignore').decode(), mask, port, tag.encode('ascii','ignore').decode()))
+    e.execute(
+        'insert into address (grp, ip_addr, mask, port, tag) values '
+        '({0}, {1!r}, {2}, {3}, {4!r})'.format(
+            group,
+            address.encode('ascii', 'ignore').decode(),
+            mask, port, tag.encode('ascii', 'ignore').decode())
+    )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove a record from address db table')
 @cli.command('rm', short_help='Remove a record from address db table')
 @click.option('mask', '--mask', type=int,
 @click.option('mask', '--mask', type=int,
-            help='Mask value')
+              help='Mask value')
 @click.option('port', '--port', type=int,
 @click.option('port', '--port', type=int,
-            help='Port value')
+              help='Port value')
 @click.argument('group', metavar='<group>', type=int)
 @click.argument('group', metavar='<group>', type=int)
 @click.argument('address', metavar='<address>')
 @click.argument('address', metavar='<address>')
 @pass_context
 @pass_context
@@ -63,27 +57,37 @@ def address_rm(ctx, mask, port, group, address):
         <address> - IP address
         <address> - IP address
     """
     """
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    addr = address.encode('ascii', 'ignore').decode()
     if not mask:
     if not mask:
         if not port:
         if not port:
-            e.execute('delete from address where grp={0} and ip_addr={1!r}'.format(group, address.encode('ascii','ignore').decode()))
+            e.execute(
+                'delete from address where grp={0} and ip_addr={1!r}'.format(
+                    group, addr)
+            )
         else:
         else:
-            e.execute('delete from address where grp={0} and ip_addr={1!r} and port={2}'.format(group, address.encode('ascii','ignore').decode(), port))
+            e.execute(
+                'delete from address where grp={0} and ip_addr={1!r} '
+                'and port={2}'.format(group, addr, port)
+            )
     else:
     else:
         if not port:
         if not port:
-            e.execute('delete from address where grp={0} and ip_addr={1!r} and mask={2}'.format(group, address.encode('ascii','ignore').decode(), mask))
+            e.execute(
+                'delete from address where grp={0} and '
+                'ip_addr={1!r} and mask={2}'.format(group, addr, mask)
+            )
         else:
         else:
-            e.execute('delete from address where setid={0} and destination={1!r} and mask={2} and port={3}'.format(group, address.encode('ascii','ignore').decode(), mask, port))
+            e.execute(
+                'delete from address where setid={0} and destination={1!r} '
+                'and mask={2} and port={3}'.format(group, addr, mask, port)
+            )
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show address records in database')
 @cli.command('showdb', short_help='Show address records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('group', nargs=-1, metavar='[<group>]', type=int)
 @click.argument('group', nargs=-1, metavar='[<group>]', type=int)
 @pass_context
 @pass_context
 def address_showdb(ctx, oformat, ostyle, group):
 def address_showdb(ctx, oformat, ostyle, group):
@@ -103,12 +107,9 @@ def address_showdb(ctx, oformat, ostyle, group):
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='Show details for address records in memory')
 @cli.command('list', short_help='Show details for address records in memory')
 @click.option('tag', '--mode', default='all',
 @click.option('tag', '--mode', default='all',
-            help='What to be printed (all, addresses, subnets, domains)')
+              help='What to be printed (all, addresses, subnets, domains)')
 @click.argument('group', nargs=-1, metavar='[<group>]', type=int)
 @click.argument('group', nargs=-1, metavar='[<group>]', type=int)
 @pass_context
 @pass_context
 def address_list(ctx, mode, group):
 def address_list(ctx, mode, group):
@@ -119,26 +120,24 @@ def address_list(ctx, mode, group):
         <group> - address group
         <group> - address group
     """
     """
     if mode == "all":
     if mode == "all":
-        command_ctl(ctx, 'permissions.addressDump', [ ])
-        command_ctl(ctx, 'permissions.subnetDump', [ ])
-        command_ctl(ctx, 'permissions.domainDump', [ ])
+        command_ctl(ctx, 'permissions.addressDump', [])
+        command_ctl(ctx, 'permissions.subnetDump', [])
+        command_ctl(ctx, 'permissions.domainDump', [])
     elif mode == "addresses":
     elif mode == "addresses":
-        command_ctl(ctx, 'permissions.addressDump', [ ])
+        command_ctl(ctx, 'permissions.addressDump', [])
     elif mode == "subnets":
     elif mode == "subnets":
-        command_ctl(ctx, 'permissions.subnetDump', [ ])
+        command_ctl(ctx, 'permissions.subnetDump', [])
     elif mode == "domains":
     elif mode == "domains":
-        command_ctl(ctx, 'permissions.domainDump', [ ])
+        command_ctl(ctx, 'permissions.domainDump', [])
     else:
     else:
-        command_ctl(ctx, 'permissions.addressDump', [ ])
+        command_ctl(ctx, 'permissions.addressDump', [])
 
 
 
 
-##
-#
-#
[email protected]('reload', short_help='Reload address records from database into memory')
[email protected](
+    'reload', short_help='Reload address records from database into memory'
+)
 @pass_context
 @pass_context
 def address_reload(ctx):
 def address_reload(ctx):
     """Reload address records from database into memory
     """Reload address records from database into memory
     """
     """
-    command_ctl(ctx, 'permissions.addressReload', [ ])
-
+    command_ctl(ctx, 'permissions.addressReload', [])

+ 54 - 39
kamcli/commands/cmd_aliasdb.py

@@ -5,21 +5,15 @@ from kamcli.cli import pass_context
 from kamcli.cli import parse_user_spec
 from kamcli.cli import parse_user_spec
 
 
 
 
-##
-#
-#
 @click.group('aliasdb', help='Manage database user aliases')
 @click.group('aliasdb', help='Manage database user aliases')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a user-alias pair')
 @cli.command('add', short_help='Add a user-alias pair')
 @click.option('table', '--table', default='dbaliases',
 @click.option('table', '--table', default='dbaliases',
-            help='Name of database table (default: dbaliases)')
+              help='Name of database table (default: dbaliases)')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('aliasid', metavar='<aliasid>')
 @click.argument('aliasid', metavar='<aliasid>')
 @pass_context
 @pass_context
@@ -33,21 +27,25 @@ def aliasdb_add(ctx, table, userid, aliasid):
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
     adata = parse_user_spec(ctx, aliasid)
     adata = parse_user_spec(ctx, aliasid)
-    ctx.vlog('Adding user [%s@%s] with alias [%s@%s]', udata['username'], udata['domain'],
-            adata['username'], adata['domain'])
+    ctx.vlog(
+        'Adding user [%s@%s] with alias [%s@%s]',
+        udata['username'], udata['domain'],
+        adata['username'], adata['domain']
+    )
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into ' + table + ' (username, domain, alias_username, alias_domain) values (%s, %s, %s, %s)',
-            udata['username'], udata['domain'], adata['username'], adata['domain'])
+    e.execute(
+        'insert into ' + table + ' (username, domain, alias_username, '
+        'alias_domain) values (%s, %s, %s, %s)',
+        udata['username'], udata['domain'],
+        adata['username'], adata['domain']
+    )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove records for a user and/or alias')
 @cli.command('rm', short_help='Remove records for a user and/or alias')
 @click.option('table', '--table', default='dbaliases',
 @click.option('table', '--table', default='dbaliases',
-            help='Name of database table (default: dbaliases)')
+              help='Name of database table (default: dbaliases)')
 @click.option('matchalias', '--match-alias', is_flag=True,
 @click.option('matchalias', '--match-alias', is_flag=True,
-            help='Match userid value as alias (when given one argument)')
+              help='Match userid value as alias (when given one argument)')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('aliasid', metavar='<aliasid>', nargs=-1)
 @click.argument('aliasid', metavar='<aliasid>', nargs=-1)
 @pass_context
 @pass_context
@@ -60,35 +58,42 @@ def aliasdb_rm(ctx, table, matchalias, userid, aliasid):
         <aliasid> - username, AoR or SIP URI for alias (optional)
         <aliasid> - username, AoR or SIP URI for alias (optional)
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Removing alias for record [%s@%s]', udata['username'], udata['domain'])
+    ctx.log('Removing alias for record [%s@%s]',
+            udata['username'], udata['domain'])
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     if not aliasid:
     if not aliasid:
         if matchalias:
         if matchalias:
-            e.execute('delete from ' + table + ' where alias_username=%s and alias_domain=%s',
-                    udata['username'], udata['domain'])
+            e.execute(
+                'delete from ' + table + ' where alias_username=%s and '
+                'alias_domain=%s',
+                udata['username'], udata['domain']
+            )
         else:
         else:
-            e.execute('delete from ' + table + ' where username=%s and domain=%s',
-                    udata['username'], udata['domain'])
+            e.execute(
+                'delete from ' + table + ' where username=%s and domain=%s',
+                udata['username'], udata['domain']
+            )
     else:
     else:
         for a in aliasid:
         for a in aliasid:
             adata = parse_user_spec(ctx, a)
             adata = parse_user_spec(ctx, a)
-            e.execute('delete from ' + table + ' where username=%s and domain=%s and alias_username=%s and alias_domain=%s',
-                    udata['username'], udata['domain'], adata['username'], adata['domain'])
+            e.execute(
+                'delete from ' + table + ' where username=%s and domain=%s '
+                'and alias_username=%s and alias_domain=%s',
+                udata['username'], udata['domain'],
+                adata['username'], adata['domain']
+            )
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show user aliases')
 @cli.command('show', short_help='Show user aliases')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.option('table', '--table', default='dbaliases',
 @click.option('table', '--table', default='dbaliases',
-            help='Name of database table (default: dbaliases)')
+              help='Name of database table (default: dbaliases)')
 @click.option('matchalias', '--match-alias', is_flag=True,
 @click.option('matchalias', '--match-alias', is_flag=True,
-            help='Match userid value as alias')
+              help='Match userid value as alias')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @pass_context
 @pass_context
 def aliasdb_show(ctx, oformat, ostyle, table, matchalias, userid):
 def aliasdb_show(ctx, oformat, ostyle, table, matchalias, userid):
@@ -111,13 +116,23 @@ def aliasdb_show(ctx, oformat, ostyle, table, matchalias, userid):
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
 
 
             if matchalias:
             if matchalias:
-                ctx.vlog('Showing records for alias [%s@%s]', udata['username'], udata['domain'])
-                res = e.execute('select * from ' + table + ' where alias_username=%s and alias_domain=%s',
-                        udata['username'], udata['domain'])
+                ctx.vlog(
+                    'Showing records for alias [%s@%s]',
+                    udata['username'], udata['domain']
+                )
+                res = e.execute(
+                    'select * from ' + table + ' where alias_username=%s '
+                    'and alias_domain=%s',
+                    udata['username'], udata['domain']
+                )
             else:
             else:
-                ctx.vlog('Showing records for user [%s@%s]', udata['username'], udata['domain'])
-                res = e.execute('select * from ' + table + ' where username=%s and domain=%s',
-                        udata['username'], udata['domain'])
+                ctx.vlog(
+                    'Showing records for user [%s@%s]',
+                    udata['username'], udata['domain']
+                )
+                res = e.execute(
+                    'select * from ' + table + ' where username=%s and '
+                    'domain=%s',
+                    udata['username'], udata['domain']
+                )
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
-
-

+ 6 - 3
kamcli/commands/cmd_config.py

@@ -1,9 +1,9 @@
-import os
 import sys
 import sys
 import click
 import click
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.cli import COMMAND_ALIASES
 from kamcli.cli import COMMAND_ALIASES
 
 
+
 @click.group('config', help='Manage the config file')
 @click.group('config', help='Manage the config file')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
@@ -19,7 +19,10 @@ def config_raw(ctx):
     ctx.log('\n---')
     ctx.log('\n---')
 
 
 
 
[email protected]('show', short_help='Show expanded content of configuration file sections')
[email protected](
+    'show',
+    short_help='Show expanded content of configuration file sections'
+)
 @click.argument('sections', nargs=-1, metavar='<sections>')
 @click.argument('sections', nargs=-1, metavar='<sections>')
 @pass_context
 @pass_context
 def config_show(ctx, sections):
 def config_show(ctx, sections):
@@ -48,4 +51,4 @@ def config_cmdaliases(ctx):
     """Show the command aliases"""
     """Show the command aliases"""
     print()
     print()
     print(COMMAND_ALIASES)
     print(COMMAND_ALIASES)
-    print()
+    print()

+ 41 - 45
kamcli/commands/cmd_db.py

@@ -1,35 +1,33 @@
 import os
 import os
 import sys
 import sys
 import click
 import click
-import hashlib
-import pprint
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
-from sqlalchemy.schema import CreateTable
+from sqlalchemy.exc import SQLAlchemyError
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_formats_list
 from kamcli.ioutils import ioutils_formats_list
 
 
-##
-#
-#
+
+CMD_BASE = 'mysql -h {0} -u {1} -p{2} '
+
+
 @click.group('db', help='Raw database operations')
 @click.group('db', help='Raw database operations')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('connect', help='Launch db cli and connect to database')
 @cli.command('connect', help='Launch db cli and connect to database')
 @pass_context
 @pass_context
 def db_connect(ctx):
 def db_connect(ctx):
     dbtype = ctx.gconfig.get('db', 'type')
     dbtype = ctx.gconfig.get('db', 'type')
     if dbtype.lower() == "mysql":
     if dbtype.lower() == "mysql":
-        scmd = "mysql -h {0} -u {1} -p{2} {3}".format(ctx.gconfig.get('db', 'host'),
-                ctx.gconfig.get('db', 'rwuser'), ctx.gconfig.get('db', 'rwpassword'), ctx.gconfig.get('db', 'dbname'))
+        scmd = (CMD_BASE + "{3}").format(
+            ctx.gconfig.get('db', 'host'),
+            ctx.gconfig.get('db', 'rwuser'),
+            ctx.gconfig.get('db', 'rwpassword'),
+            ctx.gconfig.get('db', 'dbname')
+        )
     elif dbtype == "postgres":
     elif dbtype == "postgres":
         ctx.log("unsupported database type [%s]", dbtype)
         ctx.log("unsupported database type [%s]", dbtype)
         sys.exit()
         sys.exit()
@@ -48,8 +46,12 @@ def db_connect(ctx):
 def db_clirun(ctx, query):
 def db_clirun(ctx, query):
     dbtype = ctx.gconfig.get('db', 'type')
     dbtype = ctx.gconfig.get('db', 'type')
     if dbtype == "mysql":
     if dbtype == "mysql":
-        scmd = 'mysql -h {0} -u {1} -p{2} -e "{3} ;" {4}'.format(ctx.gconfig.get('db', 'host'),
-                ctx.gconfig.get('db', 'rwuser'), ctx.gconfig.get('db', 'rwpassword'), query, ctx.gconfig.get('db', 'dbname'))
+        scmd = (CMD_BASE + '-e "{3} ;" {4}').format(
+            ctx.gconfig.get('db', 'host'),
+            ctx.gconfig.get('db', 'rwuser'),
+            ctx.gconfig.get('db', 'rwpassword'),
+            query, ctx.gconfig.get('db', 'dbname')
+        )
     elif dbtype == "postgres":
     elif dbtype == "postgres":
         ctx.log("unsupported database type [%s]", dbtype)
         ctx.log("unsupported database type [%s]", dbtype)
         sys.exit()
         sys.exit()
@@ -59,17 +61,18 @@ def db_clirun(ctx, query):
     os.system(scmd)
     os.system(scmd)
 
 
 
 
-##
-#
-#
 @cli.command('clishow', help='Show content of table via cli')
 @cli.command('clishow', help='Show content of table via cli')
 @click.argument('table', metavar='<table>')
 @click.argument('table', metavar='<table>')
 @pass_context
 @pass_context
 def db_clishow(ctx, table):
 def db_clishow(ctx, table):
     dbtype = ctx.gconfig.get('db', 'type')
     dbtype = ctx.gconfig.get('db', 'type')
     if dbtype == "mysql":
     if dbtype == "mysql":
-        scmd = 'mysql -h {0} -u {1} -p{2} -e "select * from {3} ;" {4}'.format(ctx.gconfig.get('db', 'host'),
-                ctx.gconfig.get('db', 'rwuser'), ctx.gconfig.get('db', 'rwpassword'), table, ctx.gconfig.get('db', 'dbname'))
+        scmd = (CMD_BASE + '-e "select * from {3} ;" {4}').format(
+            ctx.gconfig.get('db', 'host'),
+            ctx.gconfig.get('db', 'rwuser'),
+            ctx.gconfig.get('db', 'rwpassword'),
+            table, ctx.gconfig.get('db', 'dbname')
+        )
     elif dbtype == "postgres":
     elif dbtype == "postgres":
         ctx.log("unsupported database type [%s]", dbtype)
         ctx.log("unsupported database type [%s]", dbtype)
         sys.exit()
         sys.exit()
@@ -79,17 +82,18 @@ def db_clishow(ctx, table):
     os.system(scmd)
     os.system(scmd)
 
 
 
 
-##
-#
-#
 @cli.command('clishowg', help='Show content of table via cli')
 @cli.command('clishowg', help='Show content of table via cli')
 @click.argument('table', metavar='<table>')
 @click.argument('table', metavar='<table>')
 @pass_context
 @pass_context
 def db_clishowg(ctx, table):
 def db_clishowg(ctx, table):
     dbtype = ctx.gconfig.get('db', 'type')
     dbtype = ctx.gconfig.get('db', 'type')
     if dbtype == "mysql":
     if dbtype == "mysql":
-        scmd = 'mysql -h {0} -u {1} -p{2} -e "select * from {3} \G" {4}'.format(ctx.gconfig.get('db', 'host'),
-                ctx.gconfig.get('db', 'rwuser'), ctx.gconfig.get('db', 'rwpassword'), table, ctx.gconfig.get('db', 'dbname'))
+        scmd = (CMD_BASE + '-e "select * from {3} \G" {4}').format(
+            ctx.gconfig.get('db', 'host'),
+            ctx.gconfig.get('db', 'rwuser'),
+            ctx.gconfig.get('db', 'rwpassword'),
+            table, ctx.gconfig.get('db', 'dbname')
+        )
     elif dbtype == "postgres":
     elif dbtype == "postgres":
         ctx.log("unsupported database type [%s]", dbtype)
         ctx.log("unsupported database type [%s]", dbtype)
         sys.exit()
         sys.exit()
@@ -99,15 +103,12 @@ def db_clishowg(ctx, table):
     os.system(scmd)
     os.system(scmd)
 
 
 
 
-##
-#
-#
 @cli.command('show', help='Show content of a table')
 @cli.command('show', help='Show content of a table')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(ioutils_formats_list),
-                default=None, help='Format the output')
+              type=click.Choice(ioutils_formats_list),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('table', metavar='<table>')
 @click.argument('table', metavar='<table>')
 @pass_context
 @pass_context
 def db_show(ctx, oformat, ostyle, table):
 def db_show(ctx, oformat, ostyle, table):
@@ -117,15 +118,12 @@ def db_show(ctx, oformat, ostyle, table):
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('showcreate', help='Show content of a table')
 @cli.command('showcreate', help='Show content of a table')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(ioutils_formats_list),
-                default=None, help='Format the output')
+              type=click.Choice(ioutils_formats_list),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('table', metavar='<table>')
 @click.argument('table', metavar='<table>')
 @pass_context
 @pass_context
 def db_showcreate(ctx, oformat, ostyle, table):
 def db_showcreate(ctx, oformat, ostyle, table):
@@ -134,9 +132,7 @@ def db_showcreate(ctx, oformat, ostyle, table):
     res = e.execute('show create table {0}'.format(table))
     res = e.execute('show create table {0}'.format(table))
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
-##
-#
-#
+
 def db_engine_exec_file(ctx, sqlengine, fname):
 def db_engine_exec_file(ctx, sqlengine, fname):
     sql_file = open(fname, 'r')
     sql_file = open(fname, 'r')
     sql_command = ''
     sql_command = ''
@@ -147,15 +143,15 @@ def db_engine_exec_file(ctx, sqlengine, fname):
                 try:
                 try:
                     sqlengine.execute(text(sql_command))
                     sqlengine.execute(text(sql_command))
                     sqlengine.commit()
                     sqlengine.commit()
-                except:
-                    ctx.log("failed to execute sql statements from file [%s]", fname)
+                except SQLAlchemyError:
+                    ctx.log(
+                        "failed to execute sql statements from file [%s]",
+                        fname
+                    )
                 finally:
                 finally:
                     sql_command = ''
                     sql_command = ''
 
 
 
 
-##
-#
-#
 @cli.command('runfile', help='Run SQL statements in a file')
 @cli.command('runfile', help='Run SQL statements in a file')
 @click.argument('fname', metavar='<fname>')
 @click.argument('fname', metavar='<fname>')
 @pass_context
 @pass_context

+ 22 - 33
kamcli/commands/cmd_dialog.py

@@ -2,28 +2,21 @@ import click
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('dialog', help='Manage dialog module (active calls tracking)')
 @click.group('dialog', help='Manage dialog module (active calls tracking)')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show dialog records in database')
 @cli.command('showdb', short_help='Show dialog records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @pass_context
 @pass_context
 def dialog_showdb(ctx, oformat, ostyle):
 def dialog_showdb(ctx, oformat, ostyle):
     """Show details for records in dialog table
     """Show details for records in dialog table
@@ -36,9 +29,6 @@ def dialog_showdb(ctx, oformat, ostyle):
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='Show details for dialog records in memory')
 @cli.command('list', short_help='Show details for dialog records in memory')
 @pass_context
 @pass_context
 def dialog_list(ctx):
 def dialog_list(ctx):
@@ -46,12 +36,9 @@ def dialog_list(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'dlg.list', [ ])
+    command_ctl(ctx, 'dlg.list', [])
 
 
 
 
-##
-#
-#
 @cli.command('match', short_help='Show the details for the matching dialogs')
 @cli.command('match', short_help='Show the details for the matching dialogs')
 @click.argument('mkey', metavar='<mkey>')
 @click.argument('mkey', metavar='<mkey>')
 @click.argument('mop', metavar='<mkey>')
 @click.argument('mop', metavar='<mkey>')
@@ -62,17 +49,25 @@ def dialog_match(ctx, mkey, mop, mval):
 
 
     \b
     \b
     Parameters:
     Parameters:
-        <mkey> - matching key: ruri - use R-URI; furi - use From-URI; turi - use To-URI; callid - use Call-Id
-        <mop> - matching operator: eq - string comparison; re - regular expression; sw - starts-with
+        <mkey> - matching key:
+          ruri - use R-URI;
+          furi - use From-URI;
+          turi - use To-URI;
+          callid - use Call-Id
+        <mop> - matching operator:
+          eq - string comparison;
+          re - regular expression;
+          sw - starts-with
         <mval> - matching value
         <mval> - matching value
     """
     """
-    command_ctl(ctx, 'dlg.list_match', [ mkey, mop, mval ])
+    command_ctl(ctx, 'dlg.list_match', [mkey, mop, mval])
 
 
 
 
-##
-#
-#
[email protected]('terminate', short_help='Send BYE to the dialog identified by call-id, from-tag and to-tag')
[email protected](
+    'terminate',
+    short_help='Send BYE to the dialog identified by call-id,'
+               ' from-tag and to-tag'
+)
 @click.argument('callid', metavar='<domain>')
 @click.argument('callid', metavar='<domain>')
 @click.argument('fromtag', metavar='<fromtag>')
 @click.argument('fromtag', metavar='<fromtag>')
 @click.argument('totag', metavar='<totag>')
 @click.argument('totag', metavar='<totag>')
@@ -86,12 +81,9 @@ def dialog_terminate(ctx, callid, fromtag, totag):
         <fromtag> - From-Tag value
         <fromtag> - From-Tag value
         <to-tag> - To-Tag value
         <to-tag> - To-Tag value
     """
     """
-    command_ctl(ctx, 'dlg.terminate_dlg', [ callid, fromtag, totag ])
+    command_ctl(ctx, 'dlg.terminate_dlg', [callid, fromtag, totag])
 
 
 
 
-##
-#
-#
 @cli.command('stats_active', short_help='Show statistics for active dialogs')
 @cli.command('stats_active', short_help='Show statistics for active dialogs')
 @pass_context
 @pass_context
 def dialog_stats_active(ctx):
 def dialog_stats_active(ctx):
@@ -99,12 +91,9 @@ def dialog_stats_active(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'dlg.stats_active', [ ])
+    command_ctl(ctx, 'dlg.stats_active', [])
 
 
 
 
-##
-#
-#
 @cli.command('profile_list', short_help='List the content of a profile')
 @cli.command('profile_list', short_help='List the content of a profile')
 @click.argument('profile', metavar='<profile>')
 @click.argument('profile', metavar='<profile>')
 @pass_context
 @pass_context
@@ -115,4 +104,4 @@ def dialog_profile_list(ctx, profile):
     Parameters:
     Parameters:
         <profile> - the name of the profile
         <profile> - the name of the profile
     """
     """
-    command_ctl(ctx, 'dlg.profile_list', [ profile ])
+    command_ctl(ctx, 'dlg.profile_list', [profile])

+ 43 - 43
kamcli/commands/cmd_dialplan.py

@@ -1,38 +1,31 @@
 import click
 import click
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('dialplan', help='Manage dialplan module (regexp translations)')
 @click.group('dialplan', help='Manage dialplan module (regexp translations)')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new dialplan rule')
 @cli.command('add', short_help='Add a new dialplan rule')
 @click.option('priority', '--priority', type=int, default=0,
 @click.option('priority', '--priority', type=int, default=0,
-            help='Priority value (default: 0)')
+              help='Priority value (default: 0)')
 @click.option('matchop', '--match-op', default='equal',
 @click.option('matchop', '--match-op', default='equal',
-            help='Match operator: equal, regexp, fnmatch (default: equal)')
+              help='Match operator: equal, regexp, fnmatch (default: equal)')
 @click.option('matchlen', '--match-len', type=int, default=0,
 @click.option('matchlen', '--match-len', type=int, default=0,
-            help='Match target lenght (default: 0)')
+              help='Match target lenght (default: 0)')
 @click.option('attrs', '--attrs', default='',
 @click.option('attrs', '--attrs', default='',
-            help='Attributes (default: "")')
+              help='Attributes (default: "")')
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('matchexp', metavar='<matchexp>')
 @click.argument('matchexp', metavar='<matchexp>')
 @click.argument('substrepl', nargs=-1, metavar='<substrepl>')
 @click.argument('substrepl', nargs=-1, metavar='<substrepl>')
 @pass_context
 @pass_context
-def dialplan_add(ctx, priority, matchop, matchlen, attrs, dpid, matchexp, substrepl):
+def dialplan_add(ctx, priority, matchop, matchlen,
+                 attrs, dpid, matchexp, substrepl):
     """Add a new translation rule in dialplan table
     """Add a new translation rule in dialplan table
 
 
     \b
     \b
@@ -44,9 +37,9 @@ def dialplan_add(ctx, priority, matchop, matchlen, attrs, dpid, matchexp, substr
     """
     """
     matchid = 0
     matchid = 0
     if matchop == "regexp":
     if matchop == "regexp":
-        matchid = 1;
+        matchid = 1
     elif matchop == "fnmatch":
     elif matchop == "fnmatch":
-        matchid = 2;
+        matchid = 2
     substexp = ""
     substexp = ""
     replexp = ""
     replexp = ""
     if len(substrepl) > 0:
     if len(substrepl) > 0:
@@ -54,14 +47,24 @@ def dialplan_add(ctx, priority, matchop, matchlen, attrs, dpid, matchexp, substr
     if len(substrepl) > 1:
     if len(substrepl) > 1:
         replexp = substrepl[1]
         replexp = substrepl[1]
 
 
-    ctx.vlog('Adding to dialplan id [%d] match [%s] expression [%s]', dpid, matchop, matchexp)
+    ctx.vlog(
+        'Adding to dialplan id [%d] match [%s] expression [%s]',
+        dpid, matchop, matchexp
+    )
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into dialplan (dpid, pr, match_op, match_exp, match_len, subst_exp, repl_exp, attrs) values ({0}, {1}, {2}, {3!r}, {4}, {5!r}, {6!r}, {7!r})'.format(dpid, priority, matchid, matchexp.encode('ascii','ignore').decode(), matchlen, substexp.encode('ascii','ignore').decode(), replexp.encode('ascii','ignore').decode(), attrs.encode('ascii','ignore').decode()))
+    e.execute(
+        'insert into dialplan (dpid, pr, match_op, match_exp, match_len, '
+        'subst_exp, repl_exp, attrs) values '
+        '({0}, {1}, {2}, {3!r}, {4}, {5!r}, {6!r}, {7!r})'.format(
+            dpid, priority, matchid,
+            matchexp.encode('ascii', 'ignore').decode(), matchlen,
+            substexp.encode('ascii', 'ignore').decode(),
+            replexp.encode('ascii', 'ignore').decode(),
+            attrs.encode('ascii', 'ignore').decode()
+        )
+    )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove records from dialplan')
 @cli.command('rm', short_help='Remove records from dialplan')
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('matchexp', nargs=-1, metavar='<match exp>')
 @click.argument('matchexp', nargs=-1, metavar='<match exp>')
@@ -79,18 +82,19 @@ def dialplan_rm(ctx, dpid, matchexp):
         e.execute('delete from dialplan where dpid={0}'.format(dpid))
         e.execute('delete from dialplan where dpid={0}'.format(dpid))
     else:
     else:
         for m in matchexp:
         for m in matchexp:
-            e.execute('delete from dialplan where dpid={0} and match_exp={1!r}'.format(dpid, matchexp.encode('ascii','ignore').decode()))
+            e.execute(
+                'delete from dialplan where '
+                'dpid={0} and match_exp={1!r}'.format(
+                    dpid, matchexp.encode('ascii', 'ignore').decode())
+            )
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show dialplan records in database')
 @cli.command('showdb', short_help='Show dialplan records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('dpid', nargs=-1, metavar='[<dpid>]', type=int)
 @click.argument('dpid', nargs=-1, metavar='[<dpid>]', type=int)
 @pass_context
 @pass_context
 def dispatcher_showdb(ctx, oformat, ostyle, dpid):
 def dispatcher_showdb(ctx, oformat, ostyle, dpid):
@@ -112,9 +116,6 @@ def dispatcher_showdb(ctx, oformat, ostyle, dpid):
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='Show details for dialplan records in memory')
 @cli.command('list', short_help='Show details for dialplan records in memory')
 @click.argument('dpid', metavar='[<dpid>]', type=int)
 @click.argument('dpid', metavar='[<dpid>]', type=int)
 @pass_context
 @pass_context
@@ -125,24 +126,25 @@ def dispatcher_list(ctx, dpid):
     Parameters:
     Parameters:
         <dpid> - dialplan id
         <dpid> - dialplan id
     """
     """
-    command_ctl(ctx, 'dialplan.dump', [ dpid ])
+    command_ctl(ctx, 'dialplan.dump', [dpid])
 
 
 
 
-##
-#
-#
-@cli.command('reload', short_help='Reload dialplan records from database into memory')
+@cli.command(
+    'reload',
+    short_help='Reload dialplan records from database into memory'
+)
 @pass_context
 @pass_context
 def dialplan_reload(ctx):
 def dialplan_reload(ctx):
     """Reload dialplan records from database into memory
     """Reload dialplan records from database into memory
     """
     """
-    command_ctl(ctx, 'dialplan.reload', [ ])
+    command_ctl(ctx, 'dialplan.reload', [])
 
 
 
 
-##
-#
-#
[email protected]('translate', short_help='Translate using the rules from dialplan applied to input value')
[email protected](
+    'translate',
+    short_help='Translate using the rules from dialplan '
+               'applied to input value'
+)
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('dpid', metavar='<dpid>', type=int)
 @click.argument('ivalue', metavar='<ivalue>')
 @click.argument('ivalue', metavar='<ivalue>')
 @pass_context
 @pass_context
@@ -154,6 +156,4 @@ def dispatcher_list(ctx, dpid, ivalue):
         <dpid> - dialplan id
         <dpid> - dialplan id
         <ivalue> - input value
         <ivalue> - input value
     """
     """
-    command_ctl(ctx, 'dialplan.translate', [ dpid, ivalue ])
-
-
+    command_ctl(ctx, 'dialplan.translate', [dpid, ivalue])

+ 36 - 44
kamcli/commands/cmd_dispatcher.py

@@ -2,35 +2,29 @@ import click
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('dispatcher', help='Manage dispatcher module (load balancer)')
 @click.group('dispatcher', help='Manage dispatcher module (load balancer)')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new dispatcher destination')
 @cli.command('add', short_help='Add a new dispatcher destination')
 @click.option('flags', '--flags', type=int, default=0,
 @click.option('flags', '--flags', type=int, default=0,
-            help='Flags value')
+              help='Flags value')
 @click.option('priority', '--priority', type=int, default=0,
 @click.option('priority', '--priority', type=int, default=0,
-            help='Priority value')
+              help='Priority value')
 @click.option('attrs', '--attrs', default='',
 @click.option('attrs', '--attrs', default='',
-            help='Attributes (default: "")')
+              help='Attributes (default: "")')
 @click.option('description', '--desc', default='',
 @click.option('description', '--desc', default='',
-            help='Description (default: "")')
+              help='Description (default: "")')
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('destination', metavar='<destination>')
 @click.argument('destination', metavar='<destination>')
 @pass_context
 @pass_context
-def dispatcher_add(ctx, flags, priority, attrs, description, setid, destination):
+def dispatcher_add(ctx, flags, priority, attrs, description,
+                   setid, destination):
     """Add a new destination in a set of dispatcher db table
     """Add a new destination in a set of dispatcher db table
 
 
     \b
     \b
@@ -40,12 +34,18 @@ def dispatcher_add(ctx, flags, priority, attrs, description, setid, destination)
     """
     """
     ctx.vlog('Adding to setid [%d] destination [%s]', setid, destination)
     ctx.vlog('Adding to setid [%d] destination [%s]', setid, destination)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into dispatcher (setid, destination, flags, priority, attrs, description) values ({0}, {1!r}, {2}, {3}, {4!r}, {5!r})'.format(setid, destination.encode('ascii','ignore').decode(), flags, priority, attrs.encode('ascii','ignore').decode(), description.encode('ascii','ignore').decode()))
+    e.execute(
+        'insert into dispatcher '
+        '(setid, destination, flags, priority, attrs, description) '
+        'values ({0}, {1!r}, {2}, {3}, {4!r}, {5!r})'.format(
+            setid, destination.encode('ascii', 'ignore').decode(),
+            flags, priority,
+            attrs.encode('ascii', 'ignore').decode(),
+            description.encode('ascii', 'ignore').decode()
+        )
+    )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove a destination from dispatcher table')
 @cli.command('rm', short_help='Remove a destination from dispatcher table')
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('destination', metavar='<destination>')
 @click.argument('destination', metavar='<destination>')
@@ -59,18 +59,18 @@ def dispatcher_rm(ctx, setid, destination):
         <destination> - SIP URI for destination
         <destination> - SIP URI for destination
     """
     """
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('delete from dispatcher where setid={0} and destination={1!r}'.format(setid, destination.encode('ascii','ignore').decode()))
+    e.execute(
+        'delete from dispatcher where setid={0} and destination={1!r}'.format(
+            setid, destination.encode('ascii', 'ignore').decode())
+    )
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show dispatcher records in database')
 @cli.command('showdb', short_help='Show dispatcher records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('setid', nargs=-1, metavar='[<setid>]', type=int)
 @click.argument('setid', nargs=-1, metavar='[<setid>]', type=int)
 @pass_context
 @pass_context
 def dispatcher_showdb(ctx, oformat, ostyle, setid):
 def dispatcher_showdb(ctx, oformat, ostyle, setid):
@@ -92,38 +92,35 @@ def dispatcher_showdb(ctx, oformat, ostyle, setid):
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
-@cli.command('list', short_help='Show details for dispatcher records in memory')
+@cli.command(
+    'list',
+    short_help='Show details for dispatcher records in memory'
+)
 @pass_context
 @pass_context
 def dispatcher_list(ctx):
 def dispatcher_list(ctx):
     """Show details for dispatcher records in memory
     """Show details for dispatcher records in memory
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'dispatcher.list', [ ])
+    command_ctl(ctx, 'dispatcher.list', [])
 
 
 
 
-##
-#
-#
-@cli.command('reload', short_help='Reload dispatcher records from database into memory')
+@cli.command(
+    'reload',
+    short_help='Reload dispatcher records from database into memory'
+)
 @pass_context
 @pass_context
 def dispatcher_reload(ctx):
 def dispatcher_reload(ctx):
     """Reload dispatcher records from database into memory
     """Reload dispatcher records from database into memory
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'dispatcher.reload', [ ])
+    command_ctl(ctx, 'dispatcher.reload', [])
 
 
 
 
-##
-#
-#
 @cli.command('memadd', short_help='Add a new dispatcher destination in memory')
 @cli.command('memadd', short_help='Add a new dispatcher destination in memory')
 @click.option('flags', '--flags', type=int, default=0,
 @click.option('flags', '--flags', type=int, default=0,
-            help='Flags value')
+              help='Flags value')
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('destination', metavar='<destination>')
 @click.argument('destination', metavar='<destination>')
 @pass_context
 @pass_context
@@ -136,12 +133,9 @@ def dispatcher_memadd(ctx, flags, setid, destination):
         <destination> - SIP URI for destination
         <destination> - SIP URI for destination
     """
     """
     ctx.vlog('Adding to setid [%d] destination [%s]', setid, destination)
     ctx.vlog('Adding to setid [%d] destination [%s]', setid, destination)
-    command_ctl(ctx, 'dispatcher.add', [ setid, destination, flags ])
+    command_ctl(ctx, 'dispatcher.add', [setid, destination, flags])
 
 
 
 
-##
-#
-#
 @cli.command('memrm', short_help='Remove a destination from dispatcher memory')
 @cli.command('memrm', short_help='Remove a destination from dispatcher memory')
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('setid', metavar='<setid>', type=int)
 @click.argument('destination', metavar='<destination>')
 @click.argument('destination', metavar='<destination>')
@@ -154,6 +148,4 @@ def dispatcher_memrm(ctx, setid, destination):
         <setid> - dispatching set id
         <setid> - dispatching set id
         <destination> - SIP URI for destination
         <destination> - SIP URI for destination
     """
     """
-    command_ctl(ctx, 'dispatcher.remove', [ setid, destination ])
-
-
+    command_ctl(ctx, 'dispatcher.remove', [setid, destination])

+ 14 - 25
kamcli/commands/cmd_domain.py

@@ -2,22 +2,15 @@ import click
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('domain', help='Manage domain module (multi-domain records)')
 @click.group('domain', help='Manage domain module (multi-domain records)')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new domain')
 @cli.command('add', short_help='Add a new domain')
 @click.argument('domain', metavar='<domain>')
 @click.argument('domain', metavar='<domain>')
 @pass_context
 @pass_context
@@ -30,12 +23,12 @@ def domain_add(ctx, domain):
     """
     """
     ctx.vlog('Adding a new domain [%s]', domain)
     ctx.vlog('Adding a new domain [%s]', domain)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into domain (domain) values ({0!r})'.format(domain.encode('ascii','ignore').decode()))
+    e.execute(
+        'insert into domain (domain) values ({0!r})'.format(
+            domain.encode('ascii', 'ignore').decode())
+    )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove a record from domain table')
 @cli.command('rm', short_help='Remove a record from domain table')
 @click.argument('domain', metavar='<domain>')
 @click.argument('domain', metavar='<domain>')
 @pass_context
 @pass_context
@@ -47,7 +40,9 @@ def domain_rm(ctx, domain):
         <domain> - domain value
         <domain> - domain value
     """
     """
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('delete from domain where domain={0!r}'.format(domain.encode('ascii','ignore').decode()))
+    e.execute('delete from domain where domain={0!r}'.format(
+        domain.encode('ascii', 'ignore').decode())
+    )
 
 
 
 
 ##
 ##
@@ -55,10 +50,10 @@ def domain_rm(ctx, domain):
 #
 #
 @cli.command('showdb', short_help='Show domain records in database')
 @cli.command('showdb', short_help='Show domain records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('domain', nargs=-1, metavar='[<domain>]')
 @click.argument('domain', nargs=-1, metavar='[<domain>]')
 @pass_context
 @pass_context
 def domain_showdb(ctx, oformat, ostyle, domain):
 def domain_showdb(ctx, oformat, ostyle, domain):
@@ -80,9 +75,6 @@ def domain_showdb(ctx, oformat, ostyle, domain):
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='Show details for domain records in memory')
 @cli.command('list', short_help='Show details for domain records in memory')
 @pass_context
 @pass_context
 def domain_list(ctx):
 def domain_list(ctx):
@@ -90,18 +82,15 @@ def domain_list(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'domain.dump', [ ])
+    command_ctl(ctx, 'domain.dump', [])
 
 
 
 
-##
-#
-#
[email protected]('reload', short_help='Reload domain records from database into memory')
[email protected](
+    'reload', short_help='Reload domain records from database into memory')
 @pass_context
 @pass_context
 def domain_reload(ctx):
 def domain_reload(ctx):
     """Reload domain records from database into memory
     """Reload domain records from database into memory
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'domain.reload', [ ])
-
+    command_ctl(ctx, 'domain.reload', [])

+ 35 - 26
kamcli/commands/cmd_group.py

@@ -5,18 +5,12 @@ from kamcli.cli import pass_context
 from kamcli.cli import parse_user_spec
 from kamcli.cli import parse_user_spec
 
 
 
 
-##
-#
-#
 @click.group('group', help='Manage the ACL of users with group membership')
 @click.group('group', help='Manage the ACL of users with group membership')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('grant', short_help='Add a user into a group')
 @cli.command('grant', short_help='Add a user into a group')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('groupid', metavar='<groupid>')
 @click.argument('groupid', metavar='<groupid>')
@@ -30,14 +24,17 @@ def group_grant(ctx, userid, groupid):
         <groupid> - group name
         <groupid> - group name
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.vlog('Adding user [%s@%s] in group [%s]', udata['username'], udata['domain'], groupid)
+    ctx.vlog(
+        'Adding user [%s@%s] in group [%s]',
+        udata['username'], udata['domain'], groupid
+    )
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into grp (username, domain, grp) values (%s, %s, %s)', udata['username'], udata['domain'], groupid)
+    e.execute(
+        'insert into grp (username, domain, grp) values (%s, %s, %s)',
+        udata['username'], udata['domain'], groupid
+    )
 
 
 
 
-##
-#
-#
 @cli.command('revoke', short_help='Remove a user from groups')
 @cli.command('revoke', short_help='Remove a user from groups')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('groupid', metavar='<groupid>', nargs=-1)
 @click.argument('groupid', metavar='<groupid>', nargs=-1)
@@ -51,23 +48,31 @@ def group_revoke(ctx, userid, groupid):
         <groupid> - group name
         <groupid> - group name
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Removing ACL for user [%s@%s]', udata['username'], udata['domain'])
+    ctx.log(
+        'Removing ACL for user [%s@%s]', udata['username'], udata['domain']
+    )
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     if not groupid:
     if not groupid:
-        e.execute('delete from grp where username=%s and domain=%s', udata['username'], udata['domain'])
+        e.execute(
+            'delete from grp where username=%s and domain=%s',
+            udata['username'], udata['domain']
+        )
     else:
     else:
-        e.execute('delete from grp where username=%s and domain=%s and grp=%s', udata['username'], udata['domain'], groupid)
+        e.execute(
+            'delete from grp where username=%s and domain=%s and grp=%s',
+            udata['username'], udata['domain'], groupid
+        )
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show group membership details')
 @cli.command('show', short_help='Show group membership details')
[email protected]('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
[email protected]('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
[email protected](
+    'oformat', '--output-format', '-F',
+    type=click.Choice(['raw', 'json', 'table', 'dict']),
+    default=None, help='Format the output')
[email protected](
+    'ostyle', '--output-style', '-S',
+    default=None,
+    help='Style of the output (tabulate table format)')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @pass_context
 @pass_context
 def group_show(ctx, oformat, ostyle, userid):
 def group_show(ctx, oformat, ostyle, userid):
@@ -87,9 +92,13 @@ def group_show(ctx, oformat, ostyle, userid):
     else:
     else:
         for u in userid:
         for u in userid:
             udata = parse_user_spec(ctx, u)
             udata = parse_user_spec(ctx, u)
-            ctx.vlog('Showing group membership for user [%s@%s]', udata['username'], udata['domain'])
+            ctx.vlog(
+                'Showing group membership for user [%s@%s]',
+                udata['username'], udata['domain']
+            )
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-            res = e.execute('select * from grp where username=%s and domain=%s', udata['username'], udata['domain'])
+            res = e.execute(
+                'select * from grp where username=%s and domain=%s',
+                udata['username'], udata['domain']
+            )
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
-
-

+ 14 - 11
kamcli/commands/cmd_jsonrpc.py

@@ -1,14 +1,13 @@
-import os
-import sys
 import click
 import click
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl_name
 from kamcli.iorpc import command_ctl_name
 from kamcli.iorpc import command_jsonrpc_fifo
 from kamcli.iorpc import command_jsonrpc_fifo
 from kamcli.iorpc import command_jsonrpc_socket
 from kamcli.iorpc import command_jsonrpc_socket
 
 
+
 @click.command('jsonrpc', short_help='Execute JSONRPC command')
 @click.command('jsonrpc', short_help='Execute JSONRPC command')
 @click.option('dryrun', '--dry-run', is_flag=True,
 @click.option('dryrun', '--dry-run', is_flag=True,
-            help='Do not execute the command, only print it')
+              help='Do not execute the command, only print it')
 @click.argument('cmd', nargs=1, metavar='[<command>]')
 @click.argument('cmd', nargs=1, metavar='[<command>]')
 @click.argument('params', nargs=-1, metavar='[<params>]')
 @click.argument('params', nargs=-1, metavar='[<params>]')
 @pass_context
 @pass_context
@@ -22,7 +21,8 @@ def cli(ctx, dryrun, cmd, params):
             - <params>  - parameters for JSONRPC command
             - <params>  - parameters for JSONRPC command
                         - by default the value of a parameter is considered
                         - by default the value of a parameter is considered
                           of type string
                           of type string
-                        - to enforce integer value prefix with 'i:' (e.g., i:10)
+                        - to enforce integer value prefix with 'i:'
+                          (e.g., i:10)
                         - string values can be also prefixed with 's:'
                         - string values can be also prefixed with 's:'
                         - if a parameter starts with 's:', prefix it with 's:'
                         - if a parameter starts with 's:', prefix it with 's:'
         Examples:
         Examples:
@@ -33,11 +33,14 @@ def cli(ctx, dryrun, cmd, params):
     """
     """
     ctx.log("Running JSONRPC command: [%s]", cmd)
     ctx.log("Running JSONRPC command: [%s]", cmd)
     if ctx.gconfig.get('jsonrpc', 'transport') == 'socket':
     if ctx.gconfig.get('jsonrpc', 'transport') == 'socket':
-        command_jsonrpc_socket(ctx, dryrun, ctx.gconfig.get('jsonrpc', 'srvaddr'),
-                ctx.gconfig.get('jsonrpc', 'rcvaddr'), ctx.gconfig.get('jsonrpc', 'outformat'),
-                command_ctl_name(cmd, 'rpc'), params)
+        command_jsonrpc_socket(
+            ctx, dryrun, ctx.gconfig.get('jsonrpc', 'srvaddr'),
+            ctx.gconfig.get('jsonrpc', 'rcvaddr'), ctx.gconfig.get(
+                'jsonrpc', 'outformat'),
+            command_ctl_name(cmd, 'rpc'), params)
     else:
     else:
-        command_jsonrpc_fifo(ctx, dryrun, ctx.gconfig.get('jsonrpc', 'path'),
-                ctx.gconfig.get('jsonrpc', 'rplnamebase'), ctx.gconfig.get('jsonrpc', 'outformat'),
-                command_ctl_name(cmd, 'rpc'), params)
-
+        command_jsonrpc_fifo(
+            ctx, dryrun, ctx.gconfig.get('jsonrpc', 'path'),
+            ctx.gconfig.get('jsonrpc', 'rplnamebase'), ctx.gconfig.get(
+                'jsonrpc', 'outformat'),
+            command_ctl_name(cmd, 'rpc'), params)

+ 12 - 15
kamcli/commands/cmd_moni.py

@@ -6,13 +6,9 @@ from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.command('moni', short_help='Monitor relevant statistics')
 @click.command('moni', short_help='Monitor relevant statistics')
 @click.option('norefresh', '--no-refresh', is_flag=True,
 @click.option('norefresh', '--no-refresh', is_flag=True,
-            help='Do not refresh (execute once)')
-
+              help='Do not refresh (execute once)')
 @pass_context
 @pass_context
 def cli(ctx, norefresh):
 def cli(ctx, norefresh):
     """Monitor relevant statistics on display
     """Monitor relevant statistics on display
@@ -24,32 +20,33 @@ def cli(ctx, norefresh):
         tm, sl and usrloc
         tm, sl and usrloc
     """
     """
 
 
-    clear = lambda : os.system('tput reset')
+    def clear():
+        return os.system('tput reset')
     count = 0
     count = 0
-    slist = [ "rcv_requests", "fwd_requests", "rcv_replies", "fwd_replies",
-            "free_size", "sent_replies", "tmx:", "usrloc:" ]
+    slist = ["rcv_requests", "fwd_requests", "rcv_replies", "fwd_replies",
+             "free_size", "sent_replies", "tmx:", "usrloc:"]
     if norefresh is True:
     if norefresh is True:
-        command_ctl(ctx, 'stats.get_statistics', slist, {"func": cmd_moni_result_print})
+        command_ctl(ctx, 'stats.get_statistics', slist,
+                    {"func": cmd_moni_result_print})
     else:
     else:
         while True:
         while True:
             count = count + 1
             count = count + 1
-            command_ctl(ctx, 'stats.get_statistics', slist, {"func": cmd_moni_result_print})
+            command_ctl(ctx, 'stats.get_statistics', slist,
+                        {"func": cmd_moni_result_print})
             print()
             print()
-            print("[cycle #: " + str(count) + "; if constant make sure server is running]")
+            print("[cycle #: " + str(count) +
+                  "; if constant make sure server is running]")
             time.sleep(2)
             time.sleep(2)
             clear()
             clear()
 
 
 
 
-##
-#
-#
 def cmd_moni_result_print(ctx, response, params=None):
 def cmd_moni_result_print(ctx, response, params=None):
     ctx.vlog("formatting the response for command ps")
     ctx.vlog("formatting the response for command ps")
     print()
     print()
     rdata = json.loads(response)
     rdata = json.loads(response)
     if "result" in rdata:
     if "result" in rdata:
         rd = rdata["result"]
         rd = rdata["result"]
-        for a, b in zip(rd[::2],rd[1::2]):
+        for a, b in zip(rd[::2], rd[1::2]):
             print('{:<40}{:<}'.format(a, b))
             print('{:<40}{:<}'.format(a, b))
     else:
     else:
         print(json.dumps(rdata, indent=4, separators=(',', ': ')))
         print(json.dumps(rdata, indent=4, separators=(',', ': ')))

+ 47 - 40
kamcli/commands/cmd_mtree.py

@@ -1,32 +1,25 @@
 import click
 import click
-import hashlib
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('mtree', help='Manage mtree module (memory trees)')
 @click.group('mtree', help='Manage mtree module (memory trees)')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new mtree record')
 @cli.command('add', short_help='Add a new mtree record')
[email protected]('tname', '--tname', default='',
-            help='Tree name to be stored in column tname (default: "")')
[email protected](
+    'tname', '--tname', default='',
+    help='Tree name to be stored in column tname (default: "")'
+)
 @click.option('coltprefix', '--coltprefix', default='tprefix',
 @click.option('coltprefix', '--coltprefix', default='tprefix',
-            help='Column name for prefix (default: "tprefix")')
+              help='Column name for prefix (default: "tprefix")')
 @click.option('coltvalue', '--coltvalue', default='tvalue',
 @click.option('coltvalue', '--coltvalue', default='tvalue',
-            help='Column name for value (default: "tvalue")')
+              help='Column name for value (default: "tvalue")')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('tprefix', metavar='<tprefix>')
 @click.argument('tprefix', metavar='<tprefix>')
 @click.argument('tvalue', metavar='<tvalue>')
 @click.argument('tvalue', metavar='<tvalue>')
@@ -40,20 +33,31 @@ def mtree_add(ctx, tname, coltprefix, coltvalue, dbtname, tprefix, tvalue):
         <tprefix> - tree prefix
         <tprefix> - tree prefix
         <tvalue>  - associated value for prefix
         <tvalue>  - associated value for prefix
     """
     """
-    ctx.vlog('Adding to tree [%s] record [%s] => [%s]', dbtname, tprefix, tvalue)
+    ctx.vlog('Adding to tree [%s] record [%s] => [%s]',
+             dbtname, tprefix, tvalue)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    dbname = dbtname.encode('ascii', 'ignore').decode()
+    col_pref = coltprefix.encode('ascii', 'ignore').decode()
+    col_val = coltvalue.encode('ascii', 'ignore').decode()
+    prefix = tprefix.encode('ascii', 'ignore').decode()
+    val = tvalue.encode('ascii', 'ignore').decode()
     if not tname:
     if not tname:
-        e.execute('insert into {0!r} ({1!r}, {2!r}) values ({3!r}, {4!r})'.format(dbtname.encode('ascii','ignore').decode(), coltprefix.encode('ascii','ignore').decode(), coltvalue.encode('ascii','ignore').decode(), tprefix.encode('ascii','ignore').decode(), tvalue.encode('ascii','ignore').decode()))
+        e.execute(
+            'insert into {0!r} ({1!r}, {2!r}) values ({3!r}, {4!r})'.format(
+                dbname, col_pref, col_val, prefix, val)
+        )
     else:
     else:
-        e.execute('insert into {0!r} (tname, {1!r}, {2!r}) values ({3!r}, {4!r}, {5!r})'.format(dbtname.encode('ascii','ignore').decode(), tname.encode('ascii','ignore').decode(), coltprefix.encode('ascii','ignore').decode(), coltvalue.encode('ascii','ignore').decode(), tprefix.encode('ascii','ignore').decode(), tvalue.encode('ascii','ignore').decode()))
+        e.execute(
+            'insert into {0!r} (tname, {1!r}, {2!r}) values '
+            '({3!r}, {4!r}, {5!r})'.format(
+                dbname, tname.encode('ascii', 'ignore').decode(),
+                col_pref, col_val, prefix, val)
+        )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove a record from mtree table')
 @cli.command('rm', short_help='Remove a record from mtree table')
 @click.option('coltprefix', '--coltprefix', default='tprefix',
 @click.option('coltprefix', '--coltprefix', default='tprefix',
-            help='Column name for prefix (default: "tprefix")')
+              help='Column name for prefix (default: "tprefix")')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('tprefix', metavar='<tprefix>')
 @click.argument('tprefix', metavar='<tprefix>')
 @pass_context
 @pass_context
@@ -66,20 +70,22 @@ def mtree_rm(ctx, coltprefix, dbtname, tprefix):
         <tprefix> - tree prefix value to match the record
         <tprefix> - tree prefix value to match the record
     """
     """
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('delete from {0!r} where {1!r}={2!r}'.format(dbtname.encode('ascii','ignore').decode(), coltprefix.encode('ascii','ignore').decode(), tprefix.encode('ascii','ignore').decode()))
+    e.execute(
+        'delete from {0!r} where {1!r}={2!r}'.format(
+            dbtname.encode('ascii', 'ignore').decode(),
+            coltprefix.encode('ascii', 'ignore').decode(),
+            tprefix.encode('ascii', 'ignore').decode())
+    )
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show mtree records in database')
 @cli.command('showdb', short_help='Show mtree records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.option('coltprefix', '--coltprefix', default='tprefix',
 @click.option('coltprefix', '--coltprefix', default='tprefix',
-            help='Column name for prefix (default: "tprefix")')
+              help='Column name for prefix (default: "tprefix")')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('dbtname', metavar='<dbtname>')
 @click.argument('tprefix', nargs=-1, metavar='[<tprefix>]')
 @click.argument('tprefix', nargs=-1, metavar='[<tprefix>]')
 @pass_context
 @pass_context
@@ -94,16 +100,19 @@ def mtree_showdb(ctx, oformat, ostyle, coltprefix, dbtname, tprefix):
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     if not tprefix:
     if not tprefix:
         ctx.vlog('Showing all tree database records')
         ctx.vlog('Showing all tree database records')
-        res = e.execute('select * from {0!r}'.format(dbtname.encode('ascii','ignore')))
+        res = e.execute(
+            'select * from {0!r}'.format(dbtname.encode('ascii', 'ignore')))
     else:
     else:
         ctx.vlog('Showing tree database records for prefix')
         ctx.vlog('Showing tree database records for prefix')
-        res = e.execute('select * from {0!r} where {1!r}={2!r}'.format(dbtname.encode('ascii','ignore').decode(), coltprefix.encode('ascii','ignore').decode(), tprefix.encode('ascii','ignore').decode()))
+        res = e.execute(
+            'select * from {0!r} where {1!r}={2!r}'.format(
+                dbtname.encode('ascii', 'ignore').decode(),
+                coltprefix.encode('ascii', 'ignore').decode(),
+                tprefix.encode('ascii', 'ignore').decode())
+        )
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='Show the records in memory tree')
 @cli.command('list', short_help='Show the records in memory tree')
 @click.argument('tname', metavar='<tname>')
 @click.argument('tname', metavar='<tname>')
 @pass_context
 @pass_context
@@ -114,13 +123,12 @@ def mtree_show(ctx, tname):
     Parameters:
     Parameters:
         <tname> - tree name
         <tname> - tree name
     """
     """
-    command_ctl(ctx, 'mtree.list', [ tname ])
+    command_ctl(ctx, 'mtree.list', [tname])
 
 
 
 
-##
-#
-#
[email protected]('reload', short_help='Reload tree records from database into memory')
[email protected](
+    'reload', short_help='Reload tree records from database into memory'
+)
 @click.argument('tname', metavar='<tname>')
 @click.argument('tname', metavar='<tname>')
 @pass_context
 @pass_context
 def mtree_reload(ctx, tname):
 def mtree_reload(ctx, tname):
@@ -130,5 +138,4 @@ def mtree_reload(ctx, tname):
     Parameters:
     Parameters:
         <tname> - tree name
         <tname> - tree name
     """
     """
-    command_ctl(ctx, 'mtree.reload', [ tname ])
-
+    command_ctl(ctx, 'mtree.reload', [tname])

+ 0 - 6
kamcli/commands/cmd_ps.py

@@ -1,13 +1,9 @@
-import sys
 import click
 import click
 import json
 import json
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.command('ps', short_help='Print the list of kamailio processes')
 @click.command('ps', short_help='Print the list of kamailio processes')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
@@ -18,9 +14,7 @@ def cli(ctx):
     command_ctl(ctx, 'core.psx', [], {"func": cmd_ps_result_print})
     command_ctl(ctx, 'core.psx', [], {"func": cmd_ps_result_print})
 
 
 
 
-##
 # callback to print the result of the rpc command
 # callback to print the result of the rpc command
-#
 def cmd_ps_result_print(ctx, response, params=None):
 def cmd_ps_result_print(ctx, response, params=None):
     ctx.vlog("formatting the response for command ps")
     ctx.vlog("formatting the response for command ps")
     rdata = json.loads(response)
     rdata = json.loads(response)

+ 2 - 6
kamcli/commands/cmd_rpcmethods.py

@@ -1,14 +1,10 @@
-import os
-import time
 import click
 import click
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
[email protected]('rpcmethods', short_help='Print the list of available raw RPC methods')
[email protected](
+    'rpcmethods', short_help='Print the list of available raw RPC methods')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     """Print the list of available raw RPC methods
     """Print the list of available raw RPC methods

+ 10 - 23
kamcli/commands/cmd_rtpengine.py

@@ -1,31 +1,22 @@
 import click
 import click
-import hashlib
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
-from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('rtpengine', help='Manage rtpengine module')
 @click.group('rtpengine', help='Manage rtpengine module')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show the rtpengine records in database')
 @cli.command('showdb', short_help='Show the rtpengine records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @pass_context
 @pass_context
 def rtpengine_showdb(ctx, oformat, ostyle):
 def rtpengine_showdb(ctx, oformat, ostyle):
     """Show the rtpengine records in database table
     """Show the rtpengine records in database table
@@ -40,9 +31,6 @@ def rtpengine_showdb(ctx, oformat, ostyle):
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show the rtpengine records in memory')
 @cli.command('show', short_help='Show the rtpengine records in memory')
 @pass_context
 @pass_context
 def rtpengine_show(ctx):
 def rtpengine_show(ctx):
@@ -52,20 +40,19 @@ def rtpengine_show(ctx):
     Parameters:
     Parameters:
         none
         none
     """
     """
-    command_ctl(ctx, 'rtpengine.show', [ 'all' ])
+    command_ctl(ctx, 'rtpengine.show', ['all'])
 
 
 
 
-##
-#
-#
-@cli.command('reload', short_help='Reload the rtpengine records from database into memory')
+@cli.command(
+    'reload',
+    short_help='Reload the rtpengine records from database into memory'
+)
 @pass_context
 @pass_context
 def rtpengine_reload(ctx):
 def rtpengine_reload(ctx):
     """Reload the rtpengine records from database into memory
     """Reload the rtpengine records from database into memory
 
 
     \b
     \b
     Parameters:
     Parameters:
-        none 
+        none
     """
     """
-    command_ctl(ctx, 'rtpengine.reload', [ ])
-
+    command_ctl(ctx, 'rtpengine.reload', [])

+ 47 - 38
kamcli/commands/cmd_speeddial.py

@@ -5,21 +5,15 @@ from kamcli.cli import pass_context
 from kamcli.cli import parse_user_spec
 from kamcli.cli import parse_user_spec
 
 
 
 
-##
-#
-#
 @click.group('speeddial', help='Manage speed dial records')
 @click.group('speeddial', help='Manage speed dial records')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a speed dial record')
 @cli.command('add', short_help='Add a speed dial record')
 @click.option('table', '--table', default='speed_dial',
 @click.option('table', '--table', default='speed_dial',
-            help='Name of database table (default: speed_dial)')
+              help='Name of database table (default: speed_dial)')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('shortdial', metavar='<shortdial>')
 @click.argument('shortdial', metavar='<shortdial>')
 @click.argument('targeturi', metavar='<targeturi>')
 @click.argument('targeturi', metavar='<targeturi>')
@@ -39,26 +33,30 @@ def speeddial_add(ctx, table, userid, shortdial, targeturi, desc):
     sdata = parse_user_spec(ctx, shortdial)
     sdata = parse_user_spec(ctx, shortdial)
     tdata = parse_user_spec(ctx, targeturi)
     tdata = parse_user_spec(ctx, targeturi)
     ctx.vlog('Adding for user [%s@%s] short dial [%s@%s] target [sip:%s@%s]',
     ctx.vlog('Adding for user [%s@%s] short dial [%s@%s] target [sip:%s@%s]',
-            udata['username'], udata['domain'],
-            sdata['username'], sdata['domain'],
-            tdata['username'], tdata['domain'])
+             udata['username'], udata['domain'],
+             sdata['username'], sdata['domain'],
+             tdata['username'], tdata['domain'])
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
+    uri = 'sip:{}@{}'.format(tdata['username'], tdata['domain'])
     if not desc:
     if not desc:
-        e.execute('insert into ' + table + ' (username, domain, sd_username, sd_domain, new_uri) values (%s, %s, %s, %s, %s)',
-                udata['username'], udata['domain'], sdata['username'], sdata['domain'],
-                'sip:' + tdata['username'] + '@' + tdata['domain'])
+        e.execute(
+            'insert into ' + table + ' %s (username, domain, sd_username, '
+            'sd_domain, new_uri) values (%s, %s, %s, %s, %s)',
+            udata['username'], udata['domain'],
+            sdata['username'], sdata['domain'], uri
+        )
     else:
     else:
-        e.execute('insert into ' + table + ' (username, domain, sd_username, sd_domain, new_uri, description) values (%s, %s, %s, %s, %s, %s)',
-                udata['username'], udata['domain'], sdata['username'], sdata['domain'],
-                'sip:' + tdata['username'] + '@' + tdata['domain'], desc)
+        e.execute(
+            'insert into ' + table + ' (username, domain, sd_username, '
+            'sd_domain, new_uri, description) values (%s, %s, %s, %s, %s, %s)',
+            udata['username'], udata['domain'],
+            sdata['username'], sdata['domain'], uri, desc
+        )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove speed dial records')
 @cli.command('rm', short_help='Remove speed dial records')
 @click.option('table', '--table', default='speed_dial',
 @click.option('table', '--table', default='speed_dial',
-            help='Name of database table (default: speed_dial)')
+              help='Name of database table (default: speed_dial)')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('shortdial', metavar='<shortdial>', nargs=-1)
 @click.argument('shortdial', metavar='<shortdial>', nargs=-1)
 @pass_context
 @pass_context
@@ -71,29 +69,33 @@ def speeddial_rm(ctx, table, userid, shortdial):
         <shortdial> - username, AoR or SIP URI for short dial
         <shortdial> - username, AoR or SIP URI for short dial
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Removing speed dial for record [%s@%s]', udata['username'], udata['domain'])
+    ctx.log(
+        'Removing speed dial for record [%s@%s]',
+        udata['username'], udata['domain']
+    )
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     if not shortdial:
     if not shortdial:
         e.execute('delete from ' + table + ' where username=%s and domain=%s',
         e.execute('delete from ' + table + ' where username=%s and domain=%s',
-                    udata['username'], udata['domain'])
+                  udata['username'], udata['domain'])
     else:
     else:
         for s in shortdial:
         for s in shortdial:
             sdata = parse_user_spec(ctx, s)
             sdata = parse_user_spec(ctx, s)
-            e.execute('delete from ' + table + ' where username=%s and domain=%s and sd_username=%s and sd_domain=%s',
-                    udata['username'], udata['domain'], sdata['username'], sdata['domain'])
+            e.execute(
+                'delete from ' + table + ' where username=%s and domain=%s '
+                'and sd_username=%s and sd_domain=%s',
+                udata['username'], udata['domain'],
+                sdata['username'], sdata['domain']
+            )
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show speed dial records')
 @cli.command('show', short_help='Show speed dial records')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.option('table', '--table', default='speed_dial',
 @click.option('table', '--table', default='speed_dial',
-            help='Name of database table (default: speed_dial)')
+              help='Name of database table (default: speed_dial)')
 @click.argument('userid', metavar='[<userid>]')
 @click.argument('userid', metavar='[<userid>]')
 @click.argument('shortdial', nargs=-1, metavar='[<shortdial>]')
 @click.argument('shortdial', nargs=-1, metavar='[<shortdial>]')
 @pass_context
 @pass_context
@@ -108,16 +110,23 @@ def speeddial_show(ctx, oformat, ostyle, table, userid, shortdial):
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
 
 
-    ctx.vlog('Showing speed dial records for user [%s@%s]', udata['username'], udata['domain'])
+    ctx.vlog(
+        'Showing speed dial records for user [%s@%s]',
+        udata['username'], udata['domain']
+    )
     if not shortdial:
     if not shortdial:
-        res = e.execute('select * from ' + table + ' where username=%s and domain=%s',
-                udata['username'], udata['domain'])
+        res = e.execute(
+            'select * from ' + table + ' where username=%s and domain=%s',
+            udata['username'], udata['domain']
+        )
         ioutils_dbres_print(ctx, oformat, ostyle, res)
         ioutils_dbres_print(ctx, oformat, ostyle, res)
     else:
     else:
         for s in shortdial:
         for s in shortdial:
             sdata = parse_user_spec(ctx, s)
             sdata = parse_user_spec(ctx, s)
-            res = e.execute('select * from ' + table + ' where username=%s and domain=%s and sd_username=%s and sd_domain=%s',
-                    udata['username'], udata['domain'], sdata['username'], sdata['domain'])
+            res = e.execute(
+                'select * from ' + table + ' where username=%s and domain=%s '
+                'and sd_username=%s and sd_domain=%s',
+                udata['username'], udata['domain'],
+                sdata['username'], sdata['domain']
+            )
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
-
-

+ 8 - 25
kamcli/commands/cmd_srv.py

@@ -3,17 +3,12 @@ from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('srv', help='Common server interaction commands')
 @click.group('srv', help='Common server interaction commands')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
-##
-#
-#
+
 @cli.command('sockets', short_help='Show the list of listen sockets')
 @cli.command('sockets', short_help='Show the list of listen sockets')
 @pass_context
 @pass_context
 def srv_sockets(ctx):
 def srv_sockets(ctx):
@@ -23,9 +18,7 @@ def srv_sockets(ctx):
     """
     """
     command_ctl(ctx, 'corex.list_sockets')
     command_ctl(ctx, 'corex.list_sockets')
 
 
-##
-#
-#
+
 @cli.command('aliases', short_help='Show the list of server domain aliases')
 @cli.command('aliases', short_help='Show the list of server domain aliases')
 @pass_context
 @pass_context
 def srv_aliases(ctx):
 def srv_aliases(ctx):
@@ -35,9 +28,7 @@ def srv_aliases(ctx):
     """
     """
     command_ctl(ctx, 'corex.list_aliases')
     command_ctl(ctx, 'corex.list_aliases')
 
 
-##
-#
-#
+
 @cli.command('rpclist', short_help='Show the list of server rpc commands')
 @cli.command('rpclist', short_help='Show the list of server rpc commands')
 @pass_context
 @pass_context
 def srv_rpclist(ctx):
 def srv_rpclist(ctx):
@@ -47,9 +38,7 @@ def srv_rpclist(ctx):
     """
     """
     command_ctl(ctx, 'system.listMethods')
     command_ctl(ctx, 'system.listMethods')
 
 
-##
-#
-#
+
 @cli.command('info', short_help='Show server info')
 @cli.command('info', short_help='Show server info')
 @pass_context
 @pass_context
 def srv_info(ctx):
 def srv_info(ctx):
@@ -59,9 +48,7 @@ def srv_info(ctx):
     """
     """
     command_ctl(ctx, 'core.info')
     command_ctl(ctx, 'core.info')
 
 
-##
-#
-#
+
 @cli.command('modules', short_help='Show server loaded modules')
 @cli.command('modules', short_help='Show server loaded modules')
 @pass_context
 @pass_context
 def srv_modules(ctx):
 def srv_modules(ctx):
@@ -71,9 +58,7 @@ def srv_modules(ctx):
     """
     """
     command_ctl(ctx, 'core.modules')
     command_ctl(ctx, 'core.modules')
 
 
-##
-#
-#
+
 @cli.command('version', short_help='Show server version')
 @cli.command('version', short_help='Show server version')
 @pass_context
 @pass_context
 def srv_version(ctx):
 def srv_version(ctx):
@@ -83,12 +68,10 @@ def srv_version(ctx):
     """
     """
     command_ctl(ctx, 'core.version')
     command_ctl(ctx, 'core.version')
 
 
-##
-#
-#
+
 @cli.command('ppdefines', short_help='Show pre-processor defines')
 @cli.command('ppdefines', short_help='Show pre-processor defines')
 @click.option('full', '--full', is_flag=True,
 @click.option('full', '--full', is_flag=True,
-            help='Show full format of the records.')
+              help='Show full format of the records.')
 @pass_context
 @pass_context
 def srv_ppdefines(ctx, full):
 def srv_ppdefines(ctx, full):
     """Show pre-processor defines
     """Show pre-processor defines

+ 8 - 8
kamcli/commands/cmd_stats.py

@@ -5,7 +5,8 @@ from kamcli.iorpc import command_ctl
 
 
 @click.command('stats', short_help='Print internal statistics')
 @click.command('stats', short_help='Print internal statistics')
 @click.option('single', '--single', '-s', is_flag=True,
 @click.option('single', '--single', '-s', is_flag=True,
-            help='The name belong to one statistic (otherwise the name is for a group)')
+              help='The name belong to one statistic (otherwise the name is '
+              'for a group)')
 @click.argument('names', nargs=-1, metavar='[<name>]')
 @click.argument('names', nargs=-1, metavar='[<name>]')
 @pass_context
 @pass_context
 def cli(ctx, single, names):
 def cli(ctx, single, names):
@@ -21,17 +22,16 @@ def cli(ctx, single, names):
         for n in names:
         for n in names:
             if n.endswith(":"):
             if n.endswith(":"):
                 # enforce group name by ending with ':'
                 # enforce group name by ending with ':'
-                command_ctl(ctx, 'stats.get_statistics', [ n ])
-            elif n.find(":")>0:
+                command_ctl(ctx, 'stats.get_statistics', [n])
+            elif n.find(":") > 0:
                 # get only stat name, when providing 'group:stat'
                 # get only stat name, when providing 'group:stat'
-                command_ctl(ctx, 'stats.get_statistics', [ n.split(":")[1] ])
+                command_ctl(ctx, 'stats.get_statistics', [n.split(":")[1]])
             elif single:
             elif single:
                 # single stat name flag
                 # single stat name flag
-                command_ctl(ctx, 'stats.get_statistics', [ n ])
+                command_ctl(ctx, 'stats.get_statistics', [n])
             else:
             else:
                 # default is group name
                 # default is group name
-                command_ctl(ctx, 'stats.get_statistics', [ n+":" ])
+                command_ctl(ctx, 'stats.get_statistics', [n + ":"])
     else:
     else:
         # no name, print all
         # no name, print all
-        command_ctl(ctx, 'stats.get_statistics', [ 'all' ])
-
+        command_ctl(ctx, 'stats.get_statistics', ['all'])

+ 98 - 63
kamcli/commands/cmd_subscriber.py

@@ -1,28 +1,21 @@
 import click
 import click
 import hashlib
 import hashlib
-import json
 from sqlalchemy import create_engine
 from sqlalchemy import create_engine
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.cli import parse_user_spec
 from kamcli.cli import parse_user_spec
 
 
 
 
-##
-#
-#
 @click.group('subscriber', help='Manage the subscribers')
 @click.group('subscriber', help='Manage the subscribers')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new subscriber')
 @cli.command('add', short_help='Add a new subscriber')
 @click.option('pwtext', '--text-password', '-t',
 @click.option('pwtext', '--text-password', '-t',
-                type=click.Choice(['yes', 'no']),
-                default='yes', help='Store password in clear text (default yes)')
+              type=click.Choice(['yes', 'no']),
+              default='yes', help='Store password in clear text (default yes)')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('password', metavar='<password>')
 @click.argument('password', metavar='<password>')
 @pass_context
 @pass_context
@@ -35,19 +28,28 @@ def subscriber_add(ctx, pwtext, userid, password):
         <password> - the password
         <password> - the password
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.vlog('Adding subscriber [%s] in domain [%s] with password [%s]', udata['username'], udata['domain'], password)
-    ha1 = hashlib.md5((udata['username'] + ":" + udata['domain'] + ":" + password).encode()).hexdigest()
-    ha1b = hashlib.md5((udata['username'] + "@" + udata['domain'] + ":" + udata['domain'] + ":" + password).encode()).hexdigest()
+    ctx.vlog('Adding subscriber [%s] in domain [%s] with password [%s]',
+             udata['username'], udata['domain'], password)
+    dig = '{}:{}:{}'.format(udata['username'], udata['domain'], password)
+    ha1 = hashlib.md5(dig.encode()).hexdigest()
+    dig = '{}@{}:{}:{}'.format(
+        udata['username'], udata['domain'], udata['domain'], password)
+    ha1b = hashlib.md5(dig.encode()).hexdigest()
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    if pwtext == 'yes' :
-        e.execute('insert into subscriber (username, domain, password, ha1, ha1b) values (%s, %s, %s, %s, %s)', udata['username'], udata['domain'], password, ha1, ha1b)
+    if pwtext == 'yes':
+        e.execute(
+            'insert into subscriber (username, domain, password, ha1, ha1b) '
+            'values (%s, %s, %s, %s, %s)',
+            udata['username'], udata['domain'], password, ha1, ha1b
+        )
     else:
     else:
-        e.execute('insert into subscriber (username, domain, ha1, ha1b) values (%s, %s, %s, %s)', udata['username'], udata['domain'], ha1, ha1b)
+        e.execute(
+            'insert into subscriber (username, domain, ha1, ha1b) values '
+            '(%s, %s, %s, %s)',
+            udata['username'], udata['domain'], ha1, ha1b
+        )
 
 
 
 
-##
-#
-#
 @cli.command('rm', short_help='Remove an existing subscriber')
 @cli.command('rm', short_help='Remove an existing subscriber')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @pass_context
 @pass_context
@@ -61,14 +63,17 @@ def subscriber_rm(ctx, userid):
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
     ctx.log('Removing subscriber [%s@%s]', udata['username'], udata['domain'])
     ctx.log('Removing subscriber [%s@%s]', udata['username'], udata['domain'])
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('delete from subscriber where username=%s and domain=%s', udata['username'], udata['domain'])
+    e.execute('delete from subscriber where username=%s and domain=%s',
+              udata['username'], udata['domain'])
 
 
 
 
-##
-#
-#
 @cli.command('passwd', short_help='Update the password for a subscriber')
 @cli.command('passwd', short_help='Update the password for a subscriber')
[email protected]('pwtext', '--text-password', '-t', type=click.Choice(['yes', 'no']), default='yes', help='Store password in clear text (default yes)')
[email protected](
+    'pwtext', '--text-password', '-t',
+    type=click.Choice(['yes', 'no']),
+    default='yes',
+    help='Store password in clear text (default yes)'
+)
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('password', metavar='<password>')
 @click.argument('password', metavar='<password>')
 @pass_context
 @pass_context
@@ -81,25 +86,34 @@ def subscriber_passwd(ctx, pwtext, userid, password):
         <password> - the password
         <password> - the password
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Updating subscriber [%s@%s] with password [%s]', udata['username'], udata['domain'], password)
-    ha1 = hashlib.md5((udata['username'] + ":" + udata['domain'] + ":" + password).encode()).hexdigest()
-    ha1b = hashlib.md5((udata['username'] + "@" + udata['domain'] + ":" + udata['domain'] + ":" + password).encode()).hexdigest()
+    ctx.log('Updating subscriber [%s@%s] with password [%s]',
+            udata['username'], udata['domain'], password)
+    dig = '{}:{}:{}'.format(udata['username'], udata['domain'], password)
+    ha1 = hashlib.md5(dig.encode()).hexdigest()
+    dig = '{}@{}:{}:{}'.format(
+        udata['username'], udata['domain'], udata['domain'], password)
+    ha1b = hashlib.md5(dig.encode()).hexdigest()
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    if pwtext == 'yes' :
-        e.execute('update subscriber set password=%s, ha1=%s, ha1b=%s where username=%s and domain=%s', password, ha1, ha1b, udata['username'], udata['domain'])
+    if pwtext == 'yes':
+        e.execute(
+            'update subscriber set password=%s, ha1=%s, ha1b=%s where '
+            'username=%s and domain=%s',
+            password, ha1, ha1b, udata['username'], udata['domain']
+        )
     else:
     else:
-        e.execute('update subscriber set ha1=%s, ha1b=%s where username=%s and domain=%s', ha1, ha1b, udata['username'], udata['domain'])
+        e.execute(
+            'update subscriber set ha1=%s, ha1b=%s where '
+            'username=%s and domain=%s',
+            ha1, ha1b, udata['username'], udata['domain']
+        )
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show details for subscribers')
 @cli.command('show', short_help='Show details for subscribers')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @pass_context
 @pass_context
 def subscriber_show(ctx, oformat, ostyle, userid):
 def subscriber_show(ctx, oformat, ostyle, userid):
@@ -119,15 +133,16 @@ def subscriber_show(ctx, oformat, ostyle, userid):
     else:
     else:
         for u in userid:
         for u in userid:
             udata = parse_user_spec(ctx, u)
             udata = parse_user_spec(ctx, u)
-            ctx.vlog('Showing subscriber [%s@%s]', udata['username'], udata['domain'])
+            ctx.vlog('Showing subscriber [%s@%s]',
+                     udata['username'], udata['domain'])
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-            res = e.execute('select * from subscriber where username=%s and domain=%s', udata['username'], udata['domain'])
+            res = e.execute(
+                'select * from subscriber where username=%s and domain=%s',
+                udata['username'], udata['domain']
+            )
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-##
-#
-#
 @cli.command('setattrs', short_help='Set a string attribute for a subscriber')
 @cli.command('setattrs', short_help='Set a string attribute for a subscriber')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('attr', metavar='<attribute>')
 @click.argument('attr', metavar='<attribute>')
@@ -139,19 +154,26 @@ def subscriber_setattrs(ctx, userid, attr, val):
     \b
     \b
     Parameters:
     Parameters:
         <userid> - username, AoR or SIP URI for subscriber
         <userid> - username, AoR or SIP URI for subscriber
-        <attribute> - the name of the attribute (column name in subscriber table)
+        <attribute> - the name of the attribute (column name in
+                      subscriber table)
         <value> - the value to be set for the attribute
         <value> - the value to be set for the attribute
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Updating subscriber [%s@%s] with str attribute [%s]=[%s]', udata['username'], udata['domain'], attr, val)
+    ctx.log('Updating subscriber [%s@%s] with str attribute [%s]=[%s]',
+            udata['username'], udata['domain'], attr, val)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('update subscriber set {0}={1!r} where username={2!r} and domain={3!r}'.format(attr.encode('ascii','ignore').decode(), val.encode('ascii','ignore').decode(), udata['username'], udata['domain']))
-
-
-##
-#
-#
[email protected]('setattri', short_help='Set an integer attribute for a subscriber')
+    e.execute(
+        'update subscriber set {0}={1!r} where username={2!r} and '
+        'domain={3!r}'.format(
+            attr.encode('ascii', 'ignore').decode(),
+            val.encode('ascii', 'ignore').decode(),
+            udata['username'], udata['domain']
+        )
+    )
+
+
[email protected](
+    'setattri', short_help='Set an integer attribute for a subscriber')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('attr', metavar='<attribute>')
 @click.argument('attr', metavar='<attribute>')
 @click.argument('val', metavar='<value>')
 @click.argument('val', metavar='<value>')
@@ -162,19 +184,26 @@ def subscriber_setattri(ctx, userid, attr, val):
     \b
     \b
     Parameters:
     Parameters:
         <userid> - username, AoR or SIP URI for subscriber
         <userid> - username, AoR or SIP URI for subscriber
-        <attribute> - the name of the attribute (column name in subscriber table)
+        <attribute> - the name of the attribute (column name in
+                      subscriber table)
         <value> - the value to be set for the attribute
         <value> - the value to be set for the attribute
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Updating subscriber [%s@%s] with int attribute [%s]=[%s]', udata['username'], udata['domain'], attr, val)
+    ctx.log('Updating subscriber [%s@%s] with int attribute [%s]=[%s]',
+            udata['username'], udata['domain'], attr, val)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('update subscriber set {0}={1} where username={2!r} and domain={3!r}'.format(attr.encode('ascii','ignore').decode(), val.encode('ascii','ignore').decode(), udata['username'], udata['domain']))
-
-
-##
-#
-#
[email protected]('setattrnull', short_help='Set an attribute to NULL for a subscriber')
+    e.execute(
+        'update subscriber set {0}={1} where username={2!r} and '
+        'domain={3!r}'.format(
+            attr.encode('ascii', 'ignore').decode(),
+            val.encode('ascii', 'ignore').decode(),
+            udata['username'], udata['domain']
+        )
+    )
+
+
[email protected](
+    'setattrnull', short_help='Set an attribute to NULL for a subscriber')
 @click.argument('userid', metavar='<userid>')
 @click.argument('userid', metavar='<userid>')
 @click.argument('attr', metavar='<attribute>')
 @click.argument('attr', metavar='<attribute>')
 @pass_context
 @pass_context
@@ -184,11 +213,17 @@ def subscriber_setattrnull(ctx, userid, attr):
     \b
     \b
     Parameters:
     Parameters:
         <userid> - username, AoR or SIP URI for subscriber
         <userid> - username, AoR or SIP URI for subscriber
-        <attribute> - the name of the attribute (column name in subscriber table)
+        <attribute> - the name of the attribute (column name in
+                      subscriber table)
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
-    ctx.log('Updating subscriber [%s@%s] with attribute [%s]=NULL', udata['username'], udata['domain'], attr)
+    ctx.log('Updating subscriber [%s@%s] with attribute [%s]=NULL',
+            udata['username'], udata['domain'], attr)
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('update subscriber set {0}=NULL where username={1!r} and domain={2!r}'.format(attr.encode('ascii','ignore').decode(), udata['username'], udata['domain']))
-
-
+    e.execute(
+        'update subscriber set {0}=NULL where username={1!r} and '
+        'domain={2!r}'.format(
+            attr.encode('ascii', 'ignore').decode(),
+            udata['username'], udata['domain']
+        )
+    )

+ 3 - 15
kamcli/commands/cmd_tcp.py

@@ -3,18 +3,12 @@ from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('tcp', help='Manage TCP options and connections')
 @click.group('tcp', help='Manage TCP options and connections')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('options', short_help='Show details for TCP options in memory')
 @cli.command('options', short_help='Show details for TCP options in memory')
 @pass_context
 @pass_context
 def tcp_options(ctx):
 def tcp_options(ctx):
@@ -22,12 +16,9 @@ def tcp_options(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'core.tcp_options', [ ])
+    command_ctl(ctx, 'core.tcp_options', [])
 
 
 
 
-##
-#
-#
 @cli.command('list', short_help='List current TCP connections')
 @cli.command('list', short_help='List current TCP connections')
 @pass_context
 @pass_context
 def tcp_list(ctx):
 def tcp_list(ctx):
@@ -35,12 +26,9 @@ def tcp_list(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'core.tcp_list', [ ])
+    command_ctl(ctx, 'core.tcp_list', [])
 
 
 
 
-##
-#
-#
 @cli.command('info', short_help='Summary of TCP usage')
 @cli.command('info', short_help='Summary of TCP usage')
 @pass_context
 @pass_context
 def tcp_info(ctx):
 def tcp_info(ctx):
@@ -48,4 +36,4 @@ def tcp_info(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'core.tcp_info', [ ])
+    command_ctl(ctx, 'core.tcp_info', [])

+ 30 - 48
kamcli/commands/cmd_tls.py

@@ -7,24 +7,18 @@ from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('tls', help='Manage tls module')
 @click.group('tls', help='Manage tls module')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show TLS config records in database')
 @cli.command('showdb', short_help='Show TLS config records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @pass_context
 @pass_context
 def tls_showdb(ctx, oformat, ostyle):
 def tls_showdb(ctx, oformat, ostyle):
     """Show details for records in tlscfg table
     """Show details for records in tlscfg table
@@ -37,13 +31,13 @@ def tls_showdb(ctx, oformat, ostyle):
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-
-##
-#
-#
-@cli.command('cfgprint', short_help='Print TLS config generated from database records')
-@click.option('odir', '--odir', '-d',
-                default=None, help='Output directory path for certificates content')
+@cli.command(
+    'cfgprint', short_help='Print TLS config generated from database records')
+@click.option(
+    'odir', '--odir', '-d',
+    default=None,
+    help='Output directory path for certificates content'
+)
 @click.argument('cfgpath', nargs=-1, metavar='[<cfgpath>]', type=click.Path())
 @click.argument('cfgpath', nargs=-1, metavar='[<cfgpath>]', type=click.Path())
 @pass_context
 @pass_context
 def tls_cfgprint(ctx, odir, cfgpath):
 def tls_cfgprint(ctx, odir, cfgpath):
@@ -73,16 +67,18 @@ def tls_cfgprint(ctx, odir, cfgpath):
         if pcount > 0:
         if pcount > 0:
             print("\n")
             print("\n")
 
 
-        if ( row["profile_type"] and row["profile_type"].strip()
-                and row["profile_name"] and row["profile_name"].strip() ):
-            print("[{0:s}:{1:s}]".format(row["profile_type"],row["profile_name"]))
+        if row["profile_type"] and row["profile_type"].strip() \
+                and row["profile_name"] and row["profile_name"].strip():
+            print("[{0:s}:{1:s}]".format(
+                row["profile_type"], row["profile_name"]))
 
 
             if row["method"] and row["method"].strip():
             if row["method"] and row["method"].strip():
                 print("method={0:s}".format(row["method"]))
                 print("method={0:s}".format(row["method"]))
 
 
             print("verify_certificate={0:d}".format(row["verify_certificate"]))
             print("verify_certificate={0:d}".format(row["verify_certificate"]))
             print("verify_depth={0:d}".format(row["verify_depth"]))
             print("verify_depth={0:d}".format(row["verify_depth"]))
-            print("require_certificate={0:d}".format(row["require_certificate"]))
+            print("require_certificate={0:d}".format(
+                row["require_certificate"]))
 
 
             if row["file_type"] == 0:
             if row["file_type"] == 0:
                 if row["certificate"] and row["certificate"].strip():
                 if row["certificate"] and row["certificate"].strip():
@@ -98,28 +94,32 @@ def tls_cfgprint(ctx, odir, cfgpath):
                     print("crl={0:s}".format(row["crl"]))
                     print("crl={0:s}".format(row["crl"]))
             else:
             else:
                 if row["certificate"] and row["certificate"].strip():
                 if row["certificate"] and row["certificate"].strip():
-                    fpath = os.path.join(odir, "certificate_"+str(row["id"])+".pem")
+                    fpath = os.path.join(
+                        odir, "certificate_" + str(row["id"]) + ".pem")
                     fout = open(fpath, 'w')
                     fout = open(fpath, 'w')
                     fout.write(row["certificate"])
                     fout.write(row["certificate"])
                     fout.close()
                     fout.close()
                     print("certificate={0:s}".format(fpath))
                     print("certificate={0:s}".format(fpath))
 
 
                 if row["private_key"] and row["private_key"].strip():
                 if row["private_key"] and row["private_key"].strip():
-                    fpath = os.path.join(odir, "private_key_"+str(row["id"])+".pem")
+                    fpath = os.path.join(
+                        odir, "private_key_" + str(row["id"]) + ".pem")
                     fout = open(fpath, 'w')
                     fout = open(fpath, 'w')
                     fout.write(row["private_key"])
                     fout.write(row["private_key"])
                     fout.close()
                     fout.close()
                     print("private_key={0:s}".format(fpath))
                     print("private_key={0:s}".format(fpath))
 
 
                 if row["ca_list"] and row["ca_list"].strip():
                 if row["ca_list"] and row["ca_list"].strip():
-                    fpath = os.path.join(odir, "ca_list_"+str(row["id"])+".pem")
+                    fpath = os.path.join(
+                        odir, "ca_list_" + str(row["id"]) + ".pem")
                     fout = open(fpath, 'w')
                     fout = open(fpath, 'w')
                     fout.write(row["ca_list"])
                     fout.write(row["ca_list"])
                     fout.close()
                     fout.close()
                     print("ca_list={0:s}".format(fpath))
                     print("ca_list={0:s}".format(fpath))
 
 
                 if row["crl"] and row["crl"].strip():
                 if row["crl"] and row["crl"].strip():
-                    fpath = os.path.join(odir, "crl_"+str(row["id"])+".pem")
+                    fpath = os.path.join(
+                        odir, "crl_" + str(row["id"]) + ".pem")
                     fout = open(fpath, 'w')
                     fout = open(fpath, 'w')
                     fout.write(row["crl"])
                     fout.write(row["crl"])
                     fout.close()
                     fout.close()
@@ -143,10 +143,6 @@ def tls_cfgprint(ctx, odir, cfgpath):
         print("done")
         print("done")
 
 
 
 
-
-##
-#
-#
 @cli.command('cfgoptions', short_help='Show details for TLS options in memory')
 @cli.command('cfgoptions', short_help='Show details for TLS options in memory')
 @pass_context
 @pass_context
 def tls_cfgoptions(ctx):
 def tls_cfgoptions(ctx):
@@ -154,12 +150,9 @@ def tls_cfgoptions(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'tls.options', [ ])
+    command_ctl(ctx, 'tls.options', [])
 
 
 
 
-##
-#
-#
 @cli.command('cfgreload', short_help='Reload tls configuration file')
 @cli.command('cfgreload', short_help='Reload tls configuration file')
 @pass_context
 @pass_context
 def tls_cfgreload(ctx):
 def tls_cfgreload(ctx):
@@ -167,12 +160,9 @@ def tls_cfgreload(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'tls.reload', [ ])
+    command_ctl(ctx, 'tls.reload', [])
 
 
 
 
-##
-#
-#
 @cli.command('conlist', short_help='List current tls connections')
 @cli.command('conlist', short_help='List current tls connections')
 @pass_context
 @pass_context
 def tls_conlist(ctx):
 def tls_conlist(ctx):
@@ -180,13 +170,9 @@ def tls_conlist(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'tls.list', [ ])
-
+    command_ctl(ctx, 'tls.list', [])
 
 
 
 
-##
-#
-#
 @cli.command('info', short_help='Summary of tls usage')
 @cli.command('info', short_help='Summary of tls usage')
 @pass_context
 @pass_context
 def tls_info(ctx):
 def tls_info(ctx):
@@ -194,15 +180,11 @@ def tls_info(ctx):
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'tls.info', [ ])
-
-
+    command_ctl(ctx, 'tls.info', [])
 
 
 
 
-##
-#
-#
[email protected]('sqlprint', short_help='Print SQL statement to create the db table')
[email protected](
+    'sqlprint', short_help='Print SQL statement to create the db table')
 @pass_context
 @pass_context
 def tls_sqlprint(ctx):
 def tls_sqlprint(ctx):
     """Print SQL statement to create the db table
     """Print SQL statement to create the db table

+ 65 - 40
kamcli/commands/cmd_uacreg.py

@@ -4,29 +4,24 @@ from kamcli.ioutils import ioutils_dbres_print
 from kamcli.cli import pass_context
 from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
-##
-#
-#
+
 @click.group('uacreg', help='Manage uac remote registration')
 @click.group('uacreg', help='Manage uac remote registration')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add a new remote registration account')
 @cli.command('add', short_help='Add a new remote registration account')
 @click.option('realm', '--realm', default='',
 @click.option('realm', '--realm', default='',
-            help='Realm (default: "")')
+              help='Realm (default: "")')
 @click.option('authha1', '--auth-ha1', is_flag=True,
 @click.option('authha1', '--auth-ha1', is_flag=True,
-            help='Auth password in HA1 format')
+              help='Auth password in HA1 format')
 @click.option('flags', '--flags', type=int, default=0,
 @click.option('flags', '--flags', type=int, default=0,
-            help='Flags (default: 0)')
+              help='Flags (default: 0)')
 @click.option('regdelay', '--reg-delay', type=int, default=0,
 @click.option('regdelay', '--reg-delay', type=int, default=0,
-            help='Registration delay (default: 0)')
+              help='Registration delay (default: 0)')
 @click.option('socket', '--socket', default='',
 @click.option('socket', '--socket', default='',
-            help='Local socket (default: "")')
+              help='Local socket (default: "")')
 @click.argument('l_uuid', metavar='<l_uuid>')
 @click.argument('l_uuid', metavar='<l_uuid>')
 @click.argument('l_username', metavar='<l_username>')
 @click.argument('l_username', metavar='<l_username>')
 @click.argument('l_domain', metavar='<l_domain>')
 @click.argument('l_domain', metavar='<l_domain>')
@@ -37,9 +32,10 @@ def cli(ctx):
 @click.argument('auth_proxy', metavar='<auth_proxy>')
 @click.argument('auth_proxy', metavar='<auth_proxy>')
 @click.argument('expires', metavar='<expires>', type=int)
 @click.argument('expires', metavar='<expires>', type=int)
 @pass_context
 @pass_context
-def uacreg_add(ctx, realm, authha1, flags, regdelay, socket, l_uuid, l_username,
-            l_domain, r_username, r_domain, auth_username, auth_password,
-            auth_proxy, expires):
+def uacreg_add(
+        ctx, realm, authha1, flags, regdelay, socket, l_uuid,
+        l_username, l_domain, r_username, r_domain, auth_username,
+        auth_password, auth_proxy, expires):
     """Add a new uac remote registration account
     """Add a new uac remote registration account
 
 
     \b
     \b
@@ -54,7 +50,10 @@ def uacreg_add(ctx, realm, authha1, flags, regdelay, socket, l_uuid, l_username,
         <auth_proxy> - auth proxy (sip address)
         <auth_proxy> - auth proxy (sip address)
         <expires> - expires interval (int)
         <expires> - expires interval (int)
     """
     """
-    ctx.vlog('Adding a new uac remote registration account - local uuid: [%s]', l_uuid)
+    ctx.vlog(
+        'Adding a new uac remote registration account - local uuid: [%s]',
+        l_uuid
+    )
     pwval = ""
     pwval = ""
     ha1val = ""
     ha1val = ""
     if authha1:
     if authha1:
@@ -62,14 +61,33 @@ def uacreg_add(ctx, realm, authha1, flags, regdelay, socket, l_uuid, l_username,
     else:
     else:
         pwval = auth_password
         pwval = auth_password
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('insert into uacreg (l_uuid, l_username, l_domain, r_username, r_domain, realm, auth_username, auth_password, auth_ha1, auth_proxy, expires, flags, reg_delay, socket) values ({0!r}, {1!r}, {2!r}, {3!r}, {4!r}, {5!r}, {6!r}, {7!r}, {8!r}, {9!r}, {10}, {11}, {12}, {13!r})'.format(l_uuid.encode('ascii','ignore').decode(), l_username.encode('ascii','ignore').decode(), l_domain.encode('ascii','ignore').decode(), r_username.encode('ascii','ignore').decode(), r_domain.encode('ascii','ignore').decode(), realm.encode('ascii','ignore').decode(), auth_username.encode('ascii','ignore').decode(), pwval.encode('ascii','ignore').decode(), ha1val.encode('ascii','ignore').decode(), auth_proxy.encode('ascii','ignore').decode(), expires, flags, regdelay, socket.encode('ascii','ignore').decode()))
+    e.execute(
+        'insert into uacreg (l_uuid, l_username, l_domain, r_username, '
+        'r_domain, realm, auth_username, auth_password, auth_ha1, auth_proxy, '
+        'expires, flags, reg_delay, socket) values '
+        '({0!r}, {1!r}, {2!r}, {3!r}, '
+        '{4!r}, {5!r}, {6!r}, {7!r}, {8!r}, {9!r}, '
+        '{10}, {11}, {12}, {13!r})'.format(
+            l_uuid.encode('ascii', 'ignore').decode(),
+            l_username.encode('ascii', 'ignore').decode(),
+            l_domain.encode('ascii', 'ignore').decode(),
+            r_username.encode('ascii', 'ignore').decode(),
+            r_domain.encode('ascii', 'ignore').decode(),
+            realm.encode('ascii', 'ignore').decode(),
+            auth_username.encode('ascii', 'ignore').decode(),
+            pwval.encode('ascii', 'ignore').decode(),
+            ha1val.encode('ascii', 'ignore').decode(),
+            auth_proxy.encode('ascii', 'ignore').decode(),
+            expires, flags, regdelay,
+            socket.encode('ascii', 'ignore').decode()
+        )
+    )
+
 
 
-##
-#
-#
[email protected]('passwd', short_help='Set the password for a remote registration account')
[email protected](
+    'passwd', short_help='Set the password for a remote registration account')
 @click.option('authha1', '--auth-ha1', is_flag=True,
 @click.option('authha1', '--auth-ha1', is_flag=True,
-            help='Auth password in HA1 format')
+              help='Auth password in HA1 format')
 @click.argument('l_uuid', metavar='<l_uuid>')
 @click.argument('l_uuid', metavar='<l_uuid>')
 @click.argument('auth_password', metavar='<auth_password>')
 @click.argument('auth_password', metavar='<auth_password>')
 @pass_context
 @pass_context
@@ -81,7 +99,10 @@ def uacreg_passwd(ctx, realm, authha1, l_uuid, auth_password):
         <l_uuid> - local user unique id
         <l_uuid> - local user unique id
         <auth_password> - auth password
         <auth_password> - auth password
     """
     """
-    ctx.vlog('Adding a new uac remote registration account - local uuid: [%s]', l_uuid)
+    ctx.vlog(
+        'Adding a new uac remote registration account - local uuid: [%s]',
+        l_uuid
+    )
     pwval = ""
     pwval = ""
     ha1val = ""
     ha1val = ""
     if authha1:
     if authha1:
@@ -89,18 +110,22 @@ def uacreg_passwd(ctx, realm, authha1, l_uuid, auth_password):
     else:
     else:
         pwval = auth_password
         pwval = auth_password
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
     e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-    e.execute('update uacreg set auth_password={0!r}, auth_ha1={1!r} where l_uuid={2!r}'.format(pwval.encode('ascii','ignore').decode(), ha1val.encode('ascii','ignore').decode(), l_uuid.encode('ascii','ignore').decode(), ))
+    e.execute(
+        'update uacreg set auth_password={0!r}, auth_ha1={1!r} '
+        'where l_uuid={2!r}'.format(
+            pwval.encode('ascii', 'ignore').decode(),
+            ha1val.encode('ascii', 'ignore').decode(),
+            l_uuid.encode('ascii', 'ignore').decode(),
+        )
+    )
 
 
 
 
-##
-#
-#
 @cli.command('showdb', short_help='Show dialplan records in database')
 @cli.command('showdb', short_help='Show dialplan records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(['raw', 'json', 'table', 'dict']),
-                default=None, help='Format the output')
+              type=click.Choice(['raw', 'json', 'table', 'dict']),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('l_uuid', nargs=-1, metavar='[<l_uuid>]')
 @click.argument('l_uuid', nargs=-1, metavar='[<l_uuid>]')
 @pass_context
 @pass_context
 def dispatcher_showdb(ctx, oformat, ostyle, l_uuid):
 def dispatcher_showdb(ctx, oformat, ostyle, l_uuid):
@@ -121,26 +146,26 @@ def dispatcher_showdb(ctx, oformat, ostyle, l_uuid):
             res = e.execute('select * from uacreg where l_uuid="%s"', l)
             res = e.execute('select * from uacreg where l_uuid="%s"', l)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
-##
-#
-#
[email protected]('list', short_help='Show details for remote registration records in memory')
+
[email protected](
+    'list',
+    short_help='Show details for remote registration records in memory'
+)
 @pass_context
 @pass_context
 def uacreg_list(ctx):
 def uacreg_list(ctx):
     """Show details for remote registration records in memory
     """Show details for remote registration records in memory
 
 
     \b
     \b
     """
     """
-    command_ctl(ctx, 'uac.reg_dump', [ ])
+    command_ctl(ctx, 'uac.reg_dump', [])
 
 
 
 
-##
-#
-#
-@cli.command('reload', short_help='Reload remote registration records from database into memory')
+@cli.command(
+    'reload',
+    short_help='Reload remote registration records from database into memory'
+)
 @pass_context
 @pass_context
 def uacreg_reload(ctx):
 def uacreg_reload(ctx):
     """Reload remote registration records from database into memory
     """Reload remote registration records from database into memory
     """
     """
-    command_ctl(ctx, 'uac.reg_reload', [ ])
-
+    command_ctl(ctx, 'uac.reg_reload', [])

+ 35 - 46
kamcli/commands/cmd_ul.py

@@ -7,23 +7,17 @@ from kamcli.cli import parse_user_spec
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.group('ul', help='Manage user location records')
 @click.group('ul', help='Manage user location records')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):
     pass
     pass
 
 
 
 
-##
-#
-#
 @cli.command('show', short_help='Show details for location records in memory')
 @cli.command('show', short_help='Show details for location records in memory')
 @click.option('brief', '--brief', is_flag=True,
 @click.option('brief', '--brief', is_flag=True,
-            help='Show brief format of the records.')
+              help='Show brief format of the records.')
 @click.option('table', '--table', default='location',
 @click.option('table', '--table', default='location',
-            help='Name of location table (default: location)')
+              help='Name of location table (default: location)')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @pass_context
 @pass_context
 def ul_show(ctx, brief, table, userid):
 def ul_show(ctx, brief, table, userid):
@@ -38,39 +32,38 @@ def ul_show(ctx, brief, table, userid):
     if not userid:
     if not userid:
         ctx.vlog('Showing all records')
         ctx.vlog('Showing all records')
         if brief:
         if brief:
-            command_ctl(ctx, 'ul.dump', [ 'brief' ])
+            command_ctl(ctx, 'ul.dump', ['brief'])
         else:
         else:
-            command_ctl(ctx, 'ul.dump', [ ])
+            command_ctl(ctx, 'ul.dump', [])
     else:
     else:
         for u in userid:
         for u in userid:
             udata = parse_user_spec(ctx, u)
             udata = parse_user_spec(ctx, u)
-            ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain'])
-            aor =  udata['username'] + '@' + udata['domain']
-            command_ctl(ctx, 'ul.lookup', [ table, aor ])
+            ctx.vlog('Showing record for [%s@%s]',
+                     udata['username'], udata['domain'])
+            aor = udata['username'] + '@' + udata['domain']
+            command_ctl(ctx, 'ul.lookup', [table, aor])
 
 
 
 
-##
-#
-#
 @cli.command('add', short_help='Add location record')
 @cli.command('add', short_help='Add location record')
 @click.option('table', '--table', default='location',
 @click.option('table', '--table', default='location',
-            help='Name of location table (default: location)')
+              help='Name of location table (default: location)')
 @click.option('expires', '--expires', type=int, default=0,
 @click.option('expires', '--expires', type=int, default=0,
-            help='Expires value')
+              help='Expires value')
 @click.option('qval', '--q', type=float, default=1.0,
 @click.option('qval', '--q', type=float, default=1.0,
-            help='Q value')
+              help='Q value')
 @click.option('cpath', '--path', default='',
 @click.option('cpath', '--path', default='',
-            help='Path value')
+              help='Path value')
 @click.option('flags', '--flags', type=int, default=0,
 @click.option('flags', '--flags', type=int, default=0,
-            help='Flags value')
+              help='Flags value')
 @click.option('bflags', '--bflags', type=int, default=0,
 @click.option('bflags', '--bflags', type=int, default=0,
-            help='Branch flags value')
+              help='Branch flags value')
 @click.option('methods', '--methods', type=int, default=4294967295,
 @click.option('methods', '--methods', type=int, default=4294967295,
-            help='Methods value')
+              help='Methods value')
 @click.argument('userid', nargs=1, metavar='<userid>')
 @click.argument('userid', nargs=1, metavar='<userid>')
 @click.argument('curi', nargs=1, metavar='<contact-uri>')
 @click.argument('curi', nargs=1, metavar='<contact-uri>')
 @pass_context
 @pass_context
-def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods, userid, curi):
+def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods,
+           userid, curi):
     """Add location record
     """Add location record
 
 
     \b
     \b
@@ -80,17 +73,14 @@ def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods, userid, cur
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
     ctx.vlog('Adding record for [%s@%s]', udata['username'], udata['domain'])
     ctx.vlog('Adding record for [%s@%s]', udata['username'], udata['domain'])
-    aor =  udata['username'] + '@' + udata['domain']
-    command_ctl(ctx, 'ul.add', [ table, aor, curi, expires, qval, cpath, flags, bflags, methods ])
+    aor = udata['username'] + '@' + udata['domain']
+    command_ctl(ctx, 'ul.add', [table, aor, curi,
+                                expires, qval, cpath, flags, bflags, methods])
 
 
 
 
-
-##
-#
-#
 @cli.command('rm', short_help='Delete location records')
 @cli.command('rm', short_help='Delete location records')
 @click.option('table', '--table', default='location',
 @click.option('table', '--table', default='location',
-            help='Name of location table (default: location)')
+              help='Name of location table (default: location)')
 @click.argument('userid', nargs=1, metavar='<userid>')
 @click.argument('userid', nargs=1, metavar='<userid>')
 @click.argument('curi', nargs=-1, metavar='[<contact-uri>]')
 @click.argument('curi', nargs=-1, metavar='[<contact-uri>]')
 @pass_context
 @pass_context
@@ -105,24 +95,21 @@ def ul_rm(ctx, table, userid, curi):
     """
     """
     udata = parse_user_spec(ctx, userid)
     udata = parse_user_spec(ctx, userid)
     ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain'])
     ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain'])
-    aor =  udata['username'] + '@' + udata['domain']
+    aor = udata['username'] + '@' + udata['domain']
     if curi:
     if curi:
         for c in curi:
         for c in curi:
-            command_ctl(ctx, 'ul.rm', [ table, aor, c ])
+            command_ctl(ctx, 'ul.rm', [table, aor, c])
     else:
     else:
-        command_ctl(ctx, 'ul.rm', [ table, aor ])
-
+        command_ctl(ctx, 'ul.rm', [table, aor])
 
 
 
 
-##
-#
-#
[email protected]('showdb', short_help='Show details for location records in database')
[email protected](
+    'showdb', short_help='Show details for location records in database')
 @click.option('oformat', '--output-format', '-F',
 @click.option('oformat', '--output-format', '-F',
-                type=click.Choice(ioutils_formats_list),
-                default=None, help='Format the output')
+              type=click.Choice(ioutils_formats_list),
+              default=None, help='Format the output')
 @click.option('ostyle', '--output-style', '-S',
 @click.option('ostyle', '--output-style', '-S',
-                default=None, help='Style of the output (tabulate table format)')
+              default=None, help='Style of the output (tabulate table format)')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @click.argument('userid', nargs=-1, metavar='[<userid>]')
 @pass_context
 @pass_context
 def ul_showdb(ctx, oformat, ostyle, userid):
 def ul_showdb(ctx, oformat, ostyle, userid):
@@ -142,9 +129,11 @@ def ul_showdb(ctx, oformat, ostyle, userid):
     else:
     else:
         for u in userid:
         for u in userid:
             udata = parse_user_spec(ctx, u)
             udata = parse_user_spec(ctx, u)
-            ctx.vlog('Showing records for [%s@%s]', udata['username'], udata['domain'])
+            ctx.vlog('Showing records for [%s@%s]',
+                     udata['username'], udata['domain'])
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
             e = create_engine(ctx.gconfig.get('db', 'rwurl'))
-            res = e.execute('select * from location where username=%s and domain=%s', udata['username'], udata['domain'])
+            res = e.execute(
+                'select * from location where username=%s and domain=%s',
+                udata['username'], udata['domain']
+            )
             ioutils_dbres_print(ctx, oformat, ostyle, res)
             ioutils_dbres_print(ctx, oformat, ostyle, res)
-
-

+ 0 - 3
kamcli/commands/cmd_uptime.py

@@ -3,9 +3,6 @@ from kamcli.cli import pass_context
 from kamcli.iorpc import command_ctl
 from kamcli.iorpc import command_ctl
 
 
 
 
-##
-#
-#
 @click.command('uptime', short_help='Print the uptime for kamailio')
 @click.command('uptime', short_help='Print the uptime for kamailio')
 @pass_context
 @pass_context
 def cli(ctx):
 def cli(ctx):