Commits

Guido Draheim committed 3aeda8f

use trac plugin model for imports from components

  • Participants
  • Parent commits 65b02f0

Comments (0)

Files changed (2)

File src/dvbcronrecording/channels.py

         q = session.query(RecordingChannels)
         q = q.filter_by(id = req.args.get("id")).delete()
 
+    def channelname_list(self, req, defaults = None):
+        """ Returns list of the adapter settings """
+        session = db_cnx(self.env)
+        if defaults is None:
+            translate = Translate("channels", req.locale)
+            _defaults = translate.get("-default-channels", "3sat")
+            defaults = [ item.strip() for item in _defaults.split(",") ]
+        cols = ['channelname']
+        sql = "SELECT DISTINCT %s FROM recording_channels" % (",".join(cols))
+        sql += " ORDER BY "+(",".join(cols))
+        result = session.execute(sql)
+        entries = []
+        for entry in result:
+            entries.append(entry[0])
+        for channelname in defaults:
+            if channelname not in entries:
+                entries.append(channelname)
+        return entries
+    def channelname_to_channelconflist(self, req, channelname):
+        """ input is a channelname and the result is an object list with
+            attributes adapter + channel title. A tuning operation
+            will usually specify the channel.conf for the adapter
+            along with the zap entry name to be used from that file."""
+        logg.debug("resolving %s" % channelname)
+        q = db_cnx(self.env).query(RecordingChannels)
+        q = q.order_by("channelname", "title", "adapter")
+        q = q.filter_by( channelname = channelname)
+        for entry in q.all():
+            logg.debug("   found %s" % entry.title)
+            logg.debug("      at %s\n" % entry.adapter)
+            item = channelconfitem()
+            item.adapter = entry.adapter
+            item.title = entry.title
+            item.channel = entry.title  
+            yield item
 
-
-"""
-  Returns list of the adapter settings
-"""
-def channelname_list(env, req, defaults = None):
-    session = db_cnx(env)
-    if defaults is None:
-        translate = Translate("channels", req.locale)
-        _defaults = translate.get("-default-channels", "3sat")
-        defaults = [ item.strip() for item in _defaults.split(",") ]
-    cols = ['channelname']
-    sql = "SELECT DISTINCT %s FROM recording_channels" % (",".join(cols))
-    sql += " ORDER BY "+(",".join(cols))
-    result = session.execute(sql)
-    entries = []
-    for entry in result:
-        entries.append(entry[0])
-    for channelname in defaults:
-        if channelname not in entries:
-            entries.append(channelname)
-    return entries
-    
 class channelconfitem: pass
-def channelname_to_channelconflist(env, req, channelname):
-    """ input is a channelname and the result is an object list with
-        attributes adapter + channel title. A tuning operation
-        will usually specify the channel.conf for the adapter
-        along with the zap entry name to be used from that file."""
-    logg.debug("resolving %s" % channelname)
-    q = db_cnx(env).query(RecordingChannels)
-    q = q.order_by("channelname", "title", "adapter")
-    q = q.filter_by( channelname = channelname)
-    for entry in q.all():
-        logg.debug("   found %s" % entry.title)
-        logg.debug("      at %s\n" % entry.adapter)
-        item = channelconfitem()
-        item.adapter = entry.adapter
-        item.title = entry.title
-        item.channel = entry.title  
-        yield item
-

File src/dvbcronrecording/core.py

 from trac.config import Option, ListOption, PathOption, BoolOption
 
 from translate import Translate #@UnresolvedImport
-from channels import channelname_list, channelname_to_channelconflist
 from computer import TracSimpleRecorderComputer, MMMtoHHMM
 try:
+    from channels import DvbCronRecordingChannelsPlugin
+except:
+    DvbCronRecordingChannelsPlugin = None
+try:
     from tuning import DvbCronRecordingTuningPlugin
 except:
     DvbCronRecordingTuningPlugin = None
       Returns list of the adapter settings
     """
     def _channelname_list(self, req):
-        return channelname_list(self.env, req)
+        if DvbCronRecordingChannelsPlugin is None:
+            return []
+        channels = DvbCronRecordingChannelsPlugin(self.env)
+        return channels.channelname_list(req)
     
     def _newrecordings_list(self, req):
         translate = Translate("core", req.locale)
         plan = computer.plan(entries)
         for item in plan.items():
             yield item
+            
+    def _channelname_to_channelconflist(self, req, channelname):
+        if DvbCronRecordingChannelsPlugin is None:
+            return []
+        channels = DvbCronRecordingChannelsPlugin(self.env)
+        return channels.channelname_to_channelconflist(req, channelname)
 
     """ 
         This is doing the actual computations
                 adapter = item.tuning_adapter
                 channel = item.tuning_channel
                 if not adapter: adapter = "0"
-                for tuning in channelname_to_channelconflist(self.env, req, channelname):
+                for tuning in self._channelname_to_channelconflist(req, channelname):
                     # TODO: allow to change the adapter
                     if tuning.adapter != adapter: continue
                     if tuning.channel: channel = tuning.channel