mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 18:55:19 +00:00 
			
		
		
		
	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
This commit is contained in:
		
				
					committed by
					
						 George Joseph
						George Joseph
					
				
			
			
				
	
			
			
			
						parent
						
							57ee79a563
						
					
				
				
					commit
					a5d55fc9e1
				
			| @@ -6,6 +6,7 @@ the GNU General Public License Version 2. | ||||
| """ | ||||
|  | ||||
| import re | ||||
| import glob | ||||
| import itertools | ||||
|  | ||||
| from astdicts import OrderedDict | ||||
| @@ -57,6 +58,30 @@ class Section(MultiOrderedDict): | ||||
|         """ | ||||
|         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 @@ def try_include(line): | ||||
|     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 @@ class MultiOrderedConfigParser: | ||||
|  | ||||
|             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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user