コード例 #1
0
ファイル: Harddisk.py プロジェクト: Hains/enigma2-python3
	def prepare(self):
		try:
			dev = self.hdd.disk_path.split('/')[-1]
			os.unlink('/dev/nomount.%s' % dev)
		except Exception as e:
			print("[Harddisk] ERROR: Failed to remove /dev/nomount file:", e)
		# try mounting through fstab first
		if self.hdd.mount_device is None:
			dev = self.hdd.partitionPath("1")
		else:
			# if previously mounted, use the same spot
			dev = self.hdd.mount_device
		fstab = open("/etc/fstab")
		lines = fstab.readlines()
		fstab.close()
		for line in lines:
			parts = line.strip().split(" ")
			fspath = os.path.realpath(parts[0])
			if os.path.realpath(fspath) == dev:
				self.setCmdline("mount -t auto " + fspath)
				self.postconditions.append(Task.ReturncodePostcondition())
				return
		# device is not in fstab
		if SystemInfo["Udev"]:
			# we can let udev do the job, re-read the partition table
			# Sorry for the sleep 2 hack...
			self.setCmdline('sleep 2; hdparm -z ' + self.hdd.disk_path)
			self.postconditions.append(Task.ReturncodePostcondition())
コード例 #2
0
 def prepare(self):
     try:
         dev = self.hdd.disk_path.split(sep)[-1]
         unlink("/dev/nomount.%s" % dev)
     except (IOError, OSError) as err:
         print(
             "[Harddisk] Error %d: MountTask failed to remove '/dev/nomount' file!  (%s)"
             % (err.errno, err.strerror))
     if self.hdd.mount_device is None:
         dev = self.hdd.partitionPath(
             "1")  # Try mounting through fstab first.
     else:
         dev = self.hdd.mount_device  # If previously mounted, use the same spot.
     lines = fileReadLines("/etc/fstab", [])
     for line in lines:
         parts = line.strip().split(" ")
         fspath = realpath(parts[0])
         if realpath(fspath) == dev:
             self.setCmdline("mount -t auto " + fspath)
             self.postconditions.append(Task.ReturncodePostcondition())
             return
     # device is not in fstab
     if BoxInfo.getItem("Udev"):
         # we can let udev do the job, re-read the partition table
         # Sorry for the sleep 2 hack...
         self.setCmdline("sleep 2; hdparm -z " + self.hdd.disk_path)
         self.postconditions.append(Task.ReturncodePostcondition())
コード例 #3
0
ファイル: plugin.py プロジェクト: VytenisP/enigma2-plugins-1
 def confirmed1(self, arg):
     from Components import Task
     job = Task.Job(_("Reconstruct AP/SC"))
     task = Task.PythonTask(job, _("Reconstruct AP/SC"))
     task.work = self.offline.reindex
     Task.job_manager.AddJob(job)
     self.close()
コード例 #4
0
ファイル: Harddisk.py プロジェクト: Hains/enigma2-python3
def addInstallTask(job, package):
	task = Task.LoggingTask(job, "update packages")
	task.setTool('opkg')
	task.args.append('update')
	task = Task.LoggingTask(job, "Install " + package)
	task.setTool('opkg')
	task.args.append('install')
	task.args.append(package)
コード例 #5
0
def addInstallTask(job, package):
    task = Task.LoggingTask(job, "update packages")
    task.setTool("opkg")
    task.args.append("update")
    task = Task.LoggingTask(job, "Install " + package)
    task.setTool("opkg")
    task.args.append("install")
    task.args.append(package)
コード例 #6
0
ファイル: ui.py プロジェクト: tomzza/enigma2-plugins
	def addToTask(self, service, path):
		name = self.getName(service, path)
		offline = self.serviceHandler.offlineOperations(service)
		if offline is None:
			print "[Reconstruct AP/SC] Cannot reconstruct", name
			return
		text = _("Reconstruct AP/SC - %s") % name
		job = Task.Job(text)
		task = Task.PythonTask(job, text)
		task.work = offline.reindex
		Task.job_manager.AddJob(job)
コード例 #7
0
ファイル: plugin.py プロジェクト: norhap/enigma2-plugins-1
 def confirmed1(self, arg):
     global rApScTasks
     if not rApScTimer.isActive():
         rApScTimer.startLongTimer(10)
         rApScTasks = []
     rApScTasks.append(str(len(rApScTasks) + 1) + '. ' + self.name)
     job = Task.Job(_("Reconstruct AP/SC"))
     task = Task.PythonTask(job, self.name)
     task.work = self.offline.reindex
     Task.job_manager.AddJob(job)
     self.close()
コード例 #8
0
ファイル: Harddisk.py プロジェクト: Hains/enigma2-python3
	def createCheckJob(self):
		job = Task.Job(_("Checking filesystem..."))
		if self.findMount():
			# Create unmount task if it was not mounted
			UnmountTask(job, self)
			dev = self.mount_device
		else:
			# otherwise, assume there is one partition
			dev = self.partitionPath("1")
		task = Task.LoggingTask(job, "fsck")
		task.setTool('fsck.ext3')
		task.args.append('-f')
		task.args.append('-p')
		task.args.append(dev)
		MountTask(job, self)
		task = Task.ConditionTask(job, _("Waiting for mount"))
		task.check = self.mountDevice
		return job
コード例 #9
0
ファイル: Harddisk.py プロジェクト: Hains/enigma2-python3
	def prepare(self):
		try:
			dev = self.hdd.disk_path.split('/')[-1]
			open('/dev/nomount.%s' % dev, "wb").close()
		except Exception as e:
			print("[Harddisk] ERROR: Failed to create /dev/nomount file:", e)
		self.setTool('umount')
		self.args.append('-f')
		for dev in self.hdd.enumMountDevices():
			self.args.append(dev)
			self.postconditions.append(Task.ReturncodePostcondition())
			self.mountpoints.append(dev)
		if not self.mountpoints:
			print("[Harddisk] UnmountTask: No mountpoints found?")
			self.cmd = 'true'
			self.args = [self.cmd]
コード例 #10
0
 def prepare(self):
     try:
         dev = self.hdd.disk_path.split(sep)[-1]
         open("/dev/nomount.%s" % dev, "wb").close()
     except (IOError, OSError) as err:
         print(
             "[Harddisk] Error %d: UnmountTask failed to create '/dev/nomount' file!  (%s)"
             % (err.errno, err.strerror))
     self.setTool("umount")
     self.args.append("-f")
     for dev in self.hdd.enumMountDevices():
         self.args.append(dev)
         self.postconditions.append(Task.ReturncodePostcondition())
         self.mountpoints.append(dev)
     if not self.mountpoints:
         print("[Harddisk] UnmountTask: No mountpoints found?")
         self.cmd = "true"
         self.args = [self.cmd]
コード例 #11
0
ファイル: Harddisk.py プロジェクト: Hains/enigma2-python3
	def createInitializeJob(self):
		job = Task.Job(_("Initializing storage device..."))
		size = self.diskSize()
		print("[Harddisk] size: %s MB" % size)

		task = UnmountTask(job, self)

		task = Task.PythonTask(job, _("Removing partition table"))
		task.work = self.killPartitionTable
		task.weighting = 1

		task = Task.LoggingTask(job, _("Rereading partition table"))
		task.weighting = 1
		task.setTool('hdparm')
		task.args.append('-z')
		task.args.append(self.disk_path)

		task = Task.ConditionTask(job, _("Waiting for partition"), timeoutCount=20)
		task.check = lambda: not os.path.exists(self.partitionPath("1"))
		task.weighting = 1

		if os.path.exists('/usr/sbin/parted'):
			use_parted = True
		else:
			if size > 2097151:
				addInstallTask(job, 'parted')
				use_parted = True
			else:
				use_parted = False

		task = Task.LoggingTask(job, _("Creating partition"))
		task.weighting = 5
		if use_parted:
			task.setTool('parted')
			if size < 1024:
				# On very small devices, align to block only
				alignment = 'min'
			else:
				# Prefer optimal alignment for performance
				alignment = 'opt'
			if size > 2097151:
				parttype = 'gpt'
			else:
				parttype = 'msdos'
			task.args += ['-a', alignment, '-s', self.disk_path, 'mklabel', parttype, 'mkpart', 'primary', '0%', '100%']
		else:
			task.setTool('sfdisk')
			task.args.append('-f')
			task.args.append('-uS')
			task.args.append(self.disk_path)
			if size > 128000:
				# Start at sector 8 to better support 4k aligned disks
				print("[Harddisk] Detected >128GB disk, using 4k alignment")
				task.initial_input = "8,,L\n;0,0\n;0,0\n;0,0\ny\n"
			else:
				# Smaller disks (CF cards, sticks etc) don't need that
				task.initial_input = ",,L\n;\n;\n;\ny\n"

		task = Task.ConditionTask(job, _("Waiting for partition"))
		task.check = lambda: os.path.exists(self.partitionPath("1"))
		task.weighting = 1

		task = MkfsTask(job, _("Creating filesystem"))
		big_o_options = ["dir_index"]
		if isFileSystemSupported("ext4"):
			task.setTool("mkfs.ext4")
			if size > 20000:
				try:
					version = map(int, open("/proc/version", "r").read().split(' ', 4)[2].split('.', 2)[:2])
					if (version[0] > 3) or (version[0] > 2 and version[1] >= 2):
						# Linux version 3.2 supports bigalloc and -C option, use 256k blocks
						task.args += ["-C", "262144"]
						big_o_options.append("bigalloc")
				except Exception as ex:
					print("[Harddisk] Failed to detect Linux version:", ex)
		else:
			task.setTool("mkfs.ext3")
		if size > 250000:
			# No more than 256k i-nodes (prevent problems with fsck memory requirements)
			task.args += ["-T", "largefile", "-N", "262144"]
			big_o_options.append("sparse_super")
		elif size > 16384:
			# between 16GB and 250GB: 1 i-node per megabyte
			task.args += ["-T", "largefile"]
			big_o_options.append("sparse_super")
		elif size > 2048:
			# Over 2GB: 32 i-nodes per megabyte
			task.args += ["-T", "largefile", "-N", str(size * 32)]
		task.args += ["-F", "-F", "-m0", "-O", ",".join(big_o_options), self.partitionPath("1")]

		task = MountTask(job, self)
		task.weighting = 3

		task = Task.ConditionTask(job, _("Waiting for mount"), timeoutCount=20)
		task.check = self.mountDevice
		task.weighting = 1

		return job
コード例 #12
0
    def createInitializeJob(self):
        print("[Harddisk] Initializing storage device...")
        job = Task.Job(_("Initializing storage device..."))
        size = self.diskSize()
        print("[Harddisk] Disk size: %s MB." % size)
        task = UnmountTask(job, self)
        task = Task.PythonTask(job, _("Removing partition table."))
        task.work = self.killPartitionTable
        task.weighting = 1
        task = Task.LoggingTask(job, _("Rereading partition table."))
        task.weighting = 1
        task.setTool("hdparm")
        task.args.append("-z")
        task.args.append(self.disk_path)
        task = Task.ConditionTask(job,
                                  _("Waiting for partition."),
                                  timeoutCount=20)
        task.check = lambda: not exists(self.partitionPath("1"))
        task.weighting = 1
        if exists("/usr/sbin/parted"):
            use_parted = True
        else:
            if size > 2097151:
                addInstallTask(job, "parted")
                use_parted = True
            else:
                use_parted = False
        print("[Harddisk] Creating partition.")
        task = Task.LoggingTask(job, _("Creating partition."))
        task.weighting = 5
        if use_parted:
            task.setTool("parted")
            if size < 1024:
                alignment = "min"  # On very small devices, align to block only.
            else:
                alignment = "opt"  # Prefer optimal alignment for performance.
            if size > 2097151:
                parttype = "gpt"
            else:
                parttype = "msdos"
            task.args += [
                "-a", alignment, "-s", self.disk_path, "mklabel", parttype,
                "mkpart", "primary", "0%", "100%"
            ]
        else:
            task.setTool("sfdisk")
            task.args.append("-f")
            task.args.append("-uS")
            task.args.append(self.disk_path)
            if size > 128000:
                # Start at sector 8 to better support 4k aligned disks
                print("[Harddisk] Detected >128GB disk, using 4k alignment.")
                task.initial_input = "8,,L\n;0,0\n;0,0\n;0,0\ny\n"
            else:
                # Smaller disks (CF cards, sticks etc) don't need that
                task.initial_input = ",,L\n;\n;\n;\ny\n"
        task = Task.ConditionTask(job, _("Waiting for partition"))
        task.check = lambda: exists(self.partitionPath("1"))
        task.weighting = 1
        task = MkfsTask(job, _("Creating filesystem"))
        big_o_options = ["dir_index"]
        if isFileSystemSupported("ext4"):
            task.setTool("mkfs.ext4")
            if size > 20000:
                try:
                    version = map(
                        int,
                        fileReadLine("/proc/version").split(" ", 4)[2].split(
                            ".", 2)[:2])
                    if (version[0] > 3) or (version[0] > 2
                                            and version[1] >= 2):
                        # Linux version 3.2 supports bigalloc and -C option, use 256k blocks
                        task.args += ["-C", "262144"]
                        big_o_options.append("bigalloc")
                except Exception as err:
                    print(
                        "[Harddisk] Error: Failed to detect Linux version - '%s'!"
                        % str(err))
        else:
            task.setTool("mkfs.ext3")
        if size > 250000:
            # No more than 256k i-nodes (prevent problems with fsck memory requirements)
            task.args += ["-T", "largefile", "-N", "262144"]
            big_o_options.append("sparse_super")
        elif size > 16384:
            # between 16GB and 250GB: 1 i-node per megabyte
            task.args += ["-T", "largefile"]
            big_o_options.append("sparse_super")
        elif size > 2048:
            # Over 2GB: 32 i-nodes per megabyte
            task.args += ["-T", "largefile", "-N", str(size * 32)]
        task.args += [
            "-F", "-F", "-m0", "-O", ",".join(big_o_options),
            self.partitionPath("1")
        ]
        task = MountTask(job, self)
        task.weighting = 3
        task = Task.ConditionTask(job, _("Waiting for mount"), timeoutCount=20)
        task.check = self.mountDevice
        task.weighting = 1

        task = Task.PythonTask(job, _("Create directory") + ": movie")
        task.work = self.createMovieDir
        task.weighting = 1

        return job