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