Commits

Guido Draheim committed b7d8e86

add recording list timeline events

  • Participants
  • Parent commits 474461d

Comments (0)

Files changed (2)

src/dvbcronrecording/core.py

 import re
 import os.path
 import time
+import datetime
 import locale
 
 from trac.core import Component, implements
 from trac.web import IRequestHandler
 from trac.perm import IPermissionRequestor
 from trac.web.chrome import INavigationContributor, ITemplateProvider
+from trac.timeline.api import ITimelineEventProvider
 from trac.config import Option, ListOption, PathOption, BoolOption
 
 from translate import Translate #@UnresolvedImport
 
 from dvbcronrecording.db.session import db_cnx, commit
 from dvbcronrecording.db.schema import RecordingList #@UnresolvedImport
+from dvbcronrecording.db.schema import RecordingChanges #@UnresolvedImport
 
 def _(text): return text
 
     #
 
     implements(IPermissionRequestor, INavigationContributor, ITemplateProvider,
-      IRequestHandler)
+      IRequestHandler, ITimelineEventProvider)
 
     vardir = Option(PACKAGE, "vardir", VARDIR, 
      doc="Where to store the runtime data like the makefile and cronfile.")
             add_script(req, 'common/js/trac.js')
             return ('recordingplan.html', data, None)
         if page in [ 'activate' ]:
-            data = {}
-            data['title'] = translate("Cron Activate")
-            makefile_entries = self._makefile_entries(req)
-            makefile_list = [ entry.rule for entry in makefile_entries  ]
-            makefile_entries = self._makefile_entries(req) # FIXME
-            crontab_lines = self._to_crontablines(makefile_entries)
-            crontab_reload = self.crontabreloadline()
-            crontab_change = self.crontabchangeline()
-            crontab_list = list(crontab_lines)
-            written_messages = []
-            for adapter in self.adapter_list(req):
-                filename = self.cron_channelsconf_filename(adapter)
-                conf = self.channelsconf_for_adapter(adapter)
-                if conf:
-                    written = self.writefile(req, filename, conf)
-                    written_messages += [ written ]
-            a = self.writefile(req, self.cronfilename(), list(crontab_list))
-            b = self.writefile(req, self.makefilename(), list(makefile_list))
-            c = self.writefile(req, self.cron_update_filename(), [ crontab_reload ])
-            d = self.writefile(req, self.cron_update_change_filename(), [ crontab_change ])
-            e = translate("cron.will.be.updated.every")+(" %s" % self.cronminutes_string())
-            if self.crondirectly:
-                e = self.writefile(req, self.cron_target_filename(), list(crontab_list))
-            data['messages'] = written_messages + [ a, b, c, d, e ]
-            data['cronlines'] = crontab_list # + [ " ============= "] + makefile_list
-            data['_'] = translate
-            add_stylesheet(req, PACKAGE+'/css/recordinglist.css')
-            add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
-            add_script(req, 'common/js/trac.js')
-            return ('recordingcronfile.html', data, None)
+            return self._activate(req, page)
         if page in [ "save" ]:
             text = req.args["text"]
             result = self.savetext(req, text)
         add_script(req, 'common/js/wikitoolbar.js')
         return ('recordinglist.html', data, None)
 
+    # ITimelineEventProvider methods
+
+    def get_timeline_filters(self, req):
+        filters = []
+        if LIST_VIEW in req.perm:
+            filters += [ ("recordinglist", _("Recording List"))]
+        return filters
+
+    def get_timeline_events(self, req, start, stop, filters):
+        try:
+            session = db_cnx(self.env)
+            q = session.query(RecordingChanges)
+            q = q.filter(RecordingChanges.modified >= start)
+            q = q.filter(RecordingChanges.modified <= stop)
+            for item in q.all():
+                yield (PACKAGE, item.modified.replace(tzinfo=req.tz), item.username,
+                       (item.tablename, item.changed))
+        except Exception, e:
+                yield (PACKAGE, datetime.datetime.now(), req.authname,
+                       "ERROR:%s" % str(e))
+            
+    def render_timeline_event(self, req, field, event):
+        tablename, changed = event[3]
+        if field == 'url':
+            return req.href.recording('list')
+        elif field == 'title':
+            if changed.startswith("ACTIVATE"):
+                title = "recording list was activated"
+            else:
+                title = "recording list was modified"
+            return title
+        elif field == 'description':
+            return changed
+        
+            
     # ====================================================================
     
     # ====================================================================
         item.title = req.args.get("title")
         session = db_cnx(self.env)
         session.add(item)
+        changed = "new recording on %s [%s-%s] %s" % (item.channelname,
+                                                      item.newtime,
+                                                      item.endtime,
+                                                      item.title)
+        session.add(RecordingChanges(tablename="RecordingList",
+                                  username=req.authname,
+                                  modified=datetime.datetime.now(),
+                                  changed=changed))
         session.flush()
         return u"OK [rec:%s]" % item.id
 
         item.status = req.args.get("status")
         item.priority = req.args.get("priority")
         item.title = req.args.get("title")
+        changed = "set recording on %s [%s-%s] %s" % (item.channelname,
+                                                      item.newtime,
+                                                      item.endtime,
+                                                      item.title)
+        session.add(RecordingChanges(tablename="RecordingList",
+                                  username=req.authname,
+                                  modified=datetime.datetime.now(),
+                                  changed=changed))
         session.flush()
         return u"OK [rec:%s]" % item.id
 
     # ---------------------------------------------------------------
     # chain up the entries
     # ---------------------------------------------------------------
+    def _activate(self, req, page):
+        req.perm.assert_permission(LIST_VIEW)
+        translate = Translate(PACKAGE, req.locale, req.languages )
+        data = {}
+        data['title'] = translate("Cron Activate")
+        makefile_entries = self._makefile_entries(req)
+        makefile_list = [ entry.rule for entry in makefile_entries  ]
+        makefile_entries = self._makefile_entries(req) # FIXME
+        crontab_lines = self._to_crontablines(makefile_entries)
+        crontab_reload = self.crontabreloadline()
+        crontab_change = self.crontabchangeline()
+        crontab_list = list(crontab_lines)
+        written_messages = []
+        for adapter in self.adapter_list(req):
+            filename = self.cron_channelsconf_filename(adapter)
+            conf = self.channelsconf_for_adapter(adapter)
+            if conf:
+                written = self.writefile(req, filename, conf)
+                written_messages += [ written ]
+        a = self.writefile(req, self.cronfilename(), list(crontab_list))
+        b = self.writefile(req, self.makefilename(), list(makefile_list))
+        c = self.writefile(req, self.cron_update_filename(), [ crontab_reload ])
+        d = self.writefile(req, self.cron_update_change_filename(), [ crontab_change ])
+        e = translate("cron.will.be.updated.every")+(" %s" % self.cronminutes_string())
+        if self.crondirectly:
+            e = self.writefile(req, self.cron_target_filename(), list(crontab_list))
+        try:
+            message = "ACTIVATE: the modified recordinglist was activated"
+            session = db_cnx(self.env)
+            session.add(RecordingChanges(tablename="RecordingList",
+                                  username=req.authname,
+                                  modified=datetime.datetime.now(),
+                                  changed=message))
+        except:
+            pass
+        data['messages'] = written_messages + [ a, b, c, d, e ]
+        data['cronlines'] = crontab_list # + [ " ============= "] + makefile_list
+        data['_'] = translate
+        add_stylesheet(req, PACKAGE+'/css/recordinglist.css')
+        add_stylesheet(req, PACKAGE+'/css/dvbcronrecording.css')
+        add_script(req, 'common/js/trac.js')
+        return ('recordingcronfile.html', data, None)
+    
     def _recording_plan(self, req):
         entries = self._recordings_list(req)
         return list(self._recording_plan_from(req, entries))

src/dvbcronrecording/db/schema.py

 RecordingChannels = _db.RecordingChannels
 RecordingChannelsConf = _db.RecordingChannelsConf
 RecordingList = _db.RecordingList
+RecordingChanges = _db.RecordingChanges
 
 pass