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