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