Support Uno4kSE
[vuplus_openvuplus_3.0] / meta-bsp / recipes-vuplus / enigma2 / enigma2 / enigma2_vuplus_check_recording.patch
1 commit 6d396db9931e940fbc3435266ace23327b978575
2 Author: hschang <chang@dev3>
3 Date:   Thu Aug 10 15:22:42 2017 +0900
4
5     USB Harddisk test
6
7 diff --git a/RecordTimer.py b/RecordTimer.py
8 index 32fb923..5a13d7f 100755
9 --- a/RecordTimer.py
10 +++ b/RecordTimer.py
11 @@ -410,6 +410,15 @@ class RecordTimerEntry(timer.TimerEntry, object):
12  
13         record_service = property(lambda self: self.__record_service, setRecordService)
14  
15 +       def checkRecordingPath(self):
16 +               old_Filename = self.Filename
17 +               self.calculateFilename()
18 +               filename = self.Filename
19 +               self.Filename = old_Filename
20 +
21 +               from Components import Harddisk
22 +               return not Harddisk.isUsbStorage(filename)
23 +
24  def createTimer(xml):
25         begin = int(xml.get("begin"))
26         end = int(xml.get("end"))
27 @@ -466,6 +475,16 @@ class RecordTimer(timer.Timer):
28                         print "unable to load timers from file!"
29  
30         def doActivate(self, w):
31 +               if w.state == RecordTimerEntry.StateWaiting and w.checkRecordingPath() is False:
32 +                       service_name = w.service_ref.getServiceName()
33 +                       self.timer_list.remove(w)
34 +                       if w.dontSave is False:
35 +                               w.resetState()
36 +                               w.disable()
37 +                               self.addTimerEntry(w)
38 +                       Notifications.AddNotification(MessageBox, _("Can not recording on a USB storage.\nService name : %s"% service_name), MessageBox.TYPE_ERROR)
39 +                       return
40 +
41                 # when activating a timer which has already passed,
42                 # simply abort the timer. don't run trough all the stages.
43                 if w.shouldSkip():
44 diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py
45 index 1221f8f..c455e5f 100755
46 --- a/lib/python/Components/Harddisk.py
47 +++ b/lib/python/Components/Harddisk.py
48 @@ -6,6 +6,8 @@ from Tools.CList import CList
49  from SystemInfo import SystemInfo
50  import time
51  from Components.Console import Console
52 +import os
53 +import glob
54  
55  def MajorMinor(path):
56         rdev = stat(path).st_rdev
57 @@ -56,6 +58,30 @@ def enableUdevEvent(enable = True):
58         print "CMD : ", cmd
59         system(cmd)
60  
61 +def getDeviceFile(dev_path):
62 +       for parts in getProcMounts():
63 +               if os.path.realpath(parts[1]).startswith(dev_path):
64 +                       return parts[0]
65 +
66 +def isUsbStorage(filename):
67 +       _dirname = os.path.dirname(filename)
68 +       _dirname = os.path.realpath(_dirname)
69 +       while not os.path.ismount(_dirname):
70 +               _dirname = os.path.dirname(_dirname)
71 +
72 +       if _dirname == '/':
73 +               return False
74 +
75 +       dev = getDeviceFile(_dirname)
76 +       if dev:
77 +               dev = os.path.basename(dev)
78 +               phyPath = os.path.realpath('/sys/block/' + dev[:3])
79 +               for x in glob.glob("/sys/bus/usb/devices/usb*"):
80 +                       if phyPath.find(os.path.realpath(x)) != -1:
81 +                               return True
82 +
83 +       return False
84 +
85  DEVTYPE_UDEV = 0
86  DEVTYPE_DEVFS = 1
87  
88 diff --git a/lib/python/Screens/InfoBarGenerics.py b/lib/python/Screens/InfoBarGenerics.py
89 index ea75301..9b04238 100755
90 --- a/lib/python/Screens/InfoBarGenerics.py
91 +++ b/lib/python/Screens/InfoBarGenerics.py
92 @@ -1223,6 +1223,11 @@ class InfoBarTimeshift:
93                 if self.timeshift_enabled:
94                         print "hu, timeshift already enabled?"
95                 else:
96 +                       from Components import Harddisk
97 +                       if Harddisk.isUsbStorage(config.usage.timeshift_path.value):
98 +                               self.session.open(MessageBox, _("Timeshift not possible on a USB storage."), MessageBox.TYPE_ERROR)
99 +                               return 0
100 +
101                         if not ts.startTimeshift():
102                                 self.timeshift_enabled = 1
103  
104 diff --git a/timer.py b/timer.py
105 old mode 100644
106 new mode 100755
107 index aaae0b2..d58a83e
108 --- a/timer.py
109 +++ b/timer.py
110 @@ -232,6 +232,10 @@ class Timer:
111                 self.setNextActivation(min)
112         
113         def timeChanged(self, timer):
114 +               if timer not in (self.processed_timers + self.timer_list):
115 +                       print "timer not found"
116 +                       return
117 +
118                 print "time changed"
119                 timer.timeChanged()
120                 if timer.state == TimerEntry.StateEnded: