Package flumotion :: Package wizard :: Module diskersteps
[hide private]

Source Code for Module flumotion.wizard.diskersteps

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import gettext 
 23   
 24  from flumotion.wizard.models import Consumer 
 25  from flumotion.wizard.basesteps import ConsumerStep 
 26   
 27  __version__ = "$Rev: 7015 $" 
 28  _ = gettext.gettext 
 29   
 30  (SIZE_KB, 
 31   SIZE_MB, 
 32   SIZE_GB, 
 33   SIZE_TB) = tuple([1 << (10L*i) for i in range(1, 5)]) 
 34   
 35  TIME_MINUTE = 60 
 36  TIME_HOUR = 60*60 
 37  TIME_DAY = 60*60*24 
 38  TIME_WEEK = 60*60*24*7 
 39   
 40   
41 -class Disker(Consumer):
42 """I am a model representing the configuration file for a 43 Disk consumer. 44 45 @ivar has_time: if rotation should be done based on time 46 @ivar has_size: if rotation should be done based on size 47 @ivar time_unit: the selected size unit, 48 size will be multiplied by this value when saved 49 @ivar size_unit: the selected time unit, 50 time will be multiplied by this value when saved 51 """ 52 componentType = 'disk-consumer'
53 - def __init__(self):
54 super(Disker, self).__init__() 55 self.has_time = False 56 self.has_size = False 57 self.time_unit = TIME_HOUR 58 self.size_unit = SIZE_KB 59 self.time = 12 60 self.size = 10 61 self.properties.directory = ""
62 63 # Component 64
65 - def _getRotationType(self):
66 if self.has_time: 67 return 'time' 68 elif self.has_size: 69 return 'size' 70 else: 71 return 'none'
72
73 - def getProperties(self):
74 properties = super(Disker, self).getProperties() 75 properties.rotate_type = self._getRotationType() 76 if 'size' in properties: 77 properties.size *= self.size_unit 78 if 'time' in properties: 79 properties.time *= self.time_unit 80 81 return properties
82 83
84 -class DiskStep(ConsumerStep):
85 gladeFile = 'disker-wizard.glade' 86 icon = 'kcmdevices.png' 87
88 - def __init__(self, wizard):
89 self.model = Disker() 90 ConsumerStep.__init__(self, wizard)
91 92 # ConsumerStep 93
94 - def getConsumerModel(self):
95 return self.model
96 97 # WizardStep 98
99 - def setup(self):
100 self.directory.data_type = str 101 self.start_recording.data_type = bool 102 103 self.has_time.data_type = bool 104 self.time.data_type = int 105 self.time_unit.data_type = int 106 self.time_unit.prefill([ 107 (_('minute(s)'), TIME_MINUTE), 108 (_('hour(s)'), TIME_HOUR), 109 (_('day(s)'), TIME_DAY), 110 (_('week(s)'), TIME_WEEK)]) 111 self.time_unit.select(TIME_HOUR) 112 113 self.has_size.data_type = bool 114 self.size.data_type = int 115 self.size_unit.data_type = long 116 self.size_unit.prefill([ 117 (_('kB'), SIZE_KB), 118 (_('MB'), SIZE_MB), 119 (_('GB'), SIZE_GB), 120 (_('TB'), SIZE_TB), 121 ]) 122 123 self.add_proxy(self.model, 124 ['rotate', 125 'has_size', 126 'has_time', 127 'size_unit', 128 'time_unit']) 129 130 self.add_proxy(self.model.properties, 131 ['size', 132 'time', 133 'directory', 134 'start_recording'])
135
136 - def workerChanged(self, worker):
137 self.model.worker = worker 138 self.wizard.requireElements(self.worker, 'multifdsink')
139 140 # Private 141
142 - def _update_radio(self):
143 rotate = self.rotate.get_active() 144 self.has_size.set_sensitive(rotate) 145 self.has_time.set_sensitive(rotate) 146 147 has_size = rotate and self.has_size.get_active() 148 self.size.set_sensitive(has_size) 149 self.size_unit.set_sensitive(has_size) 150 151 has_time = rotate and self.has_time.get_active() 152 self.time.set_sensitive(has_time) 153 self.time_unit.set_sensitive(has_time)
154 155 # Callbacks 156
157 - def on_has_time_toggled(self, radio):
158 self._update_radio()
159
160 - def on_has_size_toggled(self, radio):
161 self._update_radio()
162
163 - def on_rotate_toggled(self, check):
164 self._update_radio()
165 166
167 -class DiskBothStep(DiskStep):
168 name = 'Disk (audio & video)' 169 title = _('Disk (audio and video)') 170 sidebarName = _('Disk audio/video') 171 172 # ConsumerStep 173
174 - def getConsumerType(self):
175 return 'audio-video'
176 177
178 -class DiskAudioStep(DiskStep):
179 name = 'Disk (audio only)' 180 title = _('Disk (audio only)') 181 sidebarName = _('Disk audio') 182 183 # ConsumerStep 184
185 - def getConsumerType(self):
186 return 'audio'
187 188
189 -class DiskVideoStep(DiskStep):
190 name = 'Disk (video only)' 191 title = _('Disk (video only)') 192 sidebarName = _('Disk video') 193 194 # ConsumerStep 195
196 - def getConsumerType(self):
197 return 'video'
198