Пример #1
0
	def getImagesList(self):

		def getImages(path, files, dir = _("Root directory")):
			for file in [x for x in files if os.path.splitext(x)[1] == ".zip" and model in x]:
				try:
					if checkimagefiles([x.split(os.sep)[-1] for x in zipfile.ZipFile(file).namelist()]):
						if dir not in self.imagesList:
							self.imagesList[dir] = {}
						self.imagesList[dir][file] = {'link': file, 'name': file.split(os.sep)[-1]}
				except:
					pass

		model = GetBoxName()

		if not self.imagesList:
			if not self.jsonlist:
				try:
					self.jsonlist = dict(json.load(urllib2.urlopen('http://openeight.de/json/%s' % model)))
					if config.usage.alternative_imagefeed.value:
						self.jsonlist.update(dict(json.load(urllib2.urlopen('%s%s' % (config.usage.alternative_imagefeed.value, model)))))
				except:
					pass
			self.imagesList = dict(self.jsonlist)

			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 not(SystemInfo['HasMMC'] and "/mmc" in media) and os.path.isdir(media):
					try:
						getImages(media, [os.path.join(media, x) for x in os.listdir(media) if os.path.splitext(x)[1] == ".zip" and model in x])
						for dir in ["Downloaded_Images", "Images", "Fullbackup"]:
							if dir.lower() in os.listdir(media):
								path = os.path.join(media, dir.lower())
								if os.path.isdir(path) and not os.path.islink(path) and not os.path.ismount(path):
									getImages(path, [os.path.join(path, x) for x in os.listdir(path) if os.path.splitext(x)[1] == ".zip" and model in x], dir)
									for rdir in [rdir for rdir in [os.path.join(path, rdir) for rdir in os.listdir(path)] if os.path.isdir(rdir) and os.path.splitext(rdir)[1] == ".unzipped"]:
										shutil.rmtree(rdir)
					except:
						pass

		list = []
		for catagorie in reversed(sorted(self.imagesList.keys())):
			if catagorie in self.expanded:
				list.append(ChoiceEntryComponent('expanded',((str(catagorie)), "Expander")))
				for image in reversed(sorted(self.imagesList[catagorie].keys())):
					list.append(ChoiceEntryComponent('verticalline',((str(self.imagesList[catagorie][image]['name'])), str(self.imagesList[catagorie][image]['link']))))
			else:
				for image in self.imagesList[catagorie].keys():
					list.append(ChoiceEntryComponent('expandable',((str(catagorie)), "Expander")))
					break
		if list:
			self["list"].setList(list)
			if self.setIndex:
				self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1)
				if self["list"].l.getCurrentSelection()[0][1] == "Expander":
					self.setIndex -= 1
					if self.setIndex:
						self["list"].moveToIndex(self.setIndex if self.setIndex < len(list) else len(list) - 1)
				self.setIndex = 0
			self.selectionChanged()
		else:
			self.session.openWithCallback(self.close, MessageBox, _("Cannot find images - please try later"), type=MessageBox.TYPE_ERROR, timeout=3)
Пример #2
0
	def getImagesList(self):

		def getImages(path, files):
			for file in [x for x in files if os.path.splitext(x)[1] == ".zip" and box in x]:
				try:
					if checkimagefiles([x.split(os.sep)[-1] for x in zipfile.ZipFile(file).namelist()]):
						imagetyp = _("Downloaded Images")
						if 'backup' in file.split(os.sep)[-1]:
							imagetyp = _("Fullbackup Images")
						if imagetyp not in self.imagesList:
							self.imagesList[imagetyp] = {}
						self.imagesList[imagetyp][file] = {'link': file, 'name': file.split(os.sep)[-1]}
				except:
					pass

		if not self.imagesList:
			box = GetBoxName()
			if not self.jsonlist:
				try:
					self.jsonlist = dict(json.load(urlopen('%s/%s' % (feedurl, box))))
					#if config.usage.alternative_imagefeed.value:
					#	self.jsonlist.update(dict(json.load(urlopen('%s%s' % (config.usage.alternative_imagefeed.value, box)))))
				except:
					pass
			self.imagesList = dict(self.jsonlist)

			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 not(SystemInfo['HasMMC'] and "/mmc" in media) and os.path.isdir(media):
					getImages(media, [os.path.join(media, x) for x in os.listdir(media) if os.path.splitext(x)[1] == ".zip" and box in x])
					if "images" in os.listdir(media):
						media = os.path.join(media, "images")
						if os.path.isdir(media) and not os.path.islink(media) and not os.path.ismount(media):
							getImages(media, [os.path.join(media, x) for x in os.listdir(media) if os.path.splitext(x)[1] == ".zip" and box in x])
							for dir in [dir for dir in [os.path.join(media, dir) for dir in os.listdir(media)] if os.path.isdir(dir) and os.path.splitext(dir)[1] == ".unzipped"]:
								shutil.rmtree(dir)

		_list = []
		for catagorie in reversed(sorted(self.imagesList.keys())):
			if catagorie in self.expanded:
				_list.append(ChoiceEntryComponent('expanded', ((str(catagorie)), "Expander")))
				for image in reversed(sorted(list(self.imagesList[catagorie].keys()), key=lambda x: x.split(os.sep)[-1])):
					_list.append(ChoiceEntryComponent('verticalline', ((str(self.imagesList[catagorie][image]['name'])), str(self.imagesList[catagorie][image]['link']))))
			else:
				for image in list(self.imagesList[catagorie].keys()):
					_list.append(ChoiceEntryComponent('expandable', ((str(catagorie)), "Expander")))
					break
		if _list:
			self["list"].setList(_list)
			if self.setIndex:
				self["list"].moveToIndex(self.setIndex if self.setIndex < len(_list) else len(_list) - 1)
				if self["list"].l.getCurrentSelection()[0][1] == "Expander":
					self.setIndex -= 1
					if self.setIndex:
						self["list"].moveToIndex(self.setIndex if self.setIndex < len(_list) else len(_list) - 1)
				self.setIndex = 0
			self.selectionChanged()
		else:
			self.session.openWithCallback(self.close, MessageBox, _("Cannot find images - please try later"), type=MessageBox.TYPE_ERROR, timeout=3)
Пример #3
0
    def getImagesList(self):
        def getImages(path, files):
            try:
                print self.imagesList[("Downloaded Images")]
            except:
                self.imagesList[("Downloaded Images")] = {}
            try:
                print self.imagesList[("Fullbackup Images")]
            except:
                self.imagesList[("Fullbackup Images")] = {}
            for file in [
                    x for x in files
                    if os.path.splitext(x)[1] == ".zip" and box in x
            ]:
                try:
                    if checkimagefiles([
                            x.split(os.sep)[-1]
                            for x in zipfile.ZipFile(file).namelist()
                    ]):
                        if 'backup' in file.split(os.sep)[-1]:
                            self.imagesList[("Fullbackup Images")][file] = {
                                'link': file,
                                'name': file.split(os.sep)[-1]
                            }
                        else:
                            self.imagesList[("Downloaded Images")][file] = {
                                'link': file,
                                'name': file.split(os.sep)[-1]
                            }

                except:
                    pass

        if not self.imagesList:
            box = GetBoxName()
            for version in reversed(sorted(imagecat)):
                newversion = _("Image Version %s") % version
                the_page = ""
                url = '%s/%s/images/%s' % (feedurl, version, box)
                try:
                    req = urllib2.Request(url)
                    response = urllib2.urlopen(req)
                except urllib2.URLError as e:
                    print "URL ERROR: %s\n%s" % (e, url)
                    continue

                try:
                    the_page = response.read()
                except urllib2.HTTPError as e:
                    print "HTTP download ERROR: %s" % e.code
                    continue

                lines = the_page.split('\n')
                tt = len(box)
                countimage = []
                for line in lines:
                    if line.find('<a href="o') > -1:
                        t = line.find('<a href="o')
                        e = line.find('zip"')
                        countimage.append(line[t + 9:e + 3])
                if len(countimage) >= 1:
                    self.imagesList[newversion] = {}
                    for image in countimage:
                        self.imagesList[newversion][image] = {}
                        self.imagesList[newversion][image]["name"] = image
                        self.imagesList[newversion][image][
                            "link"] = '%s/%s/images/%s/%s' % (feedurl, version,
                                                              box, image)

            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 not (SystemInfo['HasMMC']
                        and "/mmc" in media) and os.path.isdir(media):
                    getImages(media, [
                        os.path.join(media, x) for x in os.listdir(media)
                        if os.path.splitext(x)[1] == ".zip" and box in x
                    ])
                    if "images" in os.listdir(media):
                        media = os.path.join(media, "images")
                        if os.path.isdir(media) and not os.path.islink(
                                media) and not os.path.ismount(media):
                            getImages(media, [
                                os.path.join(media, x)
                                for x in os.listdir(media) if
                                os.path.splitext(x)[1] == ".zip" and box in x
                            ])
                            for dir in [
                                    dir for dir in [
                                        os.path.join(media, dir)
                                        for dir in os.listdir(media)
                                    ] if os.path.isdir(dir)
                                    and os.path.splitext(dir)[1] == ".unzipped"
                            ]:
                                shutil.rmtree(dir)

        list = []
        for catagorie in reversed(sorted(self.imagesList.keys())):
            if catagorie in self.expanded:
                list.append(
                    ChoiceEntryComponent('expanded',
                                         ((str(catagorie)), "Expander")))
                for image in reversed(sorted(
                        self.imagesList[catagorie].keys())):
                    list.append(
                        ChoiceEntryComponent(
                            'verticalline',
                            ((str(self.imagesList[catagorie][image]['name'])),
                             str(self.imagesList[catagorie][image]['link']))))
            else:
                for image in self.imagesList[catagorie].keys():
                    list.append(
                        ChoiceEntryComponent('expandable',
                                             ((str(catagorie)), "Expander")))
                    break
        if list:
            self["list"].setList(list)
            if self.setIndex:
                self["list"].moveToIndex(
                    self.setIndex if self.setIndex < len(list) else len(list) -
                    1)
                if self["list"].l.getCurrentSelection()[0][1] == "Expander":
                    self.setIndex -= 1
                    if self.setIndex:
                        self["list"].moveToIndex(self.setIndex if self.setIndex
                                                 < len(list) else len(list) -
                                                 1)
                self.setIndex = 0
            self.selectionChanged()
        else:
            self.session.openWithCallback(
                self.close,
                MessageBox,
                _("Cannot find images - please try later"),
                type=MessageBox.TYPE_ERROR,
                timeout=3)
Пример #4
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()
Пример #5
0
    def getImagesList(self):
        def getImages(path, files):
            for file in [
                    x for x in files
                    if os.path.splitext(x)[1] == ".zip" and box in x or (
                        "openpli" in x and boxname in x)
            ]:
                try:
                    if checkimagefiles([
                            x.split(os.sep)[-1]
                            for x in zipfile.ZipFile(file).namelist()
                    ]):
                        imagetyp = _("Downloaded Images")
                        if 'backup' in file.split(os.sep)[-1]:
                            imagetyp = _("Fullbackup Images")
                        if imagetyp not in self.imagesList:
                            self.imagesList[imagetyp] = {}
                        self.imagesList[imagetyp][file] = {
                            'link': file,
                            'name': file.split(os.sep)[-1][:-4]
                        }
                except:
                    pass

        if not self.imagesList:
            box = GetBoxName()
            boxname = getMachineProcModel().lower()
            try:
                import socket
                socket.getaddrinfo(feedserver, None)

                for version in sorted(imagecat):
                    newversion = _(
                        "Images %s"
                    ) % version  #Oficial, Descargadas, Full backup
                    the_page = ""
                    url = '%s/Alliance/getfirm.php?box=%s' % (feedurl, box)
                    try:
                        req = urllib2.Request(url)
                        response = urllib2.urlopen(req)
                    except urllib2.URLError as e:
                        print "URL ERROR: %s\n%s" % (e, url)
                        continue

                    try:
                        the_page = response.read()
                    except urllib2.HTTPError as e:
                        print "HTTP download ERROR: %s" % e.code
                        continue

                    lines = the_page.split('\n')
                    try:
                        l = lines[0]
                        self.feedurl = l.split("<a href='")[1].split(
                            "openspa-")[0]
                    except:
                        self["info"].setText("BOX: [" + box + "]\n" + _(
                            "No images found for this device. More info in openspa.info"
                        ))
                        list.append("(" + _("No images found for") + " " +
                                    box + ")")
                    countimage = []
                    for line in lines:
                        if line.find(".zip") > -1 and not "recovery" in line:
                            try:
                                self.feedurl = line.split(
                                    "<a href='")[1].split("openspa-")[0]
                            except:
                                pass
                            name = line.split(">")[1].split("<")[0]
                            name = name.replace(" (", " ").replace(
                                " - ",
                                " - ").replace(")", "").replace(".zip", " ->")
                            #self.urllist[name]=line.split("<a href='")[1].split("openspa-")[0]
                            countimage.append(name.split(' ->')[0])
                    if len(countimage) >= 1:
                        self.imagesList[newversion] = {}
                        for image in countimage:
                            self.imagesList[newversion][image] = {}
                            self.imagesList[newversion][image]["name"] = image
                            self.imagesList[newversion][image][
                                "link"] = '%s%s.zip' % (self.feedurl, image)

            except socket.error as e:
                print "FEEDSERVER ERROR: %s" % e

            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 os.path.isdir(media):
                    getImages(media, [
                        os.path.join(media, x) for x in os.listdir(media)
                        if os.path.splitext(x)[1] == ".zip" and box in x or (
                            "openpli" in x and boxname in x)
                    ])
                    if "images" in os.listdir(media):
                        media = os.path.join(media, "images")
                        if os.path.isdir(media) and not os.path.islink(
                                media) and not os.path.ismount(media):
                            getImages(media, [
                                os.path.join(media, x)
                                for x in os.listdir(media)
                                if os.path.splitext(x)[1] == ".zip" and box in
                                x or ("openpli" in x and boxname in x)
                            ])
                            for dir in [
                                    dir for dir in [
                                        os.path.join(media, dir)
                                        for dir in os.listdir(media)
                                    ] if os.path.isdir(dir)
                                    and os.path.splitext(dir)[1] == ".unzipped"
                            ]:
                                shutil.rmtree(dir)

        list = []
        for catagorie in self.imagesList.keys():
            if catagorie in self.expanded:
                list.append(
                    ChoiceEntryComponent('expanded',
                                         ((str(catagorie)), "Expander")))
                for image in reversed(
                        sorted(self.imagesList[catagorie].keys(),
                               key=lambda x: x.split(os.sep)[-1])):
                    list.append(
                        ChoiceEntryComponent(
                            'verticalline',
                            ((str(self.imagesList[catagorie][image]['name'])),
                             str(self.imagesList[catagorie][image]['link']))))
            else:
                for image in self.imagesList[catagorie].keys():
                    list.append(
                        ChoiceEntryComponent('expandable',
                                             ((str(catagorie)), "Expander")))
                    break
        if list:
            self["list"].setList(list)
            if self.setIndex:
                self["list"].moveToIndex(
                    self.setIndex if self.setIndex < len(list) else len(list) -
                    1)
                if self["list"].l.getCurrentSelection()[0][1] == "Expander":
                    self.setIndex -= 1
                    if self.setIndex:
                        self["list"].moveToIndex(self.setIndex if self.setIndex
                                                 < len(list) else len(list) -
                                                 1)
                self.setIndex = 0
            self.selectionChanged()
        else:
            self.session.openWithCallback(
                self.close,
                MessageBox,
                _("Cannot find images - please try later"),
                type=MessageBox.TYPE_ERROR,
                timeout=3)