[Asterisk-code-review] sip_to_pjsip.py: Handle #include globs and other fixes (asterisk[master])

George Joseph asteriskteam at digium.com
Thu Nov 5 08:55:16 CST 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15109 )

Change subject: sip_to_pjsip.py: Handle #include globs and other fixes
......................................................................

sip_to_pjsip.py: Handle #include globs and other fixes

* Wildcards in #includes are now properly expanded

* Implement operators for Section class to allow sorting

ASTERISK-29142 #close

Change-Id: I9b9cd95f4cbe5c24506b75d17173c5aa1a83e5df
---
M contrib/scripts/sip_to_pjsip/astconfigparser.py
1 file changed, 39 insertions(+), 4 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/contrib/scripts/sip_to_pjsip/astconfigparser.py b/contrib/scripts/sip_to_pjsip/astconfigparser.py
index ee857e2..eb48b70 100644
--- a/contrib/scripts/sip_to_pjsip/astconfigparser.py
+++ b/contrib/scripts/sip_to_pjsip/astconfigparser.py
@@ -6,6 +6,7 @@
 """
 
 import re
+import glob
 import itertools
 
 from astdicts import OrderedDict
@@ -57,6 +58,30 @@
         """
         return self.id == other.id
 
+    def __lt__(self, other):
+        """
+        Use self.id as means of determining equality
+        """
+        return self.id < other.id
+
+    def __gt__(self, other):
+        """
+        Use self.id as means of determining equality
+        """
+        return self.id > other.id
+
+    def __le__(self, other):
+        """
+        Use self.id as means of determining equality
+        """
+        return self.id <= other.id
+
+    def __ge__(self, other):
+        """
+        Use self.id as means of determining equality
+        """
+        return self.id >= other.id
+
     def get(self, key, from_self=True, from_templates=True,
             from_defaults=True):
         """
@@ -215,8 +240,17 @@
     included filename, otherwise None.
     """
 
-    match = re.match('^#include\s*[<"]?(.*)[>"]?$', line)
-    return match.group(1) if match else None
+    match = re.match('^#include\s*([^;]+).*$', line)
+    if match:
+        trimmed = match.group(1).rstrip()
+        quoted = re.match('^"([^"]+)"$', trimmed)
+        if quoted:
+            return quoted.group(1)
+        bracketed = re.match('^<([^>]+)>$', trimmed)
+        if bracketed:
+            return bracketed.group(1)
+        return trimmed
+    return None
 
 
 def try_section(line):
@@ -458,8 +492,9 @@
 
             include_name = try_include(line)
             if include_name:
-                parser = self.add_include(include_name)
-                parser.read(include_name, sect)
+                for incl in sorted(glob.iglob(include_name)):
+                    parser = self.add_include(incl)
+                    parser.read(incl, sect)
                 continue
 
             section, is_template, templates = try_section(line)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15109
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I9b9cd95f4cbe5c24506b75d17173c5aa1a83e5df
Gerrit-Change-Number: 15109
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201105/e4614718/attachment.html>


More information about the asterisk-code-review mailing list