4.2.0r4/r5
[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 if checkConfigBackup() is None:
60         backupAvailable = 0
61 else:
62         backupAvailable = 1
63
64 class ImageWizard(WizardLanguage, Rc):
65         skin = """
66                 <screen name="ImageWizard" position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
67                         <widget name="text" position="153,40" size="340,330" font="Regular;22" />
68                         <widget source="list" render="Listbox" position="43,340" size="490,180" scrollbarMode="showOnDemand" >
69                                 <convert type="StringList" />
70                         </widget>
71                         <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
72                         <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
73                         <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
74                         <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
75                         <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" />
76                         <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
77                         <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
78                         <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
79                         <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
80                 </screen>"""
81         def __init__(self, session):
82                 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SoftwareManager/imagewizard.xml")
83                 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
84                 Rc.__init__(self)
85                 self.session = session
86                 self["wizard"] = Pixmap()
87                 self.selectedDevice = None
88                 
89         def markDone(self):
90                 pass
91
92         def listDevices(self):
93                 list = [ (r.description, r.mountpoint) for r in harddiskmanager.getMountedPartitions(onlyhotplug = False)]
94                 for x in list:
95                         result = access(x[1], W_OK) and access(x[1], R_OK)
96                         if result is False or x[1] == '/':
97                                 list.remove(x)
98                 for x in list:
99                         if x[1].startswith('/autofs/'):
100                                 list.remove(x)  
101                 return list
102
103         def deviceSelectionMade(self, index):
104                 self.deviceSelect(index)
105                 
106         def deviceSelectionMoved(self):
107                 self.deviceSelect(self.selection)
108                 
109         def deviceSelect(self, device):
110                 self.selectedDevice = device
111                 config.plugins.configurationbackup.backuplocation.value = self.selectedDevice
112                 config.plugins.configurationbackup.backuplocation.save()
113                 config.plugins.configurationbackup.save()
114
115         
116 if config.misc.firstrun.value:
117         wizardManager.registerWizard(ImageWizard, backupAvailable, priority = 10)
118