<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10566">View Change</a></p><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">contrib/sip_to_pjsip: add a --quiet option to avoid prints<br><br>Using the --quiet or -q option in conjonction with /dev/stdout as the output<br>file allow the output to be used as a valid configuration.<br><br>Given a script that generates a valid sip.conf I can pipe the output of that<br>script into `sip_to_pjsip.py -q /dev/stdin /dev/stdout`. This allow me to use<br>that piped command in my pjsip.conf using the `exec` command.<br><br>ASTERISK-28136<br><br>Change-Id: I7b0e2e90e2549f3f8e01dc96701f111b5874c88d<br>---<br>M contrib/scripts/sip_to_pjsip/sip_to_pjsip.py<br>1 file changed, 24 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>index 1860a31..fc32d91 100755</span><br><span>--- a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>+++ b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py</span><br><span>@@ -1,5 +1,8 @@</span><br><span> #!/usr/bin/env python</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+from __future__ import print_function</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span> import optparse</span><br><span> import socket</span><br><span> try:</span><br><span>@@ -10,6 +13,7 @@</span><br><span> import astconfigparser</span><br><span> </span><br><span> PREFIX = 'pjsip_'</span><br><span style="color: hsl(120, 100%, 40%);">+QUIET = False</span><br><span> </span><br><span> ###############################################################################</span><br><span> ### some utility functions</span><br><span>@@ -106,7 +110,7 @@</span><br><span>             else:</span><br><span>                 merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)</span><br><span>         except LookupError:</span><br><span style="color: hsl(0, 100%, 40%);">-            print("lookup error")</span><br><span style="color: hsl(120, 100%, 40%);">+            print("lookup error", file=sys.stderr)</span><br><span>             merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)</span><br><span>             return</span><br><span>     elif key == 'disallow':</span><br><span>@@ -850,7 +854,7 @@</span><br><span>                   ' this was just for outbound client connections. In' \</span><br><span>                   ' chan_pjsip, this value is for client and server. Instead,' \</span><br><span>                   ' consider not to specify \'tlsclientmethod\' for chan_sip' \</span><br><span style="color: hsl(0, 100%, 40%);">-                  ' and \'method = sslv23\' for chan_pjsip.')</span><br><span style="color: hsl(120, 100%, 40%);">+                  ' and \'method = sslv23\' for chan_pjsip.', file=sys.stderr)</span><br><span>     except LookupError:</span><br><span>         """</span><br><span>         OpenSSL emerged during the 90s. SSLv2 and SSLv3 were the only</span><br><span>@@ -1267,7 +1271,7 @@</span><br><span>             pjsip.write(fp)</span><br><span> </span><br><span>     except IOError:</span><br><span style="color: hsl(0, 100%, 40%);">-        print("Could not open file " + filename + " for writing")</span><br><span style="color: hsl(120, 100%, 40%);">+        print("Could not open file " + filename + " for writing", file=sys.stderr)</span><br><span> </span><br><span> ###############################################################################</span><br><span> </span><br><span>@@ -1278,6 +1282,7 @@</span><br><span>     print usage information</span><br><span>     """</span><br><span>     global PREFIX</span><br><span style="color: hsl(120, 100%, 40%);">+    global QUIET</span><br><span>     usage = "usage: %prog [options] [input-file [output-file]]\n\n" \</span><br><span>         "Converts the chan_sip configuration input-file to the chan_pjsip output-file.\n" \</span><br><span>         "The input-file defaults to 'sip.conf'.\n" \</span><br><span>@@ -1285,24 +1290,35 @@</span><br><span>     parser = optparse.OptionParser(usage=usage)</span><br><span>     parser.add_option('-p', '--prefix', dest='prefix', default=PREFIX,</span><br><span>                       help='output prefix for include files')</span><br><span style="color: hsl(120, 100%, 40%);">+    parser.add_option('-q', '--quiet', dest='quiet', default=False, action='store_true',</span><br><span style="color: hsl(120, 100%, 40%);">+                      help="don't print messages to stdout")</span><br><span> </span><br><span>     options, args = parser.parse_args()</span><br><span>     PREFIX = options.prefix</span><br><span style="color: hsl(120, 100%, 40%);">+    if options.quiet:</span><br><span style="color: hsl(120, 100%, 40%);">+        QUIET = True</span><br><span> </span><br><span>     sip_filename = args[0] if len(args) else 'sip.conf'</span><br><span>     pjsip_filename = args[1] if len(args) == 2 else 'pjsip.conf'</span><br><span> </span><br><span>     return sip_filename, pjsip_filename</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def info(msg):</span><br><span style="color: hsl(120, 100%, 40%);">+    if QUIET:</span><br><span style="color: hsl(120, 100%, 40%);">+        return</span><br><span style="color: hsl(120, 100%, 40%);">+    print(msg)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if __name__ == "__main__":</span><br><span>     sip_filename, pjsip_filename = cli_options()</span><br><span>     # configuration parser for sip.conf</span><br><span>     sip = astconfigparser.MultiOrderedConfigParser()</span><br><span style="color: hsl(0, 100%, 40%);">-    print('Please, report any issue at:')</span><br><span style="color: hsl(0, 100%, 40%);">-    print('    https://issues.asterisk.org/')</span><br><span style="color: hsl(0, 100%, 40%);">-    print('Reading ' + sip_filename)</span><br><span style="color: hsl(120, 100%, 40%);">+    info('Please, report any issue at:')</span><br><span style="color: hsl(120, 100%, 40%);">+    info('    https://issues.asterisk.org/')</span><br><span style="color: hsl(120, 100%, 40%);">+    info('Reading ' + sip_filename)</span><br><span>     sip.read(sip_filename)</span><br><span style="color: hsl(0, 100%, 40%);">-    print('Converting to PJSIP...')</span><br><span style="color: hsl(120, 100%, 40%);">+    info('Converting to PJSIP...')</span><br><span>     pjsip, non_mappings = convert(sip, pjsip_filename, dict(), False)</span><br><span style="color: hsl(0, 100%, 40%);">-    print('Writing ' + pjsip_filename)</span><br><span style="color: hsl(120, 100%, 40%);">+    info('Writing ' + pjsip_filename)</span><br><span>     write_pjsip(pjsip_filename, pjsip, non_mappings)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10566">change 10566</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10566"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I7b0e2e90e2549f3f8e01dc96701f111b5874c88d </div>
<div style="display:none"> Gerrit-Change-Number: 10566 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Pascal Cadotte Michaud <pcm@wazo.io> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Pascal Cadotte Michaud <pcm@wazo.io> </div>