[Asterisk-code-review] contrib/sip to pjsip: add a --quiet option to avoid prints (asterisk[16])
Joshua Colp
asteriskteam at digium.com
Mon Nov 5 04:59:11 CST 2018
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10546 )
Change subject: contrib/sip_to_pjsip: add a --quiet option to avoid prints
......................................................................
contrib/sip_to_pjsip: add a --quiet option to avoid prints
Using the --quiet or -q option in conjonction with /dev/stdout as the output
file allow the output to be used as a valid configuration.
Given a script that generates a valid sip.conf I can pipe the output of that
script into `sip_to_pjsip.py -q /dev/stdin /dev/stdout`. This allow me to use
that piped command in my pjsip.conf using the `exec` command.
ASTERISK-28136
Change-Id: I7b0e2e90e2549f3f8e01dc96701f111b5874c88d
---
M contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
1 file changed, 24 insertions(+), 8 deletions(-)
Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Joshua Colp: Approved for Submit
diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
index 1860a31..fc32d91 100755
--- a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
+++ b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
@@ -1,5 +1,8 @@
#!/usr/bin/env python
+from __future__ import print_function
+
+import sys
import optparse
import socket
try:
@@ -10,6 +13,7 @@
import astconfigparser
PREFIX = 'pjsip_'
+QUIET = False
###############################################################################
### some utility functions
@@ -106,7 +110,7 @@
else:
merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
except LookupError:
- print("lookup error")
+ print("lookup error", file=sys.stderr)
merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
return
elif key == 'disallow':
@@ -850,7 +854,7 @@
' this was just for outbound client connections. In' \
' chan_pjsip, this value is for client and server. Instead,' \
' consider not to specify \'tlsclientmethod\' for chan_sip' \
- ' and \'method = sslv23\' for chan_pjsip.')
+ ' and \'method = sslv23\' for chan_pjsip.', file=sys.stderr)
except LookupError:
"""
OpenSSL emerged during the 90s. SSLv2 and SSLv3 were the only
@@ -1267,7 +1271,7 @@
pjsip.write(fp)
except IOError:
- print("Could not open file " + filename + " for writing")
+ print("Could not open file " + filename + " for writing", file=sys.stderr)
###############################################################################
@@ -1278,6 +1282,7 @@
print usage information
"""
global PREFIX
+ global QUIET
usage = "usage: %prog [options] [input-file [output-file]]\n\n" \
"Converts the chan_sip configuration input-file to the chan_pjsip output-file.\n" \
"The input-file defaults to 'sip.conf'.\n" \
@@ -1285,24 +1290,35 @@
parser = optparse.OptionParser(usage=usage)
parser.add_option('-p', '--prefix', dest='prefix', default=PREFIX,
help='output prefix for include files')
+ parser.add_option('-q', '--quiet', dest='quiet', default=False, action='store_true',
+ help="don't print messages to stdout")
options, args = parser.parse_args()
PREFIX = options.prefix
+ if options.quiet:
+ QUIET = True
sip_filename = args[0] if len(args) else 'sip.conf'
pjsip_filename = args[1] if len(args) == 2 else 'pjsip.conf'
return sip_filename, pjsip_filename
+
+def info(msg):
+ if QUIET:
+ return
+ print(msg)
+
+
if __name__ == "__main__":
sip_filename, pjsip_filename = cli_options()
# configuration parser for sip.conf
sip = astconfigparser.MultiOrderedConfigParser()
- print('Please, report any issue at:')
- print(' https://issues.asterisk.org/')
- print('Reading ' + sip_filename)
+ info('Please, report any issue at:')
+ info(' https://issues.asterisk.org/')
+ info('Reading ' + sip_filename)
sip.read(sip_filename)
- print('Converting to PJSIP...')
+ info('Converting to PJSIP...')
pjsip, non_mappings = convert(sip, pjsip_filename, dict(), False)
- print('Writing ' + pjsip_filename)
+ info('Writing ' + pjsip_filename)
write_pjsip(pjsip_filename, pjsip, non_mappings)
--
To view, visit https://gerrit.asterisk.org/10546
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b0e2e90e2549f3f8e01dc96701f111b5874c88d
Gerrit-Change-Number: 10546
Gerrit-PatchSet: 4
Gerrit-Owner: Pascal Cadotte Michaud <pcm at wazo.io>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Pascal Cadotte Michaud <pcm at wazo.io>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181105/d7427532/attachment-0001.html>
More information about the asterisk-code-review
mailing list