Superb quality and spec AB-Com PULSe 4K SE. Crazy offer! Only £99! FREE UK DELIVERY! 4K UHD, Enigma 2, Multiboot 4 images & more!...
Superb quality and spec AB-Com PULSe 4K Rev II Twin Satellite tuner only £149! FREE UK DELIVERY! 4K UHD, Enigma 2, SATA HDD facility, Multiboot 4 images & more!...

[Zgemma H7] Crash creating Autotimer that only matches when description contains a certain string.

So what produces the warning, config,py or the plugin?
Neither. StartEnigma2 complains about an incorrect number of args in a callback. It's related to whether "self" is an arg in an object call. It didn't seem to be an issue in EPGTranslator in the end, but there was no callback involved there.

Anyway, it's now all in AutoTimerEditor.py and looks much better. It now adds a ConfigRegex class there instead (which is an extension of ConfigText).
 
it's now all in AutoTimerEditor.py and looks much better. It now adds a ConfigRegex class there instead (which is an extension of ConfigText).
Ok, that sounds like a good idea.

Can I see the changes please?
 
Can I see the changes please?
Yes. But (I also think) I've worked out how to handle the OpenWebIF interface too, so will get that working first (later tonight??).

This is the patch for the enigma2 GUI:

Code:
[FONT=monospace][COLOR=#000000]--- AT-Regex/AutoTimerEditor.py 2023-06-20 15:18:34.251932420 +0100 [/COLOR]
+++ Enigma-Packages/enigma2-plugins/autotimer/src/AutoTimerEditor.py    2022-09-03 01:17:12.291969535 +0100 
@@ -40,11 +40,6 @@ 
 # Default Record Directory 
 from Tools import Directories 
  
-# So we can check for a valid regex 
-# 
-from re import compile as re_compile 
-from sys import version_info as pv_info 
- 
 # Tags 
 try: 
        from Screens.TagEditor import TagEditor 
@@ -1104,47 +1099,6 @@ 
        def retval(self): 
                return self.returnVal 
  
-# Extend the ConfigText class so we can check that we have a valid 
-# regular expression before saving it. 
-# 
-class ConfigRegex(ConfigText): 
-       def __init__(self, **kwargs): 
-               if "err_timeout" in kwargs: 
-                       self.err_timeout = kwargs["err_timeout"] 
-                       del kwargs["err_timeout"] 
-               else: 
-                       self.err_timeout = 5 
-               if "rpt_session" in kwargs: 
-                       self.rpt_session = kwargs["rpt_session"] 
-                       del kwargs["rpt_session"] 
-               else: 
-                       self.rpt_session = None 
-               ConfigText.__init__(self, **kwargs) 
- 
-       def setValue(self, val): 
-               try:  
-                       dnc = re_compile(val) 
-               except Exception as ex: 
-                       import traceback 
-                       estr = traceback.format_exception_only(ex) 
-                       errm = (_("The filter must be a valid regular expression.\n") + 
-                               _("%s is not valid.") % val + 
-                               "\n\n" + estr[0] + "\n" + 
-                               _("See: ") + 
-                               "https://docs.python.org/%d.%d/library/re.html" % (pv_info.major, pv_info.minor) 
-                              ) 
-                       if self.rpt_session: 
-                               self.rpt_session.open( 
-                                       MessageBox, 
-                                       errm, 
-                                       type=MessageBox.TYPE_ERROR, 
-                                       timeout=self.err_timeout 
-                               ) 
-                       else: 
-                               print("[AutoTimerEditor::ConfigRegex]", errm) 
-                       return 
-               ConfigText.setValue(self, val) 
- 
  
 class AutoTimerFilterEditor(Screen, ConfigListScreen): 
        """Edit AutoTimer Filter""" 
@@ -1333,7 +1287,7 @@ 
                        if self.typeSelection.value == "day": 
                                entry = getConfigListEntry(text, NoSave(ConfigSelection(choices=weekdays))) 
                        else: 
-                               entry = getConfigListEntry(text, NoSave(ConfigRegex(rpt_session=self.session,fixed_size=False))) 
+                               entry = getConfigListEntry(text, NoSave(ConfigText(fixed_size=False))) 
  
                        list.insert(pos, entry) 
                        self["config"].setList(list)
[/FONT]
 
This is the full patch (the correct way round), including the changes to AutoTimerResource.py so that AT settings from OpenWebIF get checked too (and any error is reported to the Web page).
I'll submit a PR if there are no adverse comments....

Code:
--- my-gits/enigma2-plugins/autotimer/src/AutoTimerEditor.py    2022-11-02 12:43:17.325607470 +0000 
+++ AT-Regex/AutoTimerEditor.py 2023-06-21 00:51:11.698200471 +0100 
@@ -40,6 +40,11 @@ 
 # Default Record Directory 
 from Tools import Directories 
  
+# So we can check for a valid regex 
+# 
+from re import compile as re_compile 
+from sys import version_info as pv_info 
+ 
 # Tags 
 try: 
        from Screens.TagEditor import TagEditor 
@@ -1099,6 +1104,59 @@ 
        def retval(self): 
                return self.returnVal 
  
+# Check that a string/list of strings is/are valid regular expressions. 
+# Returns the error message on an invalid regex. 
+# Returns an empty string if all is OK 
+# 
+def CheckValidRegex(str_arg): 
+       if not isinstance(str_arg, (list, tuple)): 
+               str_arg = (str_arg,)    # Make a tuple from a single string 
+       try:  
+               for val in str_arg: 
+                       dnc = re_compile(val) 
+       except Exception as ex: 
+               import traceback 
+               estr = traceback.format_exception_only(ex) 
+               errm = (_("The filter must be a valid regular expression.\n") + 
+                       _("%s is not valid.") % val + 
+                       "\n\n" + estr[0] + "\n" + 
+                       _("See: ") + 
+                       "https://docs.python.org/%d.%d/library/re.html" % (pv_info.major, pv_info.minor) 
+                      ) 
+               return errm 
+       return "" 
+ 
+# Extend the ConfigText class so we can check that we have a valid 
+# regular expression before saving it. 
+# 
+class ConfigRegex(ConfigText): 
+       def __init__(self, **kwargs): 
+               if "err_timeout" in kwargs: 
+                       self.err_timeout = kwargs["err_timeout"] 
+                       del kwargs["err_timeout"] 
+               else: 
+                       self.err_timeout = 5 
+               if "rpt_session" in kwargs: 
+                       self.rpt_session = kwargs["rpt_session"] 
+                       del kwargs["rpt_session"] 
+               else: 
+                       self.rpt_session = None 
+               ConfigText.__init__(self, **kwargs) 
+ 
+       def setValue(self, val): 
+               errm = CheckValidRegex(val) 
+               if errm != "": 
+                       if self.rpt_session: 
+                               self.rpt_session.open( 
+                                       MessageBox, 
+                                       errm, 
+                                       type=MessageBox.TYPE_ERROR, 
+                                       timeout=self.err_timeout 
+                               ) 
+                       else: 
+                               print("[AutoTimerEditor::ConfigRegex]", errm) 
+                       return 
+               ConfigText.setValue(self, val) 
  
 class AutoTimerFilterEditor(Screen, ConfigListScreen): 
        """Edit AutoTimer Filter""" 
@@ -1287,7 +1345,7 @@ 
                        if self.typeSelection.value == "day": 
                                entry = getConfigListEntry(text, NoSave(ConfigSelection(choices=weekdays))) 
                        else: 
-                               entry = getConfigListEntry(text, NoSave(ConfigText(fixed_size=False))) 
+                               entry = getConfigListEntry(text, NoSave(ConfigRegex(rpt_session=self.session,fixed_size=False))) 
  
                        list.insert(pos, entry) 
                        self["config"].setList(list) 
--- my-gits/enigma2-plugins/autotimer/src/AutoTimerResource.py  2022-11-02 12:43:17.325607470 +0000 
+++ AT-Regex/AutoTimerResource.py       2023-06-21 00:49:39.892327324 +0100 
@@ -16,6 +16,8 @@ 
  
 from .AutoTimerSettings import getAutoTimerSettingsDefinitions 
  
+from .AutoTimerEditor import CheckValidRegex 
+ 
 API_VERSION = "1.7" 
  
  
@@ -410,6 +412,10 @@ 
                                description.remove('') 
                        while '' in dayofweek: 
                                dayofweek.remove('') 
+# These must be valid regexes 
+                       errm = CheckValidRegex(title + shortdescription + description) 
+                       if errm != "": 
+                               return self.returnResult(req, False, errm) 
                        timer.include = (title, shortdescription, description, dayofweek) 
  
                # Excludes 
@@ -431,6 +437,10 @@ 
                                description.remove('') 
                        while '' in dayofweek: 
                                dayofweek.remove('') 
+# These must be valid regexes 
+                       errm = CheckValidRegex(title + shortdescription + description) 
+                       if errm != "": 
+                               return self.returnResult(req, False, errm) 
                        timer.exclude = (title, shortdescription, description, dayofweek) 
  
                tags = getA("tag")
 
Although I might change CheckValidRegex to be CheckREList and always send it a list, rather than getting the function to check what it has been given.
And simplify the keyword extraction for ConfigRegex, by just putting it in the parameter list.
 
Last edited:
I've submitted a PR (with the changes mentioned in the previous post).
And have now received an email saying it failed a quality test as:

Add 1 missing arguments; 'format_exception_only' expects 2 positional arguments.
Bug
However, Since Python 3.10 it doesn't required 2 args and if I did give it a second one it would ignore the first one (which is the relevant one) for "backward compatibility". (The 1-arg version does work on Vix 6.4.xxx).

So I reckon the auto-test is wrong. Since I'm assuming all users of this will be by Python >= 3.10.

EDIT: Although I can confirm it is an issue on Python3.9.

EDIT2: I now have a version that works on 3.9 and 3.11 (using the old 3.9 syntax). Is it worth resubmitting?
 
Last edited:

OpenViX Feeds Status

Back
Top