PageRenderTime 66ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/enigma.py

https://github.com/kakunbsc/enigma2.1
Python | 364 lines | 247 code | 109 blank | 8 comment | 7 complexity | 6e336f18ca4c2f6b7e8ec7d3303d1ef8 MD5 | raw file
  1. # fake-enigma
  2. import fake_time
  3. class slot:
  4. def __init__(self):
  5. self.list = [ ]
  6. def get(self):
  7. return self.list
  8. def __call__(self):
  9. for x in self.list:
  10. x()
  11. timers = set()
  12. import time
  13. from events import eventfnc
  14. ##################### ENIGMA BASE
  15. class eTimer:
  16. def __init__(self):
  17. self.timeout = slot()
  18. self.next_activation = None
  19. print "NEW TIMER"
  20. def start(self, msec, singleshot = False):
  21. print "start timer", msec
  22. self.next_activation = time.time() + msec / 1000.0
  23. self.msec = msec
  24. self.singleshot = singleshot
  25. timers.add(self)
  26. def stop(self):
  27. timers.remove(self)
  28. def __repr__(self):
  29. return "<eTimer timeout=%s next_activation=%s singleshot=%s>" % (repr(self.timeout), repr(self.next_activation), repr(self.singleshot))
  30. def do(self):
  31. if self.singleshot:
  32. self.stop()
  33. self.next_activation += self.msec / 1000.0
  34. self.timeout()
  35. def runIteration():
  36. running_timers = list(timers)
  37. assert len(running_timers), "no running timers, so nothing will ever happen!"
  38. running_timers.sort(key=lambda x: x.next_activation)
  39. print "running:", running_timers
  40. next_timer = running_timers[0]
  41. now = time.time()
  42. delay = next_timer.next_activation - now
  43. if delay > 0:
  44. time.sleep(delay)
  45. now += delay
  46. while len(running_timers) and running_timers[0].next_activation <= now:
  47. running_timers[0].do()
  48. running_timers = running_timers[1:]
  49. stopped = False
  50. def stop():
  51. global stopped
  52. stopped = True
  53. def run(duration = 1000):
  54. stoptimer = eTimer()
  55. stoptimer.start(duration * 1000.0)
  56. stoptimer.callback.append(stop)
  57. while not stopped:
  58. runIteration()
  59. ##################### ENIGMA GUI
  60. eSize = None
  61. ePoint = None
  62. gFont = None
  63. eWindow = None
  64. eLabel = None
  65. ePixmap = None
  66. eWindowStyleManager = None
  67. loadPNG = None
  68. addFont = None
  69. gRGB = None
  70. eWindowStyleSkinned = None
  71. eButton = None
  72. eListboxPythonStringContent = None
  73. eListbox = None
  74. eSubtitleWidget = None
  75. class eEPGCache:
  76. @classmethod
  77. def getInstance(self):
  78. return self.instance
  79. instance = None
  80. def __init__(self):
  81. eEPGCache.instance = self
  82. def lookupEventTime(self, ref, query):
  83. return None
  84. eEPGCache()
  85. getBestPlayableServiceReference = None
  86. class pNavigation:
  87. def __init__(self):
  88. self.m_event = slot()
  89. self.m_record_event = slot()
  90. @eventfnc
  91. def recordService(self, service):
  92. return iRecordableService(service)
  93. @eventfnc
  94. def stopRecordService(self, service):
  95. service.stop()
  96. @eventfnc
  97. def playService(self, service):
  98. return None
  99. def __repr__(self):
  100. return "pNavigation"
  101. eRCInput = None
  102. getPrevAsciiCode = None
  103. class eServiceReference:
  104. isDirectory=1
  105. mustDescent=2
  106. canDescent=4
  107. flagDirectory=isDirectory|mustDescent|canDescent
  108. shouldSort=8
  109. hasSortKey=16
  110. sort1=32
  111. isMarker=64
  112. isGroup=128
  113. def __init__(self, ref):
  114. self.ref = ref
  115. self.flags = 0
  116. def toString(self):
  117. return self.ref
  118. def __repr__(self):
  119. return self.toString()
  120. class iRecordableService:
  121. def __init__(self, ref):
  122. self.ref = ref
  123. @eventfnc
  124. def prepare(self, filename, begin, end, event_id):
  125. return 0
  126. @eventfnc
  127. def start(self):
  128. return 0
  129. @eventfnc
  130. def stop(self):
  131. return 0
  132. def __repr__(self):
  133. return "iRecordableService(%s)" % repr(self.ref)
  134. quitMainloop = None
  135. class eAVSwitch:
  136. @classmethod
  137. def getInstance(self):
  138. return self.instance
  139. instance = None
  140. def __init__(self):
  141. eAVSwitch.instance = self
  142. def setColorFormat(self, value):
  143. print "[eAVSwitch] color format set to %d" % value
  144. def setAspectRatio(self, value):
  145. print "[eAVSwitch] aspect ratio set to %d" % value
  146. def setWSS(self, value):
  147. print "[eAVSwitch] wss set to %d" % value
  148. def setSlowblank(self, value):
  149. print "[eAVSwitch] wss set to %d" % value
  150. def setVideomode(self, value):
  151. print "[eAVSwitch] wss set to %d" % value
  152. def setInput(self, value):
  153. print "[eAVSwitch] wss set to %d" % value
  154. eAVSwitch()
  155. eDVBVolumecontrol = None
  156. class eRFmod:
  157. @classmethod
  158. def getInstance(self):
  159. return self.instance
  160. instance = None
  161. def __init__(self):
  162. eRFmod.instance = self
  163. def setFunction(self, value):
  164. print "[eRFmod] set function to %d" % value
  165. def setTestmode(self, value):
  166. print "[eRFmod] set testmode to %d" % value
  167. def setSoundFunction(self, value):
  168. print "[eRFmod] set sound function to %d" % value
  169. def setSoundCarrier(self, value):
  170. print "[eRFmod] set sound carrier to %d" % value
  171. def setChannel(self, value):
  172. print "[eRFmod] set channel to %d" % value
  173. def setFinetune(self, value):
  174. print "[eRFmod] set finetune to %d" % value
  175. eRFmod()
  176. class eDBoxLCD:
  177. @classmethod
  178. def getInstance(self):
  179. return self.instance
  180. instance = None
  181. def __init__(self):
  182. eDBoxLCD.instance = self
  183. def setLCDBrightness(self, value):
  184. print "[eDBoxLCD] set brightness to %d" % value
  185. def setLCDContrast(self, value):
  186. print "[eDBoxLCD] set contrast to %d" % value
  187. def setInverted(self, value):
  188. print "[eDBoxLCD] set inverted to %d" % value
  189. eDBoxLCD();
  190. Misc_Options = None
  191. class eServiceCenter:
  192. @classmethod
  193. def getInstance(self):
  194. return self.instance
  195. instance = None
  196. def __init__(self):
  197. eServiceCenter.instance = self
  198. def info(self, ref):
  199. return None
  200. eServiceCenter()
  201. ##################### ENIGMA CHROOT
  202. print "import directories"
  203. import Tools.Directories
  204. print "done"
  205. chroot="."
  206. for (x, (y, z)) in Tools.Directories.defaultPaths.items():
  207. Tools.Directories.defaultPaths[x] = (chroot + y, z)
  208. Tools.Directories.defaultPaths[Tools.Directories.SCOPE_SKIN] = ("../data/", Tools.Directories.PATH_DONTCREATE)
  209. Tools.Directories.defaultPaths[Tools.Directories.SCOPE_CONFIG] = ("/etc/enigma2/", Tools.Directories.PATH_DONTCREATE)
  210. ##################### ENIGMA CONFIG
  211. print "import config"
  212. import Components.config
  213. print "done"
  214. my_config = [
  215. "config.skin.primary_skin=None\n"
  216. ]
  217. Components.config.config.unpickle(my_config)
  218. ##################### ENIGMA ACTIONS
  219. class eActionMap:
  220. def __init__(self):
  221. pass
  222. ##################### ENIGMA STARTUP:
  223. def init_nav():
  224. print "init nav"
  225. import Navigation, NavigationInstance
  226. NavigationInstance.instance = Navigation.Navigation()
  227. def init_record_config():
  228. print "init recording"
  229. import Components.RecordingConfig
  230. Components.RecordingConfig.InitRecordingConfig()
  231. def init_parental_control():
  232. print "init parental"
  233. from Components.ParentalControl import InitParentalControl
  234. InitParentalControl()
  235. def init_all():
  236. # this is stuff from mytest.py
  237. init_nav()
  238. init_record_config()
  239. init_parental_control()
  240. import Components.InputDevice
  241. Components.InputDevice.InitInputDevices()
  242. import Components.AVSwitch
  243. Components.AVSwitch.InitAVSwitch()
  244. import Components.UsageConfig
  245. Components.UsageConfig.InitUsageConfig()
  246. import Components.Network
  247. Components.Network.InitNetwork()
  248. import Components.Lcd
  249. Components.Lcd.InitLcd()
  250. import Components.SetupDevices
  251. Components.SetupDevices.InitSetupDevices()
  252. import Components.RFmod
  253. Components.RFmod.InitRFmod()
  254. import Screens.Ci
  255. Screens.Ci.InitCiConfig()