Пример #1
0
def getTrashFolder(path = None):
    try:
        if path is None or os.path.realpath(path) == '/media/autofs':
            print 'path is none'
            return ''
        if '/movie' in path:
            mountpoint = Harddisk.findMountPoint(os.path.realpath(path))
            trashcan = os.path.join(mountpoint, 'movie')
        else:
            trashcan = Harddisk.findMountPoint(os.path.realpath(path))
        return os.path.realpath(os.path.join(trashcan, '.Trash'))
    except:
        return
Пример #2
0
def getTrashFolder(path=None):
	# Returns trash folder without symlinks
	try:
		if path is None:
			print 'path is none'
		else:
			if path.find('/movie') >0:
				mountpoint = Harddisk.findMountPoint(os.path.realpath(path))
				trashcan = os.path.join(mountpoint, 'movie')
			else:
				trashcan = Harddisk.findMountPoint(os.path.realpath(path))
			return os.path.realpath(os.path.join(trashcan, ".Trash"))
	except:
		return ""
Пример #3
0
def getTrashFolder(path=None):
    # Returns trash folder without symlinks
    try:
        print "PATH:", path
        if path is None or os.path.realpath(path) == "/media/autofs":
            print "path is none"
        else:
            if "/movie" in path:
                mountpoint = Harddisk.findMountPoint(os.path.realpath(path))
                trashcan = os.path.join(mountpoint, "movie")
            else:
                trashcan = Harddisk.findMountPoint(os.path.realpath(path))
            return os.path.realpath(os.path.join(trashcan, ".Trash"))
    except:
        return ""
Пример #4
0
def getTrashFolder(path=None):
	# Returns trash folder without symlinks
	try:
		if path is None or os.path.realpath(path) == '/media/autofs':
			print 'path is none'
			return ""
		else:
			if '/movie' in path:
				mountpoint = Harddisk.findMountPoint(os.path.realpath(path))
				trashcan = os.path.join(mountpoint, 'movie')
			else:
				trashcan = Harddisk.findMountPoint(os.path.realpath(path))
			return os.path.realpath(os.path.join(trashcan, ".Trash"))
	except:
		return None
Пример #5
0
def defaultRecordingLocation(candidate=None):
	if candidate and os.path.exists(candidate):
		return candidate
	# First, try whatever /hdd points to, or /media/hdd
	try:
		path = os.path.realpath("/hdd")
	except:
		path = '/media/hdd'
	if not os.path.exists(path):
		path = ''
		# Find the largest local disk
		from Components import Harddisk
		mounts = [m for m in Harddisk.getProcMounts() if m[1].startswith('/media/')]
		# Search local devices first, use the larger one
		path = bestRecordingLocation([m for m in mounts if m[0].startswith('/dev/')])
		# If we haven't found a viable candidate yet, try remote mounts
		if not path:
			path = bestRecordingLocation(mounts)
	if path:
		# If there's a movie subdir, we'd probably want to use that.
		movie = os.path.join(path, 'movie')
		if os.path.isdir(movie):
			path = movie
		if not path.endswith('/'):
			path += '/' # Bad habits die hard, old code relies on this
	return path
Пример #6
0
def defaultRecordingLocation(candidate = None):
    if candidate and os.path.exists(candidate):
        return candidate
    try:
        path = os.readlink('/hdd')
    except:
        path = '/media/hdd'

    if not os.path.exists(path):
        path = ''
        from Components import Harddisk
        mounts = [ m for m in Harddisk.getProcMounts() if m[1].startswith('/media/') ]
        biggest = 0
        havelocal = False
        for candidate in mounts:
            try:
                islocal = candidate[1].startswith('/dev/')
                stat = os.statvfs(candidate[1])
                size = (stat.f_blocks + stat.f_bavail) * stat.f_bsize
                if islocal and not havelocal or islocal or not havelocal and size > biggest:
                    path = candidate[1]
                    havelocal = islocal
                    biggest = size
            except Exception as e:
                print '[DRL]', e

    if path:
        movie = os.path.join(path, 'movie')
        if os.path.isdir(movie):
            path = movie
        if not path.endswith('/'):
            path += '/'
    return path
Пример #7
0
	def __init__(self,session,testitem):
		Screen.__init__(self, session)
		self.testitem = testitem
		self.devpath = "mmcblk0"
		self.usbdevice = Harddisk(self.devpath)
		self.usbdevicename = self.usbdevice.model()
		self.usbsize= self.usbdevice.capacity()
#		self.usbfreesize = (stat.f_bfree/1000) * (stat.f_bsize/1000)
		self.usbfreesize = self.usbdevice.free()
		
		print "usbdevicename:",self.usbdevicename
		
		print "usbsize:",self.usbsize

		print "usbfreesize",self.usbfreesize

		self["usbtitle"] = StaticText("SDCard Device:"+self.usbdevicename)
		self["usbname"] = StaticText("CardInfor: "+self.usbdevicename)
		self["usbsize"] = StaticText("Card Size: "+self.usbsize)
		self["usbfreesize"]=StaticText(_("Free Size: %d M") % (self.usbfreesize))
		
		self["actions"] = ActionMap(["SetupActions", "ColorActions"], 
			{
				"cancel": self.testfinish,
				"ok": self.testfinish
			})
Пример #8
0
def getTrashFolder(path):
	# Returns trash folder without symlinks. Path may be file or directory or whatever.
	mountpoint = Harddisk.findMountPoint(os.path.realpath(path))
	movie = os.path.join(mountpoint, 'movie')
	if os.path.isdir(movie):
		mountpoint = movie
	return os.path.join(mountpoint, ".Trash")
Пример #9
0
def defaultRecordingLocation(candidate=None):
	if candidate and os.path.exists(candidate):
		return candidate
	# First, try whatever /hdd points to, or /media/hdd
	try:
		path = os.readlink('/hdd')
	except:
		path = '/media/hdd'
	if not os.path.exists(path):
		path = ''
		# Find the largest local disk
		from Components import Harddisk
		mounts = [m for m in Harddisk.getProcMounts() if m[1].startswith('/media/')]
		biggest = 0
		havelocal = False
		for candidate in mounts:
			try:
				islocal = candidate[1].startswith('/dev/') # Good enough
				stat = os.statvfs(candidate[1])
				# Free space counts double
				size = (stat.f_blocks + stat.f_bavail) * stat.f_bsize
				if (islocal and not havelocal) or (islocal or not havelocal and size > biggest):
					path = candidate[1]
					havelocal = islocal
					biggest = size
			except Exception, e:
				print "[DRL]", e
Пример #10
0
	def save(self):
		print "[MultiBootStartup] select new startup: ", self.list[self.selection]
		ret = system("cp -f '/boot/%s' /boot/STARTUP" %self.list[self.selection])
		if ret:
			self.session.open(MessageBox, _("File '/boot/%s' copy to '/boot/STARTUP' failed!") %self.list[self.selection], MessageBox.TYPE_ERROR)
			self.getCurrent()
			return

		writeoption = already = failboot = False
		newboot = boot = self.readlineFile('/boot/STARTUP')

		if self.checkBootEntry(boot):
			failboot = True
		elif self.option_enabled:
			for x in self.optionsList:
				if (x[0] + "'" in boot or x[0] + " " in boot) and x[0] != self.optionsList[self.option][0]:
					newboot = boot.replace(x[0],self.optionsList[self.option][0])
					writeoption = True
					break
				elif (x[0] + "'" in boot or x[0] + " " in boot) and x[0] == self.optionsList[self.option][0]:
					already = True
					break
			if not (writeoption or already):
				if "boxmode" in boot:
					failboot = True
				elif self.option:
					newboot = boot.replace("rootwait", "rootwait hd51_4.%s" %(self.optionsList[self.option][0]))
					writeoption = True

		if self.enable_bootnamefile:
			if failboot:
				self.writeFile('/boot/bootname', 'STARTUP_1=STARTUP_1')
			else:
				self.writeFile('/boot/bootname', '%s=%s' %('STARTUP_%s' %boot[22:23], self.list[self.selection]))

		message = _("Do you want to reboot now with selected image?")
		if failboot:
			print "[MultiBootStartup] wrong bootsettings: " + boot
			if '/dev/mmcblk0p3' in Harddisk.getextdevices("ext4"):
				if self.writeFile('/boot/STARTUP', "boot emmcflash0.kernel1 'root=/dev/mmcblk0p3 rw rootwait'"):
					txt = _("Next boot will start from Image 1.")
				else:
					txt =_("Can not repair file %s") %("'/boot/STARTUP'") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
			else:
				txt = _("Alternative Image 1 partition for boot repair not found.") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
			message = _("Wrong Bootsettings detected!") + "\n\n%s\n\n%s\n" %(boot, txt) + _("Do you want to reboot now?")
		elif writeoption:
			if not self.writeFile('/boot/STARTUP', newboot):
				txt = _("Can not write file %s") %("'/boot/STARTUP'") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
				message = _("Write error!") + "\n\n%s\n\n%s\n" %(boot, txt) + _("Do you want to reboot now?")

		#verify boot
		if failboot or writeoption:
			boot = self.readlineFile('/boot/STARTUP')
			if self.checkBootEntry(boot):
				txt = _("Error in file %s") %("'/boot/STARTUP'") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
				message = _("Command line error!") + "\n\n%s\n\n%s\n" %(boot, txt) + _("Do you want to reboot now?")

		self.session.openWithCallback(self.restartBOX,MessageBox, message, MessageBox.TYPE_YESNO)
Пример #11
0
class SDCardTest(Screen):
	skin = """
		<screen name="SDCardTest" position="220,57" size="840,605" title="SDCardTest" flags="wfNoBorder">
			<ePixmap position="0,0" zPosition="-10" size="1100,605" pixmap="DMConcinnity-HD-Transp/menu/setupbg.png" />
			<widget source="global.CurrentTime" render="Label" position="20,20" size="80,25" font="Regular;23" foregroundColor="black" backgroundColor="grey" transparent="1">
				<convert type="ClockToText">Default</convert>
			</widget>
			<widget source="global.CurrentTime" render="Label" position="110,20" size="140,25" font="Regular;23" foregroundColor="blue" backgroundColor="grey" transparent="1">
				<convert type="ClockToText">Format:%d.%m.%Y</convert>
			</widget>
			<eLabel text="USB information" position="270,20" size="540,43" font="Regular;35" halign="right" foregroundColor="black" backgroundColor="grey" transparent="1" />
			<widget source="usbtitle" render="Label" position="110,145" size="700,35" font="Regular;26" foregroundColor="yellow" backgroundColor="transpBlack" transparent="1" />
			<widget source="usbname" render="Label" position="140,190" size="700,30" font="Regular;24" backgroundColor="transpBlack" transparent="1" />
			<widget source="usbsize" render="Label" position="140,220" size="700,30" font="Regular;24" backgroundColor="transpBlack" transparent="1" />
			<widget source="usbfreesize" render="Label" position="140,250" size="700,30" font="Regular;24" backgroundColor="transpBlack" transparent="1" />
		</screen>"""
	def __init__(self,session,testitem):
		Screen.__init__(self, session)
		self.testitem = testitem
		self.devpath = "mmcblk0"
		self.usbdevice = Harddisk(self.devpath)
		self.usbdevicename = self.usbdevice.model()
		self.usbsize= self.usbdevice.capacity()
#		self.usbfreesize = (stat.f_bfree/1000) * (stat.f_bsize/1000)
		self.usbfreesize = self.usbdevice.free()
		
		print "usbdevicename:",self.usbdevicename
		
		print "usbsize:",self.usbsize

		print "usbfreesize",self.usbfreesize

		self["usbtitle"] = StaticText("SDCard Device:"+self.usbdevicename)
		self["usbname"] = StaticText("CardInfor: "+self.usbdevicename)
		self["usbsize"] = StaticText("Card Size: "+self.usbsize)
		self["usbfreesize"]=StaticText(_("Free Size: %d M") % (self.usbfreesize))
		
		self["actions"] = ActionMap(["SetupActions", "ColorActions"], 
			{
				"cancel": self.testfinish,
				"ok": self.testfinish
			})

	def testfinish(self):
		self.testitem.setTestResult(FactoryTestItem.TESTRESULT_OK)
		self.close()
Пример #12
0
	def list_files(self, PATH):
		files = []
		self.path = PATH
		for name in listdir(self.path):
			if path.isfile(path.join(self.path, name)):
				cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
				if cmdline in Harddisk.getextdevices("ext4") and not name == "STARTUP":
					files.append(name)
		return files
Пример #13
0
	def list_files(self, PATH):
		files = []
		self.path = PATH
		for name in listdir(self.path):
			if path.isfile(path.join(self.path, name)):
				cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
				if cmdline in Harddisk.getextdevices("ext4") and not name == "STARTUP":
					files.append(name)
		return files
Пример #14
0
    def list_files(self, PATH):
        files = []
        self.path = PATH
        for name in listdir(self.path):
            if path.isfile(path.join(self.path, name)):
                cmdline = self.read_startup('/boot/' + name).split('=', 1)[1].split(' ', 1)[0]
                if cmdline in Harddisk.getextdevices('ext4') and not name == 'cmdline.txt':
                    files.append(name)

        return files
Пример #15
0
 def onRemoteRootFS(self):
     if self.remoteRootFS is None:
         from Components import Harddisk
         for parts in Harddisk.getProcMounts():
             if parts[1] == '/' and parts[2] == 'nfs':
                 self.remoteRootFS = True
                 break
         else:
             self.remoteRootFS = False
     return self.remoteRootFS
Пример #16
0
    def isUsbRecordingPath(self):
        dirname = None

        if self.dirname:
            dirname = findSafeRecordPath(self.dirname)

        if dirname is None:
            dirname = findSafeRecordPath(defaultMoviePath())

        from Components import Harddisk
        return Harddisk.isUsbStorage(dirname)
Пример #17
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			for name in listdir(self.path):
				if path.isfile(path.join(self.path, name)):
					cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
					if cmdline in Harddisk.getextdevices("ext4"):
						files.append(name)
			files.append("Recovery")
		return files
Пример #18
0
	def start(self):
		self.currentSelected = self["config"].l.getCurrentSelection()
		title = _("Please select a backup destination")
		choices = []
		retval = []
		if self.currentSelected[0][1] != "Queued":
			for media in ['/media/%s' % x for x in os.listdir('/media')] + (['/media/net/%s' % x for x in os.listdir('/media/net')] if os.path.isdir('/media/net') else []):
				if Harddisk.Freespace(media) > 300000:
					choices.append((_("Backup to destination: %s") % (media),self.currentSelected[0][1], media, self.currentSelected[0][2]))
			choices.append((_("No, do not backup a image"), False))
			self.session.openWithCallback(self.doFullBackup, ChoiceBox,title=title,list=choices)
Пример #19
0
	def list_files(self, PATH):
		files = []
		for name in listdir(PATH):
			if path.isfile(path.join(PATH, name)):
				try:
					cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
				except IndexError:
					continue
				if cmdline in Harddisk.getextdevices("ext4") and not name == "STARTUP":
					files.append(name)
		return files
Пример #20
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			for name in listdir(self.path):
				if path.isfile(path.join(self.path, name)):
					cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
					if cmdline in Harddisk.getextdevices("ext4"):
						files.append(name)
			files.append("Recovery")
		return files
Пример #21
0
	def list_files(self, PATH):
		files = []
		for name in listdir(PATH):
			if path.isfile(path.join(PATH, name)):
				try:
					cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
				except IndexError:
					continue
				if cmdline in Harddisk.getextdevices("ext4") and not name == "STARTUP":
					files.append(name)
		return files
Пример #22
0
def enumTrashFolders():
    # Walk through all Trash folders. This may access network
    # drives and similar, so might block for minutes.
    for mount in Harddisk.getProcMounts():
        if mount[1].startswith('/media/'):
            mountpoint = mount[1]
            movie = os.path.join(mountpoint, 'movie')
            if os.path.isdir(movie):
                mountpoint = movie
            result = os.path.join(mountpoint, ".Trash")
            if os.path.isdir(result):
                yield result
Пример #23
0
def enumTrashFolders():
	# Walk through all Trash folders. This may access network
	# drives and similar, so might block for minutes.
	for mount in Harddisk.getProcMounts():
		if mount[1].startswith('/media/'):
			mountpoint = mount[1]
			movie = os.path.join(mountpoint, 'movie')
			if os.path.isdir(movie):
				mountpoint = movie
			result = os.path.join(mountpoint, ".Trash")
			if os.path.isdir(result):
				yield result
Пример #24
0
def findSafeRecordPath(dirname):
	from Components import Harddisk
	dirname = os.path.realpath(dirname)
	mountpoint = Harddisk.findMountPoint(dirname)
	if mountpoint in ('/', '/media'):
		print '[RecordTimer] media is not mounted:', dirname
		return None
	if not os.path.isdir(dirname):
		try:
			os.makedirs(dirname)
		except Exception, ex:
			print '[RecordTimer] Failed to create dir "%s":' % dirname, ex
			return None
Пример #25
0
def findSafeRecordPath(dirname):
    from Components import Harddisk
    dirname = os.path.realpath(dirname)
    mountpoint = Harddisk.findMountPoint(dirname)
    if mountpoint in ('/', '/media'):
        print '[RecordTimer] media is not mounted:', dirname
        return None
    if not os.path.isdir(dirname):
        try:
            os.makedirs(dirname)
        except Exception, ex:
            print '[RecordTimer] Failed to create dir "%s":' % dirname, ex
            return None
Пример #26
0
def findSafeRecordPath(dirname):
	if not dirname:
		return None
	dirname = os.path.realpath(dirname)
	mountpoint = Harddisk.findMountPoint(dirname)
	if not os.path.ismount(mountpoint):
		print '[RecordTimer] media is not mounted:', dirname
		return None
	if not os.path.isdir(dirname):
		try:
			os.makedirs(dirname)
		except Exception, ex:
			print '[RecordTimer] Failed to create dir "%s":' % dirname, ex
			return None
Пример #27
0
def findSafeRecordPath(dirname):
	if not dirname:
		return None
	dirname = os.path.realpath(dirname)
	mountpoint = Harddisk.findMountPoint(dirname)
	if not os.path.ismount(mountpoint):
		print '[RecordTimer] media is not mounted:', dirname
		return None
	if not os.path.isdir(dirname):
		try:
			os.makedirs(dirname)
		except Exception, ex:
			print '[RecordTimer] Failed to create dir "%s":' % dirname, ex
			return None
Пример #28
0
    def list_files(self, PATH):
        files = []
        for name in listdir(PATH):
            if path.isfile(path.join(PATH, name)):
                try:
                    cmdline = self.read_startup('/boot/' + name).split(
                        '=', 3)[3].split(' ', 1)[0]
                except IndexError:
                    continue

                if cmdline in Harddisk.getextdevices(
                        'ext4') and not name == 'STARTUP':
                    files.append(name)

        return files
Пример #29
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			for name in listdir(self.path):
				if path.isfile(path.join(self.path, name)):
					if self.MACHINEBUILD in ("hd51","vs1500","h7","ceryon7252"):
						cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
					else:
						cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
					if cmdline in Harddisk.getextdevices("ext4"):
						files.append(name)
			if getMachineBuild() not in ("gb7252"):
				files.append("Recovery")
		return files
Пример #30
0
def getTrashFolder(path=None):
	# Returns trash folder without symlinks
	try:
		if path is None or os.path.realpath(path) == '/media/autofs':
			print 'path is none'
			return ""
		else:
			trashcan = Harddisk.findMountPoint(os.path.realpath(path))
			if '/movie' in path:
				trashcan = os.path.join(trashcan, 'movie')
			elif config.usage.default_path.value in path:
				# if default_path happens to not be the default /hdd/media/movie, then we can have a trash folder there instead
				trashcan = os.path.join(trashcan, config.usage.default_path.value)
			return os.path.realpath(os.path.join(trashcan, ".Trash"))
	except:
		return None
Пример #31
0
def getTrashFolder(path=None):
	# Returns trash folder without symlinks
	try:
		if path is None or os.path.realpath(path) == '/media/autofs':
			print('[Trashcan] path is none')
			return ""
		else:
			trashcan = Harddisk.findMountPoint(os.path.realpath(path))
			if '/movie' in path:
				trashcan = os.path.join(trashcan, 'movie')
			elif config.usage.default_path.value in path:
				# if default_path happens to not be the default /hdd/media/movie, then we can have a trash folder there instead
				trashcan = os.path.join(trashcan, config.usage.default_path.value)
			return os.path.realpath(os.path.join(trashcan, ".Trash"))
	except:
		return None
Пример #32
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			for name in listdir(self.path):
				if path.isfile(path.join(self.path, name)):
					if self.MACHINEBUILD in ("hd51","vs1500","h7"):
						cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
					elif self.MACHINEBUILD in ("8100s"):
						cmdline = self.read_startup("/boot/" + name).split("=",4)[4].split(" ",1)[0]
					else:
						cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
					if cmdline in Harddisk.getextdevices("ext4"):
						files.append(name)
			if getMachineBuild() not in ("gb7252"):
				files.append("Recovery")
		return files
Пример #33
0
def defaultRecordingLocation(candidate=None):
	if candidate and pathExists(candidate):
		return candidate
	try:
		path = readlink("/hdd")  # First, try whatever /hdd points to, or /media/hdd.
	except OSError as err:
		path = "/media/hdd"
	if not pathExists(path):  # Find the largest local disk.
		from Components import Harddisk
		mounts = [mount for mount in Harddisk.getProcMounts() if mount[1].startswith("/media/")]
		path = bestRecordingLocation([mount for mount in mounts if mount[0].startswith("/dev/")])  # Search local devices first, use the larger one.
		if not path:  # If we haven't found a viable candidate yet, try remote mounts.
			path = bestRecordingLocation([mount for mount in mounts if not mount[0].startswith("/dev/")])
	if path:
		movie = pathjoin(path, "movie", "")  # If there's a movie subdir, we'd probably want to use that (directories need to end in sep).
		if isdir(movie):
			path = movie
	return path
Пример #34
0
 def checkBootEntry(self, ENTRY):
     try:
         ret = False
         temp = ENTRY.split(' ')
         #read kernel, root as number and device name
         kernel = int(temp[1].split("emmcflash0.kernel")[1])
         root = int(temp[2].split("'root=/dev/mmcblk0p")[1])
         device = temp[2].split("=")[1]
         #read boxmode and new boxmode settings
         cmdx = 5
         cmd4 = "rootwait'"
         bootmode = '1'
         if 'boxmode' in ENTRY:
             cmdx = 6
             cmd4 = "rootwait"
             bootmode = temp[5].split(
                 "%s_4.boxmode=" % getMachineBuild())[1].replace("'", '')
         setmode = self.optionsList[self.option][0].split('=')[1]
         #verify entries
         if cmdx != len(temp) or 'boot' != temp[0] or 'rw' != temp[
                 3] or cmd4 != temp[
                     4] or kernel != root - kernel - 1 or "'" != ENTRY[-1:]:
             print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with not matching entries!"
             ret = True
         #verify length
         elif ('boxmode' not in ENTRY
               and len(ENTRY) > 58) or ('boxmode' in ENTRY
                                        and len(ENTRY) > 76):
             print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with line length!"
             ret = True
         #verify boxmode
         elif bootmode != setmode and not self.option_enabled:
             print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with unsupported boxmode!"
             ret = True
         #verify device
         elif not device in Harddisk.getextdevices("ext4"):
             print "[MultiBootStartup] Command line in '/boot/STARTUP' - boot device not exist!"
             ret = True
     except:
         print "[MultiBootStartup] Command line in '/boot/STARTUP' - unknown problem!"
         ret = True
     return ret
Пример #35
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			for name in listdir(self.path):
				if path.isfile(path.join(self.path, name)):
					try:
						if self.MACHINEBUILD in ("hd51","vs1500","h7"):
							cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
						elif self.MACHINEBUILD in ("8100s"):
							cmdline = self.read_startup("/boot/" + name).split("=",4)[4].split(" ",1)[0]
						else:
							cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
						if cmdline in Harddisk.getextdevices("ext4"):
							files.append(name)
					except IndexError:
						print '[ImageBackup] - IndexError in file: %s' %name
						self.error_files += '/boot/' + name + ', ' 
			if getMachineBuild() not in ("gb7252"):
				files.append("Recovery")
		return files
Пример #36
0
def defaultRecordingLocation(candidate=None):
	if candidate and os.path.exists(candidate):
		return candidate
	# First, try whatever /hdd points to, or /media/hdd
	try:
		path = os.path.realpath('/hdd')
	except:
		path = '/media/hdd'
	if not os.path.exists(path) or not os.path.ismount(path):
		path = ''
		from Components import Harddisk
		mounts = [m for m in Harddisk.getProcMounts() if m[1].startswith('/media/')]
		path = bestRecordingLocation([m for m in mounts if m[0].startswith('/dev/')])
	if path:
		# If there's a movie subdir, we'd probably want to use that.
		movie = os.path.join(path, 'movie')
		if os.path.isdir(movie):
			path = movie
		if not path.endswith('/'):
			path += '/' # Bad habits die hard, old code relies on this

	return path
Пример #37
0
def defaultRecordingLocation(candidate=None):
    if candidate and os.path.exists(candidate):
        return candidate
    # First, try whatever /hdd points to, or /media/hdd
    try:
        path = os.readlink('/hdd')
    except:
        path = '/media/hdd'
    if not os.path.exists(path):
        path = ''
        # Find the largest local disk
        from Components import Harddisk
        mounts = [
            m for m in Harddisk.getProcMounts() if m[1].startswith('/media/')
        ]
        biggest = 0
        havelocal = False
        for candidate in mounts:
            try:
                islocal = candidate[1].startswith('/dev/')  # Good enough
                stat = os.statvfs(candidate[1])
                # Free space counts double
                size = (stat.f_blocks + stat.f_bavail) * stat.f_bsize
                if (islocal and not havelocal) or (islocal or not havelocal
                                                   and size > biggest):
                    path = candidate[1]
                    havelocal = islocal
                    biggest = size
            except Exception as e:
                print("[DRL]", e)
    if path:
        # If there's a movie subdir, we'd probably want to use that.
        movie = os.path.join(path, 'movie')
        if os.path.isdir(movie):
            path = movie
        if not path.endswith('/'):
            path += '/'  # Bad habits die hard, old code relies on this
    return path
Пример #38
0
	def list_files(self, PATH):
		files = []
		if SystemInfo["HaveMultiBoot"]:
			self.path = PATH
			if SystemInfo["HasRootSubdir"]:
				for name in listdir(self.path):
					if path.isfile(path.join(self.path, name)):
						try:
							cmdline = self.find_rootfssubdir(name)
							if cmdline == None:
								continue
						except IndexError:
							continue
						cmdline_startup = self.find_rootfssubdir("STARTUP")
						if (cmdline != cmdline_startup) and (name != "STARTUP"):
							files.append(name)
				files.insert(0,"STARTUP")
			else:
				for name in listdir(self.path):
					if path.isfile(path.join(self.path, name)):
						try:
							if self.MACHINEBUILD in ("hd51","vs1500","h7"):
								cmdline = self.read_startup("/boot/" + name).split("=",3)[3].split(" ",1)[0]
							elif self.MACHINEBUILD in ("8100s"):
								cmdline = self.read_startup("/boot/" + name).split("=",4)[4].split(" ",1)[0]
							else:
								cmdline = self.read_startup("/boot/" + name).split("=",1)[1].split(" ",1)[0]
							if cmdline in Harddisk.getextdevices("ext4"):
								files.append(name)
						except IndexError:
							print '[ImageBackup] - IndexError in file: %s' %name
							self.error_files += '/boot/' + name + ', ' 
				if getMachineBuild() not in ("gb7252"):
					files.append("Recovery")
		else:
			files = "None"
		return files
Пример #39
0
	def checkBootEntry(self, ENTRY):
		try:
			ret = False
			temp = ENTRY.split(' ')
			#read kernel, root as number and device name
			kernel = int(temp[1].split("emmcflash0.kernel")[1])
			root = int(temp[4].split("root=/dev/mmcblk0p")[1])
			device = temp[4].split("=")[1]
			#read boxmode and new boxmode settings
			cmdx = 7
			cmd4 = "rootwait'"
			bootmode = '1'
			if 'boxmode' in ENTRY:
				cmdx = 8
				cmd4 = "rootwait"
				bootmode = temp[7].split("%s_4.boxmode=" %getMachineBuild())[1].replace("'",'')
			setmode = self.optionsList[self.option][0].split('=')[1]
			#verify entries
			if cmdx != len(temp) or 'boot' != temp[0] or 'rw' != temp[5] or cmd4 != temp[6] or kernel != root-kernel-1 or "'" != ENTRY[-1:]:
				print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with not matching entries!"
				ret = True
			#verify length
			elif ('boxmode' not in ENTRY and len(ENTRY) > 96) or ('boxmode' in ENTRY and len(ENTRY) > 115):
				print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with line length!"
				ret = True
			#verify boxmode
			elif bootmode != setmode and not self.option_enabled:
				print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with unsupported boxmode!"
				ret = True
			#verify device
			elif not device in Harddisk.getextdevices("ext4"):
				print "[MultiBootStartup] Command line in '/boot/STARTUP' - boot device not exist!"
				ret = True
		except:
			print "[MultiBootStartup] Command line in '/boot/STARTUP' - unknown problem!"
			ret = True
		return ret
Пример #40
0
    def checkBootEntry(self, ENTRY):
        try:
            ret = False
            temp = ENTRY.split(' ')
            kernel = int(temp[1].split('emmcflash0.kernel')[1])
            root = int(temp[4].split('root=/dev/mmcblk0p')[1])
            device = temp[4].split('=')[1]
            cmdx = 7
            cmd4 = "rootwait'"
            bootmode = '1'
            if 'boxmode' in ENTRY:
                cmdx = 8
                cmd4 = 'rootwait'
                bootmode = temp[7].split(
                    '%s_4.boxmode=' % getMachineBuild())[1].replace("'", '')
            setmode = self.optionsList[self.option][0].split('=')[1]
            if cmdx != len(temp) or 'boot' != temp[0] or 'rw' != temp[
                    5] or cmd4 != temp[
                        6] or kernel != root - kernel - 1 or "'" != ENTRY[-1:]:
                print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with not matching entries!"
                ret = True
            elif 'boxmode' not in ENTRY and len(
                    ENTRY) > 96 or 'boxmode' in ENTRY and len(ENTRY) > 115:
                print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with line length!"
                ret = True
            elif bootmode != setmode and not self.option_enabled:
                print "[MultiBootStartup] Command line in '/boot/STARTUP' - problem with unsupported boxmode!"
                ret = True
            elif device not in Harddisk.getextdevices('ext4'):
                print "[MultiBootStartup] Command line in '/boot/STARTUP' - boot device not exist!"
                ret = True
        except:
            print "[MultiBootStartup] Command line in '/boot/STARTUP' - unknown problem!"
            ret = True

        return ret
Пример #41
0
    def save(self):
        print "[MultiBootStartup] select new startup: ", self.list[
            self.selection]
        ret = system("cp -f '/boot/%s' /boot/STARTUP" %
                     self.list[self.selection])
        if ret:
            self.session.open(
                MessageBox,
                _("File '/boot/%s' copy to '/boot/STARTUP' failed!") %
                self.list[self.selection], MessageBox.TYPE_ERROR)
            self.getCurrent()
            return

        writeoption = already = failboot = False
        newboot = boot = self.readlineFile('/boot/STARTUP')

        if self.checkBootEntry(boot):
            failboot = True
        elif self.option_enabled:
            for x in self.optionsList:
                if (x[0] + "'" in boot or x[0] + " "
                        in boot) and x[0] != self.optionsList[self.option][0]:
                    newboot = boot.replace(x[0],
                                           self.optionsList[self.option][0])
                    writeoption = True
                    break
                elif (x[0] + "'" in boot or x[0] + " "
                      in boot) and x[0] == self.optionsList[self.option][0]:
                    already = True
                    break
            if not (writeoption or already):
                if "boxmode" in boot:
                    failboot = True
                elif self.option:
                    newboot = boot.replace(
                        "rootwait", "rootwait hd51_4.%s" %
                        (self.optionsList[self.option][0]))
                    writeoption = True

        if self.enable_bootnamefile:
            if failboot:
                self.writeFile('/boot/bootname', 'STARTUP_1=STARTUP_1')
            else:
                self.writeFile(
                    '/boot/bootname', '%s=%s' %
                    ('STARTUP_%s' % boot[22:23], self.list[self.selection]))

        message = _("Do you want to reboot now with selected image?")
        if failboot:
            print "[MultiBootStartup] wrong bootsettings: " + boot
            if '/dev/mmcblk0p3' in Harddisk.getextdevices("ext4"):
                if self.writeFile(
                        '/boot/STARTUP',
                        "boot emmcflash0.kernel1 'root=/dev/mmcblk0p3 rw rootwait'"
                ):
                    txt = _("Next boot will start from Image 1.")
                else:
                    txt = _("Can not repair file %s") % (
                        "'/boot/STARTUP'") + "\n" + _(
                            "Caution, next boot is starts with these settings!"
                        ) + "\n"
            else:
                txt = _(
                    "Alternative Image 1 partition for boot repair not found."
                ) + "\n" + _(
                    "Caution, next boot is starts with these settings!") + "\n"
            message = _("Wrong Bootsettings detected!") + "\n\n%s\n\n%s\n" % (
                boot, txt) + _("Do you want to reboot now?")
        elif writeoption:
            if not self.writeFile('/boot/STARTUP', newboot):
                txt = _("Can not write file %s") % (
                    "'/boot/STARTUP'") + "\n" + _(
                        "Caution, next boot is starts with these settings!"
                    ) + "\n"
                message = _("Write error!") + "\n\n%s\n\n%s\n" % (
                    boot, txt) + _("Do you want to reboot now?")

        #verify boot
        if failboot or writeoption:
            boot = self.readlineFile('/boot/STARTUP')
            if self.checkBootEntry(boot):
                txt = _("Error in file %s") % ("'/boot/STARTUP'") + "\n" + _(
                    "Caution, next boot is starts with these settings!") + "\n"
                message = _("Command line error!") + "\n\n%s\n\n%s\n" % (
                    boot, txt) + _("Do you want to reboot now?")

        self.session.openWithCallback(self.restartBOX, MessageBox, message,
                                      MessageBox.TYPE_YESNO)
Пример #42
0
    def save(self):
        print "[MultiBootStartup] select new startup: ", self.list[
            self.selection]
        ret = system("cp -f '/boot/%s' /boot/STARTUP" %
                     self.list[self.selection])
        if ret:
            self.session.open(
                MessageBox,
                _("File '/boot/%s' not found - copy to /boot/STARTUP failed!")
                % self.list[self.selection], MessageBox.TYPE_ERROR)
            self.getCurrent()
            return

        newboot = boot = self.readlineFile('/boot/STARTUP')
        newmode = self.optionsList[self.option][0].split('=')[1]

        #check for wrong changes
        try:
            cmdfail = False
            bootcmd = boot.split("=", 1)[1].split(" ", 1)[0]
            bootmode = '1'
            temp = boot.split(' ')
            #read kernel and root
            kernel = int(temp[1].split("emmcflash0.kernel")[1])
            root = int(temp[2].split("'root=/dev/mmcblk0p")[1])
            #read boxmode
            cmd4 = "rootwait'"
            if 'boxmode' in boot:
                cmd4 = "rootwait"
                bootmode = temp[5].split("hd51_4.boxmode=")[1].replace("'", '')
            #verify settings
            if not ('boot' == temp[0] and 'rw' == temp[3] and cmd4 == temp[4]
                    and kernel == root - kernel - 1 and "'" == boot[-1:]
                    and bootcmd in Harddisk.getextdevices("ext4")):
                cmdfail = True
        except:
            cmdfail = True

        checkboot = True or cmdfail  #check command line on/off (forcing to True if fail in boot)
        writeoption = already = failboot = False

        if checkboot and (cmdfail or
                          (bootmode != newmode and not self.option_enabled) or
                          (len(boot.split('boxmode')) > 2) or
                          ('boxmode' in boot and len(boot) > 76) or
                          ('boxmode' not in boot and len(boot) > 58)):
            failboot = True
        elif self.option_enabled:
            for x in self.optionsList:
                if (x[0] + "'" in boot or x[0] + " "
                        in boot) and x[0] != self.optionsList[self.option][0]:
                    newboot = boot.replace(x[0],
                                           self.optionsList[self.option][0])
                    writeoption = True
                    break
                elif (x[0] + "'" in boot or x[0] + " "
                      in boot) and x[0] == self.optionsList[self.option][0]:
                    already = True
                    break
            if not (writeoption or already):
                if "boxmode" in boot:
                    failboot = checkboot
                elif self.option:
                    newboot = boot.replace(
                        "rootwait", "rootwait hd51_4.%s" %
                        (self.optionsList[self.option][0]))
                    writeoption = True

        if self.enable_bootnamefile:
            if failboot:
                self.writeFile('/boot/bootname', 'STARTUP_1=STARTUP_1')
            else:
                self.writeFile(
                    '/boot/bootname', '%s=%s' %
                    ('STARTUP_%s' % boot[22:23], self.list[self.selection]))

        message = _("Do you want to reboot now with selected image?")
        if failboot:
            print "[MultiBootStartup] wrong bootsettings: " + boot
            if '/dev/mmcblk0p3' in Harddisk.getextdevices("ext4"):
                if self.writeFile(
                        '/boot/STARTUP',
                        "boot emmcflash0.kernel1 'root=/dev/mmcblk0p3 rw rootwait'"
                ):
                    txt = _("Next boot will start from Image 1.")
                else:
                    txt = _("Can not repair file %s") % (
                        "'/boot/STARTUP'") + "\n" + _(
                            "Caution, next boot is starts with these settings!"
                        ) + "\n"
            else:
                txt = _(
                    "Alternative Image 1 partition for boot repair not found."
                ) + "\n" + _(
                    "Caution, next boot is starts with these settings!") + "\n"
            message = _("Wrong Bootsettings detected!") + "\n\n%s\n\n%s\n" % (
                boot, txt) + _("Do you want to reboot now?")
        elif writeoption:
            if not self.writeFile('/boot/STARTUP', newboot):
                txt = _("Can not write file %s") % (
                    "'/boot/STARTUP'") + "\n" + _(
                        "Caution, next boot is starts with these settings!"
                    ) + "\n"
                message = _("Write error!") + "\n\n%s\n\n%s\n" % (
                    boot, txt) + _("Do you want to reboot now?")
        self.session.openWithCallback(self.restartBOX, MessageBox, message,
                                      MessageBox.TYPE_YESNO)
Пример #43
0
    def save(self):
        print '[MultiBootStartup] select new startup: ', self.list[
            self.selection]
        ret = system("cp -f '/boot/%s' /boot/STARTUP" %
                     self.list[self.selection])
        if ret:
            self.session.open(
                MessageBox,
                _("File '/boot/%s' copy to '/boot/STARTUP' failed!") %
                self.list[self.selection], MessageBox.TYPE_ERROR)
            self.getCurrent()
            return
        writeoption = already = failboot = False
        newboot = boot = self.readlineFile('/boot/STARTUP')
        if self.checkBootEntry(boot):
            failboot = True
        elif self.option_enabled:
            for x in self.optionsList:
                if (x[0] + "'" in boot or x[0] + ' '
                        in boot) and x[0] != self.optionsList[self.option][0]:
                    newboot = boot.replace(x[0],
                                           self.optionsList[self.option][0])
                    if self.optionsList[self.option][0] == 'boxmode=1':
                        newboot = newboot.replace('520M@248M', '440M@328M')
                        newboot = newboot.replace('200M@768M', '192M@768M')
                    elif self.optionsList[self.option][0] == 'boxmode=12':
                        newboot = newboot.replace('440M@328M', '520M@248M')
                        newboot = newboot.replace('192M@768M', '200M@768M')
                    writeoption = True
                    break
                elif (x[0] + "'" in boot or x[0] + ' '
                      in boot) and x[0] == self.optionsList[self.option][0]:
                    already = True
                    break

            if not (writeoption or already):
                if 'boxmode' in boot:
                    failboot = True
                elif self.option:
                    newboot = boot.replace(
                        'rootwait', 'rootwait %s_4.%s' %
                        (getMachineBuild(), self.optionsList[self.option][0]))
                    if self.optionsList[self.option][0] == 'boxmode=1':
                        newboot = newboot.replace('520M@248M', '440M@328M')
                        newboot = newboot.replace('200M@768M', '192M@768M')
                    elif self.optionsList[self.option][0] == 'boxmode=12':
                        newboot = newboot.replace('440M@328M', '520M@248M')
                        newboot = newboot.replace('192M@768M', '200M@768M')
                    writeoption = True
        if self.enable_bootnamefile:
            if failboot:
                self.writeFile('/boot/bootname', 'STARTUP_1=STARTUP_1')
            else:
                self.writeFile(
                    '/boot/bootname',
                    '%s=%s' % ('STARTUP_%s' % getMachineBuild(), boot[22:23],
                               self.list[self.selection]))
        message = _('Do you want to reboot now with selected image?')
        if failboot:
            print '[MultiBootStartup] wrong bootsettings: ' + boot
            if '/dev/mmcblk0p3' in Harddisk.getextdevices('ext4'):
                if self.writeFile(
                        '/boot/STARTUP',
                        "boot emmcflash0.kernel1 'brcm_cma=440M@328M brcm_cma=192M@768M root=/dev/mmcblk0p3 rw rootwait'"
                ):
                    txt = _('Next boot will start from Image 1.')
                else:
                    txt = _(
                        'Can not repair file %s'
                    ) % "'/boot/STARTUP'" + '\n' + _(
                        'Caution, next boot is starts with these settings!'
                    ) + '\n'
            else:
                txt = _(
                    'Alternative Image 1 partition for boot repair not found.'
                ) + '\n' + _(
                    'Caution, next boot is starts with these settings!') + '\n'
            message = _('Wrong Bootsettings detected!') + '\n\n%s\n\n%s\n' % (
                boot, txt) + _('Do you want to reboot now?')
        elif writeoption:
            if not self.writeFile('/boot/STARTUP', newboot):
                txt = _('Can not write file %s') % "'/boot/STARTUP'" + '\n' + _(
                    'Caution, next boot is starts with these settings!') + '\n'
                message = _('Write error!') + '\n\n%s\n\n%s\n' % (
                    boot, txt) + _('Do you want to reboot now?')
        if failboot or writeoption:
            boot = self.readlineFile('/boot/STARTUP')
            if self.checkBootEntry(boot):
                txt = _('Error in file %s') % "'/boot/STARTUP'" + '\n' + _(
                    'Caution, next boot is starts with these settings!') + '\n'
                message = _('Command line error!') + '\n\n%s\n\n%s\n' % (
                    boot, txt) + _('Do you want to reboot now?')
        self.session.openWithCallback(self.restartBOX, MessageBox, message,
                                      MessageBox.TYPE_YESNO)
Пример #44
0
	def save(self):
		print "[MultiBootStartup] select new startup: ", self.list[self.selection]
		ret = system("cp -f '/boot/%s' /boot/STARTUP" %self.list[self.selection])
		if ret:
			self.session.open(MessageBox, _("File '/boot/%s' not found - copy to /boot/STARTUP failed!") %self.list[self.selection], MessageBox.TYPE_ERROR)
			self.getCurrent()
			return

		newboot = boot = self.readlineFile('/boot/STARTUP')
		newmode = self.optionsList[self.option][0].split('=')[1]

		#check for wrong changes
		try:
			cmdfail = False
			bootcmd = boot.split("=",1)[1].split(" ",1)[0]
			bootmode = '1'
			temp = boot.split(' ')
			#read kernel and root
			kernel = int(temp[1].split("emmcflash0.kernel")[1])
			root = int(temp[2].split("'root=/dev/mmcblk0p")[1])
			#read boxmode
			cmd4 = "rootwait'"
			if 'boxmode' in boot:
				cmd4 = "rootwait"
				bootmode = temp[5].split("hd51_4.boxmode=")[1].replace("'",'')
			#verify settings
			if not ('boot' == temp[0] and 'rw' == temp[3] and cmd4 == temp[4] and kernel == root-kernel-1 and "'" == boot[-1:] and bootcmd in Harddisk.getextdevices("ext4")):
				cmdfail = True
		except:
			cmdfail = True

		checkboot = True or cmdfail #check command line on/off (forcing to True if fail in boot)
		writeoption = already = failboot = False

		if checkboot and (cmdfail or (bootmode != newmode and not self.option_enabled) or (len(boot.split('boxmode')) > 2) or ('boxmode' in boot and len(boot) > 76) or ('boxmode' not in boot and len(boot) > 58)):
			failboot = True
		elif self.option_enabled:
			for x in self.optionsList:
				if (x[0] + "'" in boot or x[0] + " " in boot) and x[0] != self.optionsList[self.option][0]:
					newboot = boot.replace(x[0],self.optionsList[self.option][0])
					writeoption = True
					break
				elif (x[0] + "'" in boot or x[0] + " " in boot) and x[0] == self.optionsList[self.option][0]:
					already = True
					break
			if not (writeoption or already):
				if "boxmode" in boot:
					failboot = checkboot
				elif self.option:
					newboot = boot.replace("rootwait", "rootwait hd51_4.%s" %(self.optionsList[self.option][0]))
					writeoption = True

		if self.enable_bootnamefile:
			if failboot:
				self.writeFile('/boot/bootname', 'STARTUP_1=STARTUP_1')
			else:
				self.writeFile('/boot/bootname', '%s=%s' %('STARTUP_%s' %boot[22:23], self.list[self.selection]))

		message = _("Do you want to reboot now with selected image?")
		if failboot:
			print "[MultiBootStartup] wrong bootsettings: " + boot
			if '/dev/mmcblk0p3' in Harddisk.getextdevices("ext4"):
				if self.writeFile('/boot/STARTUP', "boot emmcflash0.kernel1 'root=/dev/mmcblk0p3 rw rootwait'"):
					txt = _("Next boot will start from Image 1.")
				else:
					txt =_("Can not repair file %s") %("'/boot/STARTUP'") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
			else:
				txt = _("Alternative Image 1 partition for boot repair not found.") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
			message = _("Wrong Bootsettings detected!") + "\n\n%s\n\n%s\n" %(boot, txt) + _("Do you want to reboot now?")
		elif writeoption:
			if not self.writeFile('/boot/STARTUP', newboot):
				txt = _("Can not write file %s") %("'/boot/STARTUP'") + "\n" + _("Caution, next boot is starts with these settings!") + "\n"
				message = _("Write error!") + "\n\n%s\n\n%s\n" %(boot, txt) + _("Do you want to reboot now?")
		self.session.openWithCallback(self.restartBOX,MessageBox, message, MessageBox.TYPE_YESNO)
Пример #45
0
    def doFullBackup(self, answer):
        if answer is not None:
            if answer[1]:
                self.RECOVERY = answer[3]
                self.DIRECTORY = "%s/fullbackup" % answer[2]
                if not os.path.exists(self.DIRECTORY):
                    try:
                        os.makedirs(self.DIRECTORY)
                    except:
                        self.session.open(MessageBox,
                                          _("Can't create backup directory"),
                                          MessageBox.TYPE_ERROR,
                                          timeout=10)
                        return
                self.SLOT = answer[1]
                self.MODEL = GetBoxName()
                self.OEM = getBrandOEM()
                self.MACHINEBUILD = getMachineBuild()
                self.MACHINENAME = getMachineName()
                self.MACHINEBRAND = getMachineBrand()
                self.IMAGEFOLDER = getImageFolder()
                self.UBINIZE_ARGS = getMachineUBINIZE()
                self.MKUBIFS_ARGS = getMachineMKUBIFS()
                self.ROOTFSSUBDIR = "none"
                self.ROOTFSBIN = getMachineRootFile()
                self.KERNELBIN = getMachineKernelFile()
                self.ROOTFSTYPE = getImageFileSystem().strip()
                self.IMAGEDISTRO = getImageDistro()
                self.DISTROVERSION = getImageVersion()

                if SystemInfo["canRecovery"]:
                    self.EMMCIMG = SystemInfo["canRecovery"][0]
                    self.MTDBOOT = SystemInfo["canRecovery"][1]
                else:
                    self.EMMCIMG = "none"
                    self.MTDBOOT = "none"

                self.getImageList = self.saveImageList
                if SystemInfo["canMultiBoot"]:
                    self.MTDKERNEL = SystemInfo["canMultiBoot"][
                        self.SLOT]["kernel"].split('/')[2]
                    self.MTDROOTFS = SystemInfo["canMultiBoot"][
                        self.SLOT]["device"].split('/')[2]
                    if 'rootsubdir' in SystemInfo["canMultiBoot"][self.SLOT]:
                        self.ROOTFSSUBDIR = SystemInfo["canMultiBoot"][
                            self.SLOT]['rootsubdir']
                else:
                    self.MTDKERNEL = getMachineMtdKernel()
                    self.MTDROOTFS = getMachineMtdRoot()

                print "[Image Backup] BOX MACHINEBUILD = >%s<" % self.MACHINEBUILD
                print "[Image Backup] BOX MACHINENAME = >%s<" % self.MACHINENAME
                print "[Image Backup] BOX MACHINEBRAND = >%s<" % self.MACHINEBRAND
                print "[Image Backup] BOX MODEL = >%s<" % self.MODEL
                print "[Image Backup] OEM MODEL = >%s<" % self.OEM
                print "[Image Backup] IMAGEFOLDER = >%s<" % self.IMAGEFOLDER
                print "[Image Backup] UBINIZE = >%s<" % self.UBINIZE_ARGS
                print "[Image Backup] MKUBIFS = >%s<" % self.MKUBIFS_ARGS
                print "[Image Backup] MTDBOOT = >%s<" % self.MTDBOOT
                print "[Image Backup] MTDKERNEL = >%s<" % self.MTDKERNEL
                print "[Image Backup] MTDROOTFS = >%s<" % self.MTDROOTFS
                print "[Image Backup] ROOTFSBIN = >%s<" % self.ROOTFSBIN
                print "[Image Backup] KERNELBIN = >%s<" % self.KERNELBIN
                print "[Image Backup] ROOTFSSUBDIR = >%s<" % self.ROOTFSSUBDIR
                print "[Image Backup] ROOTFSTYPE = >%s<" % self.ROOTFSTYPE
                print "[Image Backup] EMMCIMG = >%s<" % self.EMMCIMG
                print "[Image Backup] IMAGEDISTRO = >%s<" % self.IMAGEDISTRO
                print "[Image Backup] DISTROVERSION = >%s<" % self.DISTROVERSION
                print "[Image Backup] MTDBOOT = >%s<" % self.MTDBOOT
                print "[Image Backup] USB RECOVERY = >%s< " % self.RECOVERY
                print "[Image Backup] DESTINATION = >%s< " % self.DIRECTORY
                print "[Image Backup] SLOT = >%s< " % self.SLOT

                self.TITLE = _("Full back-up on %s") % (self.DIRECTORY)
                self.START = time()
                self.DATE = strftime("%Y%m%d_%H%M", localtime(self.START))
                self.IMAGEVERSION = self.imageInfo()
                self.MKFS_UBI = "/usr/sbin/mkfs.ubifs"
                self.MKFS_TAR = "/bin/tar"
                self.BZIP2 = "/usr/bin/bzip2"
                self.MKFS_JFFS2 = "/usr/sbin/mkfs.jffs2"
                self.UBINIZE = "/usr/sbin/ubinize"
                self.NANDDUMP = "/usr/sbin/nanddump"
                self.FASTBOOT = "/usr/bin/ext2simg"
                self.WORKDIR = "%s/bi" % self.DIRECTORY

                self.SHOWNAME = "%s %s" % (self.MACHINEBRAND, self.MODEL)
                self.MAINDEST = "%s/build_%s/%s" % (self.DIRECTORY, self.MODEL,
                                                    self.IMAGEFOLDER)
                self.MAINDESTROOT = "%s/build_%s" % (self.DIRECTORY,
                                                     self.MODEL)

                self.message = "echo -e '\n"
                if getMachineBrand().startswith('A') or getMachineBrand(
                ).startswith('E') or getMachineBrand().startswith(
                        'I') or getMachineBrand().startswith(
                            'O') or getMachineBrand().startswith(
                                'U') or getMachineBrand().startswith('Xt'):
                    self.message += (_('Back-up Tool for an %s\n') %
                                     self.SHOWNAME).upper()
                else:
                    self.message += (_('Back-up Tool for a %s\n') %
                                     self.SHOWNAME).upper()
                self.message += VERSION + '\n'
                self.message += "_________________________________________________\n\n"
                self.message += _(
                    "Please be patient, a backup will now be made,\n")
                self.message += _(
                    "because of the used filesystem the back-up\n")
                if self.RECOVERY:
                    self.message += _(
                        "will take about 30 minutes for this system\n")
                else:
                    self.message += _(
                        "will take about 1-15 minutes for this system\n")
                self.message += "_________________________________________________\n"
                self.message += "'"

                ## PREPARING THE BUILDING ENVIRONMENT
                os.system("rm -rf %s" % self.WORKDIR)
                self.backuproot = "/tmp/bi/root"
                if SystemInfo["canMultiBoot"]:
                    if 'rootsubdir' in SystemInfo["canMultiBoot"][self.SLOT]:
                        self.backuproot = "/tmp/bi/RootSubdir/"
                if not os.path.exists(self.WORKDIR):
                    os.makedirs(self.WORKDIR)
                if not os.path.exists(self.backuproot):
                    os.makedirs(self.backuproot)
                os.system("sync")
                if SystemInfo["canMultiBoot"]:
                    if 'rootsubdir' in SystemInfo["canMultiBoot"][self.SLOT]:
                        os.system("mount /dev/%s /tmp/bi/RootSubdir" %
                                  self.MTDROOTFS)
                        self.backuproot = self.backuproot + self.ROOTFSSUBDIR
                    else:
                        os.system("mount /dev/%s %s" %
                                  (self.MTDROOTFS, self.backuproot))
                else:
                    os.system("mount --bind / %s" % (self.backuproot))

                if "jffs2" in self.ROOTFSTYPE.split():
                    cmd1 = "%s --root=%s --faketime --output=%s/root.jffs2 %s" % (
                        self.MKFS_JFFS2, self.backuproot, self.WORKDIR,
                        self.MKUBIFS_ARGS)
                    cmd2 = None
                    cmd3 = None
                elif "ubi" in self.ROOTFSTYPE.split():
                    f = open("%s/ubinize.cfg" % self.WORKDIR, "w")
                    f.write("[ubifs]\n")
                    f.write("mode=ubi\n")
                    f.write("image=%s/root.ubi\n" % self.WORKDIR)
                    f.write("vol_id=0\n")
                    f.write("vol_type=dynamic\n")
                    f.write("vol_name=rootfs\n")
                    f.write("vol_flags=autoresize\n")
                    f.close()
                    ff = open("%s/root.ubi" % self.WORKDIR, "w")
                    ff.close()
                    cmd1 = "%s -r %s -o %s/root.ubi %s" % (
                        self.MKFS_UBI, self.backuproot, self.WORKDIR,
                        self.MKUBIFS_ARGS)
                    cmd2 = "%s -o %s/root.ubifs %s %s/ubinize.cfg" % (
                        self.UBINIZE, self.WORKDIR, self.UBINIZE_ARGS,
                        self.WORKDIR)
                    cmd3 = "mv %s/root.ubifs %s/root.%s" % (
                        self.WORKDIR, self.WORKDIR, self.ROOTFSTYPE)
                else:
                    if self.EMMCIMG == "usb_update.bin" and self.RECOVERY:
                        cmd1 = None
                        cmd2 = None
                    else:
                        cmd1 = "%s -cf %s/rootfs.tar -C %s --exclude ./var/nmbd --exclude ./.resizerootfs --exclude ./.resize-rootfs --exclude ./.resize-linuxrootfs --exclude ./.resize-userdata --exclude ./var/lib/samba/private/msg.sock --exclude ./var/lib/samba/msg.sock/* --exclude ./run/avahi-daemon/socket ." % (
                            self.MKFS_TAR, self.WORKDIR, self.backuproot)
                        cmd2 = "%s %s/rootfs.tar" % (self.BZIP2, self.WORKDIR)
                    cmd3 = None

                cmdlist = []
                cmdlist.append(self.message)
                if cmd1:
                    cmdlist.append('echo "' + _("Create:") +
                                   ' %s"' % self.ROOTFSBIN)
                    cmdlist.append(cmd1)
                if cmd2:
                    cmdlist.append(cmd2)
                if cmd3:
                    cmdlist.append(cmd3)

                if self.EMMCIMG == "usb_update.bin" and self.RECOVERY:
                    SEEK_CONT = (Harddisk.getFolderSize(self.backuproot) /
                                 1024) + 100000

                    cmdlist.append('echo "' + _("Create:") + " fastboot dump" +
                                   '"')
                    cmdlist.append(
                        'cp -f /usr/share/fastboot.bin %s/fastboot.bin' %
                        (self.WORKDIR))
                    #cmdlist.append("dd if=/dev/mmcblk0p1 of=%s/fastboot.bin" % self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") + " bootargs dump" +
                                   '"')
                    cmdlist.append(
                        'cp -f /usr/share/bootargs.bin %s/bootargs.bin' %
                        (self.WORKDIR))
                    #cmdlist.append("dd if=/dev/mmcblk0p2 of=%s/bootargs.bin" % self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") + " boot dump" +
                                   '"')
                    cmdlist.append("dd if=/dev/mmcblk0p3 of=%s/boot.img" %
                                   self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") +
                                   " baseparam dump" + '"')
                    #cmdlist.append('cp -f /usr/share/bootargs.bin %s/baseparam.img' %(self.WORKDIR))
                    cmdlist.append("dd if=/dev/mmcblk0p4 of=%s/baseparam.img" %
                                   self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") + " pq_param dump" +
                                   '"')
                    #cmdlist.append('cp -f /usr/share/bootargs.bin %s/pq_param.bin' %(self.WORKDIR))
                    cmdlist.append("dd if=/dev/mmcblk0p5 of=%s/pq_param.bin" %
                                   self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") + " logo dump" +
                                   '"')
                    cmdlist.append("dd if=/dev/mmcblk0p6 of=%s/logo.img" %
                                   self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") +
                                   " deviceinfo dump" + '"')
                    #cmdlist.append('cp -f /usr/share/bootargs.bin %s/deviceinfo.bin' %(self.WORKDIR))
                    cmdlist.append(
                        "dd if=/dev/mmcblk0p7 of=%s/deviceinfo.bin" %
                        self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") +
                                   " apploader dump" + '"')
                    cmdlist.append(
                        'cp -f /usr/share/apploader.bin %s/apploader.bin' %
                        (self.WORKDIR))
                    #cmdlist.append("dd if=/dev/mmcblk0p10 of=%s/apploader.bin" % self.WORKDIR)

                    cmdlist.append('echo "' + _("Create:") + " rootfs dump" +
                                   '"')
                    cmdlist.append(
                        "dd if=/dev/zero of=%s/rootfs.ext4 seek=%s count=60 bs=1024"
                        % (self.WORKDIR, SEEK_CONT))
                    cmdlist.append("mkfs.ext4 -F -i 4096 %s/rootfs.ext4" %
                                   (self.WORKDIR))
                    cmdlist.append("mkdir -p %s/userdata" % self.WORKDIR)
                    cmdlist.append("mount %s/rootfs.ext4 %s/userdata" %
                                   (self.WORKDIR, self.WORKDIR))
                    cmdlist.append("mkdir -p %s/userdata/linuxrootfs1" %
                                   self.WORKDIR)
                    cmdlist.append("mkdir -p %s/userdata/linuxrootfs2" %
                                   self.WORKDIR)
                    cmdlist.append("mkdir -p %s/userdata/linuxrootfs3" %
                                   self.WORKDIR)
                    cmdlist.append("mkdir -p %s/userdata/linuxrootfs4" %
                                   self.WORKDIR)
                    cmdlist.append("rsync -aAX %s/ %s/userdata/linuxrootfs1/" %
                                   (self.backuproot, self.WORKDIR))
                    cmdlist.append("umount %s/userdata" % (self.WORKDIR))

                cmdlist.append('echo "' + _("Create:") + " kerneldump" + '"')
                if SystemInfo["canMultiBoot"] or self.MTDKERNEL.startswith(
                        'mmcblk0'):
                    cmdlist.append(
                        "dd if=/dev/%s of=%s/%s" %
                        (self.MTDKERNEL, self.WORKDIR, self.KERNELBIN))
                else:
                    cmdlist.append("nanddump -a -f %s/vmlinux.gz /dev/%s" %
                                   (self.WORKDIR, self.MTDKERNEL))

                if self.EMMCIMG == "usb_update.bin" and self.RECOVERY:
                    cmdlist.append('echo "' +
                                   _("Create: Recovery Fullbackup %s") %
                                   (self.EMMCIMG) + '"')
                    f = open("%s/emmc_partitions.xml" % self.WORKDIR, "w")
                    f.write('<?xml version="1.0" encoding="GB2312" ?>\n')
                    f.write('<Partition_Info>\n')
                    f.write(
                        '<Part Sel="1" PartitionName="fastboot" FlashType="emmc" FileSystem="none" Start="0" Length="1M" SelectFile="fastboot.bin"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="bootargs" FlashType="emmc" FileSystem="none" Start="1M" Length="1M" SelectFile="bootargs.bin"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="bootoptions" FlashType="emmc" FileSystem="none" Start="2M" Length="1M" SelectFile="boot.img"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="baseparam" FlashType="emmc" FileSystem="none" Start="3M" Length="3M" SelectFile="baseparam.img"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="pqparam" FlashType="emmc" FileSystem="none" Start="6M" Length="4M" SelectFile="pq_param.bin"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="logo" FlashType="emmc" FileSystem="none" Start="10M" Length="4M" SelectFile="logo.img"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="deviceinfo" FlashType="emmc" FileSystem="none" Start="14M" Length="4M" SelectFile="deviceinfo.bin"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="loader" FlashType="emmc" FileSystem="none" Start="26M" Length="32M" SelectFile="apploader.bin"/>\n'
                    )
                    f.write(
                        '<Part Sel="1" PartitionName="linuxkernel1" FlashType="emmc" FileSystem="none" Start="66M" Length="16M" SelectFile="kernel.bin"/>\n'
                    )
                    if self.MACHINENAME in ("sf8008m"):
                        f.write(
                            '<Part Sel="1" PartitionName="userdata" FlashType="emmc" FileSystem="ext3/4" Start="130M" Length="3580M" SelectFile="rootfs.ext4"/>\n'
                        )
                    else:
                        f.write(
                            '<Part Sel="1" PartitionName="userdata" FlashType="emmc" FileSystem="ext3/4" Start="130M" Length="7000M" SelectFile="rootfs.ext4"/>\n'
                        )
                    f.write('</Partition_Info>\n')
                    f.close()
                    cmdlist.append(
                        'mkupdate -s 00000003-00000001-01010101 -f %s/emmc_partitions.xml -d %s/%s'
                        % (self.WORKDIR, self.WORKDIR, self.EMMCIMG))

                self.session.open(Console,
                                  title=self.TITLE,
                                  cmdlist=cmdlist,
                                  finishedCallback=self.doFullBackupCB,
                                  closeOnSuccess=True)

            else:
                self.close()
        else:
            self.close()