4.2.1r16
[enigma2.git] / usr / lib / enigma2 / python / Plugins / SystemPlugins / SoftwareManager / ImageWizard.py
1 from Screens.WizardLanguage import WizardLanguage
2 from Screens.Wizard import wizardManager
3 from Screens.Rc import Rc
4 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS
5 from Components.Pixmap import Pixmap
6 from os import access, W_OK, R_OK
7 from enigma import eEnv
8
9 from Components.config import config, ConfigSubsection, ConfigText, ConfigLocations, ConfigBoolean
10 from Components.Harddisk import harddiskmanager
11
12 config.misc.firstrun = ConfigBoolean(default = True)
13 config.plugins.configurationbackup = ConfigSubsection()
14 config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False)
15 config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/hostname'])
16
17
18 backupfile = "enigma2settingsbackup.tar.gz"
19
20 def checkConfigBackup():
21         parts = [ (p.description, p.mountpoint) for p in harddiskmanager.getMountedPartitions() if p.mountpoint != "/"]
22         parts.extend([ ( hd.model(), harddiskmanager.getAutofsMountpoint(hd.device + str(hd.numPartitions())) ) for hd in harddiskmanager.hdd if harddiskmanager.getAutofsMountpoint(hd.device + str(hd.numPartitions())) not in parts ])
23
24
25         if len(parts):
26                 for x in parts:
27                         if x[1].endswith('/'):
28                                 fullbackupfile =  x[1] + 'backup/' + backupfile
29                                 if fileExists(fullbackupfile):
30                                         config.plugins.configurationbackup.backuplocation.value = str(x[1])
31                                         config.plugins.configurationbackup.backuplocation.save()
32                                         config.plugins.configurationbackup.save()
33                                         return x
34                         else:
35                                 fullbackupfile =  x[1] + '/backup/' + backupfile
36                                 if fileExists(fullbackupfile):
37                                         config.plugins.configurationbackup.backuplocation.value = str(x[1])
38                                         config.plugins.configurationbackup.backuplocation.save()
39                                         config.plugins.configurationbackup.save()
40                                         return x
41                 return None
42         return None             
43
44 def checkBackupFile():
45         backuplocation = config.plugins.configurationbackup.backuplocation.value
46         if backuplocation.endswith('/'):
47                 fullbackupfile =  backuplocation + 'backup/' + backupfile
48                 if fileExists(fullbackupfile):
49                         return True
50                 else:
51                         return False
52         else:
53                 fullbackupfile =  backuplocation + '/backup/' + backupfile
54                 if fileExists(fullbackupfile):
55                         return True
56                 else:
57                         return False
58
59 class ImageWizard(WizardLanguage, Rc):
60         skin = """
61                 <screen name="ImageWizard" position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
62                         <widget name="text" position="153,40" size="340,330" font="Regular;22" />
63                         <widget source="list" render="Listbox" position="43,340" size="490,180" scrollbarMode="showOnDemand" >
64                                 <convert type="StringList" />
65                         </widget>
66                         <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
67                         <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
68                         <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
69                         <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
70                         <widget name="rc" pixmaps="skin_default/rc0.png,skin_default/rc1.png,skin_default/rc2.png" position="530,50" zPosition="10" size="154,500" alphatest="on" />
71                         <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
72                         <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
73                         <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
74                         <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
75                 </screen>"""
76         def __init__(self, session):
77                 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/imagewizard.xml")
78                 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
79                 Rc.__init__(self)
80                 self.session = session
81                 self["wizard"] = Pixmap()
82                 self.selectedDevice = None
83                 
84         def markDone(self):
85                 pass
86
87         def listDevices(self):
88                 list = [ (r.description, r.mountpoint) for r in harddiskmanager.getMountedPartitions(onlyhotplug = False)]
89                 for x in list:
90                         result = access(x[1], W_OK) and access(x[1], R_OK)
91                         if result is False or x[1] == '/':
92                                 list.remove(x)
93                 for x in list:
94                         if x[1].startswith('/autofs/'):
95                                 list.remove(x)  
96                 return list
97
98         def deviceSelectionMade(self, index):
99                 self.deviceSelect(index)
100                 
101         def deviceSelectionMoved(self):
102                 self.deviceSelect(self.selection)
103                 
104         def deviceSelect(self, device):
105                 self.selectedDevice = device
106                 config.plugins.configurationbackup.backuplocation.value = self.selectedDevice
107                 config.plugins.configurationbackup.backuplocation.save()
108                 config.plugins.configurationbackup.save()
109
110 wizardManager.registerWizard(ImageWizard, config.misc.firstrun.value, priority = 10)
111