Commits

Guido Draheim  committed d2767c1

change computer into trac component with options

  • Participants
  • Parent commits c4b4f7a

Comments (0)

Files changed (4)

 syntax: regexp
 ^rpm$
 syntax: regexp
-^src/dvbcronrecording/locale/de/LC_MESSAGES/dvbcronrecording\.po$
+^src/dvbcronrecording/locale/de/LC_MESSAGES/dvbcronrecording\.po$
+syntax: regexp
+^src/MANIFEST$

File .pydevproject

 <?eclipse-pydev version="1.0"?>
 
 <pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2.7</pydev_property>
 <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
 <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
 <path>/DvbCronRecording/src</path>
-<path>/DvbCronRecording/src/tracsimplerecorder</path>
 </pydev_pathproperty>
 <pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
 <path>/usr/lib/python2.6/site-packages</path>
-<path>/usr/lib64/python2.6</path>
-<path>/usr/lib64/python2.6/site-packages</path>
+<path>/usr/lib/python2.7/site-packages</path>
+<path>/usr/lib64/python2.7</path>
+<path>/usr/lib64/python2.7/site-packages</path>
 </pydev_pathproperty>
 </pydev_project>

File src/dvbcronrecording/computer.py

 import time
 import re
 import datetime
-
 import logging
 
+from trac.core import Component #, implements
+from trac.config import Option, ListOption, FloatOption, BoolOption
+
+try:
+    from channels import DvbCronRecordingChannelsPlugin
+except:
+    DvbCronRecordingChannelsPlugin = None
+
 DEBUG = False
+PACKAGE = 'dvbcronrecording'
+NAV = 'recordings'
+URL = 'recording'
 
-logg = logging.getLogger("DvbCronRecordingComputer")
-if DEBUG:
-    logg.addHandler(logging.FileHandler("/tmp/DvbCronRecordingComputer.log"))
-    logg.setLevel(logging.DEBUG)
-
-onlydate_rank = 0.5 # +1
-rankup_channels = [ "3sat", "arte" ]
-rankup_plus = 0.3
 default_adapter = u"0"
 
 def intnull(value, default = None):
         self.after = []
         self.message = ""
 
-class RecorderItem:
+class RecorderItem(Component):
     """ converting the database entry - which is similar to what
         the user entered in the input form fields - to an object
         with computable data attributes. Note that newtime/endtime
 
 months_ahead = 3
     
-class TracSimpleRecorderComputer:
+class TracCronRecordingPlanComputer(Component):
+    """ it is a component but it does not have its own database tables - it 
+        just helps to turn the recording list into a proper recording plan. """
+        
+    algorithm = Option(PACKAGE, "planning-algorithm", "plan3",
+                       doc="Choose the planning type plan1,plan2,plan3,plan4")
+    rankup_channels = ListOption(PACKAGE, "planning-rankup-channels","3sat,arte",
+                       doc="Choose the channels to implicitly rank higher")
+    rankup_value = FloatOption(PACKAGE, "planning-rankup-value", 0.3,
+                        doc="Amount of rank increment for the rankup-channels") 
+    onlydate_rankup = FloatOption(PACKAGE, "planning-onlydate-rankup", 0.5,
+                        doc="Amount of rank increment for single date recordings") 
+    
     def __init__(self):
         self._adapters = {}
         self._adapterlist = None
+        self.logg = logging.getLogger(__name__)
     
     def adapters(self, channelname):
         if channelname in self._adapters:
             adapterlist += [ default_adapter ]
         return adapterlist
             
+    def channels_list(self):
+        if DvbCronRecordingChannelsPlugin is None:
+            return [ 0 ]
+        channels = DvbCronRecordingChannelsPlugin(self.env)
+        return channels.channels_list()
+    
+    # ======================================================================
     def zero(self, spec):
         if not spec: return 0
         return int(spec)
     def recordinglist_to_recorderitems(self, entries, ahead = months_ahead):
         allowed_months = self.get_allowed_months(ahead)
         past_days = self.get_past_days_this_month()
-        logg.info("allowed_months %s" % (str(allowed_months)))    
+        self.logg.debug("allowed_months %s" % (str(allowed_months)))    
         for entry in entries:
             if entry.status == "no": 
-                logg.debug("status disabled for %s", entry.title) 
+                self.logg.debug("status disabled for %s", entry.title) 
                 continue
             item = RecorderItem()
             item.channelname = entry.channelname
             item.title = entry.title
             if not item.title:
-                logg.debug("item had not title") 
+                self.logg.debug("item had not title") 
                 continue            
             if not item.channelname: 
-                logg.debug("no channel name for '%s", item.title) 
+                self.logg.debug("no channel name for '%s", item.title) 
                 continue            
             m = re.match("(\d+)[.](\d+)[.]", entry.onlydate)
             if m:
-                logg.debug("onlydate %s for %s", entry.onlydate, item.title)
+                self.logg.debug("onlydate %s for %s", entry.onlydate, item.title)
                 try:
                     onlyday = intnull(m.group(1))
                     onlymonth = intnull(m.group(2))
                     if not onlyday: continue
                     if not onlymonth: continue
                     if onlymonth not in allowed_months:
-                        logg.debug("onlymonth not in allowed_months '%s'", item.title) 
+                        self.logg.debug("onlymonth not in allowed_months '%s'", item.title) 
                         continue
                     if (onlyday, onlymonth) in past_days: 
-                        logg.debug("(onlyday, onlymonth) in past_days '%s'", item.title) 
+                        self.logg.debug("(onlyday, onlymonth) in past_days '%s'", item.title) 
                         continue
                     item.onlyday = onlyday
                     item.months = [ onlymonth ]
-                    logg.info("onlyday %s onlymonths %s for %s", item.onlyday, item.months, item.title)
+                    self.logg.debug("onlyday %s onlymonths %s for %s", item.onlyday, item.months, item.title)
                 except Exception:
-                    logg.debug("conversion error %s '%s'", entry.onlydate, item.title)
+                    self.logg.debug("conversion error %s '%s'", entry.onlydate, item.title)
                 item.weekday = intnull(entry.weekday)
             else: 
                 item.weekday = intnull(entry.weekday)
                 if item.weekday is None:
-                    logg.debug("item.weekday is None '%s'", item.title) 
+                    self.logg.debug("item.weekday is None '%s'", item.title) 
                     continue
                 if item.weekday >= 7: item.weekday = item.weekday % 7
             item.newtimeMMM = self.zero(self.minutes(entry.newtime))
             item.extratimeM = self.zero(self.minutes(entry.extratime))
             try: item.rank = float(int(entry.priority))
             except: pass
-            if item.channelname in rankup_channels:
-                item.rank += rankup_plus
-            logg.debug("originally %s-%s '%s'" % (entry.newtime, entry.endtime, item.title))
+            if item.channelname in self.rankup_channels:
+                item.rank += self.rankup_value
+            self.logg.debug("originally %s-%s '%s'" % (entry.newtime, entry.endtime, item.title))
             yield item
     def recordinglist_to_recordergroups(self, entries, ahead = months_ahead):
         recorderitems = list(self.recordinglist_to_recorderitems(entries, ahead))
             for month in item.months: 
                 if month not in onlymonths:
                     onlymonths.append(month)
-        logg.info("onlymonths %s", onlymonths)
+        self.logg.debug("onlymonths %s", onlymonths)
         regularmonths = [ month for month in xrange(1,13) if month not in onlymonths ]
-        logg.info("regularmonths %s", regularmonths)
+        self.logg.debug("regularmonths %s", regularmonths)
         localtime = time.localtime()
         this_month = localtime.tm_mon
         this_year = localtime.tm_year
                     # no generate the recordings for that day
                     items = self.clone_filtered_for_date(recorderitems, date)
                     for group in self.recordergroups_from_filtered(items):
-                        logg.info("onlydate group %s", unicode(group))
+                        self.logg.debug("onlydate group %s", unicode(group))
                         yield group
                 except ValueError:
                     pass # expected
         items = self.clone_filtered_for_regular(recorderitems, regularmonths)
-        logg.info("=======================================================")
+        self.logg.debug("=======================================================")
         items = list(items)
         for item in items:
-            logg.info("regular item %s", unicode(item))
+            self.logg.debug("regular item %s", unicode(item))
         for group in self.recordergroups_from_filtered(items):
-            logg.info("regular group %s", unicode(group))
+            self.logg.debug("regular group %s", unicode(group))
             yield group
     def clone_filtered_for_date(self, recorderitems, date):
         for item in recorderitems:
             newitem.months = [ date.month ]
             newitem.weekday = date.weekday()
             if item.onlyday: 
-                newitem.rank += onlydate_rank
+                newitem.rank += self.onlydate_rankup
             yield newitem
     def clone_filtered_for_regular(self, recorderitems, regularmonths):
         for item in recorderitems:
             of newtime-endtime is the recording time interval. """
         yield self.adjust_recordergroup(group) 
     def adjust_recordergroup(self, group):
-        logg.info("adjust group %s", unicode(group))
+        self.logg.debug("adjust group %s", unicode(group))
         nextday = 0
         previous = None
         for item in group.items:
             nextday = 0
         return group
     def make_cronmonths(self, group):
-        logg.info("adjust group %s", unicode(group))
+        self.logg.debug("adjust group %s", unicode(group))
         for item in group.items:
             ranges = []
             months = item.months
                             if date.month not in item.months: continue
                         else:
                             if item.weekday != date.weekday(): continue
-                        logg.info("* %s => [%s.%s.] w%s '%s'", date, item.onlyday, item.months, item.weekday, item.title)
+                        self.logg.debug("* %s => [%s.%s.] w%s '%s'", date, item.onlyday, item.months, item.weekday, item.title)
                         newtimeMMM = item.newtimeMMM
                         endtimeMMM = item.endtimeMMM
                         if endtimeMMM < newtimeMMM: endtimeMMM += 24 * 60
         predeletes = []
         seen = ""
         for elem in timelist:
-            logg.info("timelist_groups: adapter '%s' -vs- '%s'",
+            self.logg.debug("timelist_groups: adapter '%s' -vs- '%s'",
                       adapter, elem.adapter)            
             if adapter is not None and elem.adapter is not None:
                 if adapter != elem.adapter:
         return newplan           
     def plan3(self, entries):
         """ main entry point """
+        self.logg.info("plan3")
         timelist = list(self.recordinglist_to_recordertimelist(entries))
         old_deleted = 0
         for round in xrange(2):
         return plan
     def plan4(self, entries):
         """ main entry point """
-        logg.info("plan4")
+        self.logg.info("plan4")
         timelist = list(self.recordinglist_to_recordertimelist(entries))
         self.assign_adapters_for_timelist(timelist)
         old_deleted = 0
         for adapter in self.adapterlist():
             for group in self.timelist_groups(timelist, adapter):
                 plan.addgroup(group)
-        logg.info("adapterlist = %s", self.adapterlist())
+        self.logg.info("adapterlist = %s", self.adapterlist())
         if True:
             plan.sort()
             return self.reduce_regular_groups(plan)
             return plan
             
     def plan(self, entries):
+        self.set_adapters_from_channels_list(self.channels_list())
         return self.plan3(entries)
 
 def deltaM(td):

File src/dvbcronrecording/core.py

 from trac.config import Option, ListOption, PathOption, BoolOption
 
 from translate import Translate #@UnresolvedImport
-from computer import TracSimpleRecorderComputer, MMMtoHHMM
+from computer import TracCronRecordingPlanComputer, MMMtoHHMM
 try:
     from channels import DvbCronRecordingChannelsPlugin
 except:
         return "\n".join(list(self.loadtextlines(req)))
     def loadtextlines(self, req):
         entries = self._recordings_list(req)
-        computer = TracSimpleRecorderComputer()
-        computer.set_adapters_from_channels_list(self.channels_list())
+        computer = TracCronRecordingPlanComputer(self.env)
         plan = computer.plan(entries)
         for group in plan.groups():
             newtime = MMMtoHHMM(group.newtimeMMM).replace(":","")
         entries = self._recordings_list(req)
         return list(self._recording_plan_from(entries))
     def _recording_plan_from(self, entries):
-        computer = TracSimpleRecorderComputer()
-        computer.set_adapters_from_channels_list(self.channels_list())
+        computer = TracCronRecordingPlanComputer(self.env)
         plan = computer.plan(entries)
         for item in plan.items():
             yield item
     """
     def _makefile_entries(self, req):
         entries = self._recordings_list(req)
-        computer = TracSimpleRecorderComputer()
-        computer.set_adapters_from_channels_list(self.channels_list())
+        computer = TracCronRecordingPlanComputer(self.env)
         plan = computer.plan(entries)
         for group in plan.groups():
             if not group.items: continue