adding the Gemini3 Wizard
[enigma2-plugins.git] / geminiwizard / src / plugin.py
1 # -*- coding: utf-8 -*-
2 from enigma import quitMainloop
3 from Screens.Screen import Screen
4 from Screens.ChoiceBox import ChoiceBox
5 from Screens.MessageBox import MessageBox
6 from Plugins.Plugin import PluginDescriptor
7 from Tools.HardwareInfo import HardwareInfo
8 from Components.Ipkg import IpkgComponent as OpkgComponent
9 from os import path as os_path, system as os_system
10
11 #-------------------------------------------------------------------------------------------------
12
13 def setFeed():
14         def _createFeedConf(type):
15                 wfile = open("/etc/opkg/gemini-%s-feed.conf" % (type), 'w')
16                 wfile.write("src/gz gemini-%s http://download.blue-panel.com/gemini3/%s\n" % (type, type))
17                 wfile.close()
18                 
19         device = HardwareInfo()
20         _createFeedConf('mipsel')
21         _createFeedConf(device.get_device_name())
22         _createFeedConf('all')
23         return 1
24
25 #-------------------------------------------------------------------------------------------------
26 def checkForUgly():
27         for x in ["/etc/MultiQuickButton", "/etc/init.d/CCcam", "/usr/lib/enigma2/python/Plugins/Extensions/Quickbutton"]:
28                 if os_path.exists(x):
29                         if x == "/etc/MultiQuickButton":
30                                 return "Multiquickbutton plugin"
31                         elif x == "/etc/init.d/CCcam":
32                                 return "pimp plugin (CCcam)"
33                         elif x == "/usr/lib/enigma2/python/Plugins/Extensions/Quickbutton":
34                                 return "Quickbutton plugin"
35                 return ""
36
37 #-------------------------------------------------------------------------------------------------
38
39 def main(session, **kwargs):
40         list =[
41                 (_("Install") + " Gemini Plugin", {"package": "geminiplugin"}),
42                 (_("Install") + " Gemini Plugin " + " ( + " + _("Plugins") + ")", {"package": "g3install-full"})
43                 ]
44         session.STATE=-1
45         session.GP3PACKAGE=None
46         session.info = None
47         session.opkg = OpkgComponent()
48         ugly = checkForUgly()
49         
50         def Exit(arg):
51                 exit(None)
52         
53         if ugly != "":
54                 session.openWithCallback(Exit, MessageBox, _("Gemini3 Wizard Installation stoped\nPlease remove '%s' first!") % ugly, MessageBox.TYPE_ERROR, timeout=15)
55                 
56         def _reboot(val=None):
57                 FINALE = "depmod -a && update-modules"
58                 if session.GP3PACKAGE["package"] == "g3install-full":
59                         FINALE +=" && opkg remove g3install-full"
60                 os_system(FINALE)
61                 quitMainloop(2)
62                 
63         def _opkgCallback(event, param):
64                 if event == OpkgComponent.EVENT_DONE:
65                         if session.STATE == 0:
66                                 session.STATE=1
67                                 session.opkg.startCmd(OpkgComponent.CMD_INSTALL, session.GP3PACKAGE)
68                                 
69                         elif session.STATE == 1:
70                                 session.info.close(True)
71                                 
72                 elif event == OpkgComponent.EVENT_ERROR:
73                         session.open(MessageBox, _("Gemini3 Wizard: %s") % param, MessageBox.TYPE_ERROR, timeout=5)
74                         
75         session.opkg.addCallback(_opkgCallback)
76         
77         def _closeInfo(val=None):
78                 if val is not None:
79                         session.openWithCallback(_reboot, MessageBox, _("Restart"), MessageBox.TYPE_INFO, timeout=5)
80         
81         def _selectPackage(pack):
82                 if pack is not None:
83                         session.info = session.openWithCallback(_closeInfo, MessageBox, _("Install") + " Gemini plugin...", type = MessageBox.TYPE_INFO, enable_input = False)
84                         session.GP3PACKAGE = pack[1]
85                         if setFeed():
86                                 session.STATE=0
87                                 session.opkg.startCmd(OpkgComponent.CMD_UPDATE)
88                 
89         session.openWithCallback(_selectPackage, ChoiceBox, title = "Gemini3 Wizard", list = list)
90
91 #-------------------------------------------------------------------------------------------------
92
93 def Plugins(**kwargs):
94         return PluginDescriptor(
95                         name=_("Gemini3 Wizard"),
96                         description=_("the Gemini3 plugin Wizard"),
97                         where = [PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU],
98                         icon="gp3wizard.png",
99                         fnc=main)