add DreamPackageWizard
[enigma2.git] / lib / python / Screens / DefaultWizard.py
1 from Wizard import wizardManager
2 from Screens.WizardLanguage import WizardLanguage
3 from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTPARTITION
4
5 from Components.Pixmap import Pixmap, MovingPixmap
6 from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, getConfigListEntry
7 from Components.DreamInfoHandler import DreamInfoHandler, InfoHandler, InfoHandlerParseError
8 from Components.PluginComponent import plugins
9 from Plugins.Plugin import PluginDescriptor
10 import os
11
12 config.misc.defaultchosen = ConfigBoolean(default = True)
13
14 import xml.sax
15
16 class DefaultWizard(WizardLanguage, DreamInfoHandler):
17         def __init__(self, session, silent = True):
18                 DreamInfoHandler.__init__(self, self.statusCallback)
19                 self.silent = silent
20                 self.setDirectory()
21         
22                 WizardLanguage.__init__(self, session, showSteps = False)
23                 self["wizard"] = Pixmap()
24                 self["rc"] = MovingPixmap()
25                 self["arrowdown"] = MovingPixmap()
26                 self["arrowup"] = MovingPixmap()
27                 self["arrowup2"] = MovingPixmap()
28         
29         def setDirectory(self):
30                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
31                 self.directory = resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)
32                 self.xmlfile = "defaultwizard.xml"
33         
34         def markDone(self):
35                 config.misc.defaultchosen.value = 0
36                 config.misc.defaultchosen.save()
37                 configfile.save()
38                 
39         def statusCallback(self, status, progress):
40                 print "statusCallback:", status, progress
41                 if status == DreamInfoHandler.STATUS_DONE:
42                         self["text"].setText(_("The installation of the default settings is finished. You can now continue configuring your Dreambox by pressing the OK button on the remote control."))
43                         self.markDone()
44                         self.disableKeys = False
45
46         def getConfigList(self):
47                 self.packageslist = []
48                 configList = []
49                 self.fillPackagesList()
50                 self.packagesConfig = []
51                 for x in range(len(self.packageslist)):
52                         entry = ConfigYesNo()
53                         self.packagesConfig.append(entry)
54                         configList.append(getConfigListEntry(self.packageslist[x][0]["attributes"]["name"], entry))
55                 return configList
56
57         def selectionMade(self):
58                 print "selection made"
59                 #self.installPackage(int(index))
60                 indexList = []
61                 for x in range(len(self.packagesConfig)):
62                         if self.packagesConfig[x].value:
63                                 indexList.append(x)
64                 self.installPackages(indexList)
65                 
66 class DreamPackageWizard(DefaultWizard):
67         def __init__(self, session, packagefile, silent = False):
68                 os.system("mkdir /tmp/package")
69                 os.system("tar xpzf %s -C /tmp/package" % packagefile)
70                 self.packagefile = packagefile
71                 DefaultWizard.__init__(self, session, silent)
72                 
73         def setDirectory(self):
74                 self.directory = "/tmp/package"
75                 self.xmlfile = "dreampackagewizard.xml"
76                 
77 class ImageDefaultInstaller(DreamInfoHandler):
78         def __init__(self):
79                 DreamInfoHandler.__init__(self, self.statusCallback, blocking = True)
80                 self.directory = resolveFilename(SCOPE_DEFAULTDIR)
81                 self.fillPackagesList()
82                 self.installPackage(0)
83                 
84         def statusCallback(self, status, progress):
85                 pass
86
87 def install(choice):
88         if choice is not None:
89                 #os.system("mkdir /tmp/package && tar xpzf %s ")
90                 choice[2].open(DreamPackageWizard, choice[1])
91
92 def filescan_open(list, session, **kwargs):
93         from Screens.ChoiceBox import ChoiceBox
94         print "open default wizard"
95         filelist = [(os.path.split(x.path)[1], x.path, session) for x in list]
96         print filelist
97         session.openWithCallback(install, ChoiceBox, title = _("Please choose he package..."), list=filelist)
98
99 def filescan(**kwargs):
100         from Components.Scanner import Scanner, ScanPath
101         from mimetypes import add_type
102         add_type("application/x-dream-package", "dmpkg")
103         return \
104                 Scanner(mimetypes = ["application/x-dream-package"], 
105                         paths_to_scan = 
106                                 [
107                                         ScanPath(path = "dmpkg", with_subdirs = True), 
108                                         ScanPath(path = "", with_subdirs = False), 
109                                 ], 
110                         name = "Dream-Package", 
111                         description = "Install settings, skins, software...", 
112                         openfnc = filescan_open, )
113
114 print "add dreampackage scanner plugin"
115 plugins.addPlugin(PluginDescriptor(name="Dream-Package", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan, internal = True))
116 print "added"
117
118 wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value, priority = 6)
119
120 if config.misc.defaultchosen.value:
121         print "Installing image defaults"
122         installer = ImageDefaultInstaller()
123         print "installing done!"