Example #1
0
 def save(self):
     currentry = self["config"].getCurrent()
     defaultChanged = None
     if self.checkReadWriteDir(currentry[1]):
         config.usage.default_path.value = self.default_dirname.value
         config.usage.timer_path.value = self.timer_dirname.value
         config.usage.instantrec_path.value = self.instantrec_dirname.value
         config.usage.timeshift_path.value = self.timeshift_dirname.value
         config.usage.default_path.save()
         config.usage.timer_path.save()
         config.usage.instantrec_path.save()
         config.usage.timeshift_path.save()
         if self.default_device.value != "/media/hdd":
             if self.default_device.value != "<undefined>":  #changing default ?
                 tmp = harddiskmanager.getPartitionbyMountpoint(
                     self.default_device.value)
                 if tmp is not None:
                     defaultChanged = harddiskmanager.changeStorageDevice(
                         tmp.uuid, "mount_default", None)
             else:  #disabling default ?
                 p = harddiskmanager.getDefaultStorageDevicebyUUID(
                     defaultStorageDevice())
                 if p is not None:
                     defaultChanged = harddiskmanager.changeStorageDevice(
                         defaultStorageDevice(), "unmount", None)
         if defaultChanged is None:
             self.close()
         elif defaultChanged is False:
             self.session.open(
                 MessageBox,
                 _("There was en error while configuring your storage device."
                   ), MessageBox.TYPE_ERROR)
         else:
             self.close()
Example #2
0
def mountpoint_choosen(option):
	if option is None:
		return

	from Screens.ChoiceBox import ChoiceBox

	print "scanning", option
	(description, mountpoint, session) = option
	res = scanDevice(mountpoint)

	list = [ (r.description, r, res[r], session) for r in res ]

	if not list:
		if mountpoint != "/":
			from Components.Harddisk import harddiskmanager
			p = harddiskmanager.getPartitionbyMountpoint(mountpoint)
			if p is not None and p.uuid is None: #ignore partitions with unknown or no filesystem uuid
				print "ignore", mountpoint, "because we have no uuid"
				return

		from Screens.MessageBox import MessageBox
		if access(mountpoint, F_OK|R_OK):
			session.open(MessageBox, _("No displayable files on this medium found!"), MessageBox.TYPE_ERROR)
		else:
			print "ignore", mountpoint, "because its not accessible"
		return
	
	session.openWithCallback(execute, ChoiceBox, 
		title = _("The following files were found..."),
		list = list)
Example #3
0
	def save(self):
		currentry = self["config"].getCurrent()
		defaultChanged = None
		if self.checkReadWriteDir(currentry[1]):
			config.usage.default_path.value = self.default_dirname.value
			config.usage.timer_path.value = self.timer_dirname.value
			config.usage.instantrec_path.value = self.instantrec_dirname.value
			config.usage.timeshift_path.value = self.timeshift_dirname.value
			config.usage.default_path.save()
			config.usage.timer_path.save()
			config.usage.instantrec_path.save()
			config.usage.timeshift_path.save()
			if self.default_device.value != "/media/hdd":
				if self.default_device.value != "<undefined>": #changing default ?
					tmp = harddiskmanager.getPartitionbyMountpoint(self.default_device.value)
					if tmp is not None:
						defaultChanged = harddiskmanager.changeStorageDevice(tmp.uuid, "mount_default", None)
				else: #disabling default ?
					p = harddiskmanager.getDefaultStorageDevicebyUUID(defaultStorageDevice())
					if p is not None:
						defaultChanged = harddiskmanager.changeStorageDevice(defaultStorageDevice(), "unmount", None)
			if defaultChanged is None:
				self.close()
			elif defaultChanged is False:
				self.session.open(MessageBox, _("There was en error while configuring your storage device."), MessageBox.TYPE_ERROR)
			else:
				self.close()
Example #4
0
def mountpoint_chosen(option):
    if option is None:
        return

    from Screens.ChoiceBox import ChoiceBox

    print "scanning", option
    (description, mountpoint, session) = option
    res = scanDevice(mountpoint)

    list = [(r.description, r, res[r], session) for r in res]

    if not list:
        from Components.Harddisk import harddiskmanager
        from Components.UsageConfig import defaultStorageDevice
        p = harddiskmanager.getPartitionbyMountpoint(mountpoint)

        if mountpoint != "/":
            if p is not None and p.uuid is None:  #ignore partitions with unknown or no filesystem uuid
                print "ignore", mountpoint, "because we have no uuid"
                return
            if defaultStorageDevice(
            ) == "<undefined>" or not harddiskmanager.HDDEnabledCount(
            ):  # no configured default storage device found
                if p is not None and p.isInitialized:
                    print "ignore", mountpoint, "as its usable as default storage device"
                    return

        description = None
        if p:
            description = p.description

        from Screens.MessageBox import MessageBox
        if access(mountpoint, F_OK | R_OK):
            session.open(MessageBox,
                         _("No displayable files on this medium found!"),
                         MessageBox.TYPE_ERROR,
                         timeout=10,
                         title=description)
        else:
            print "ignore", mountpoint, "because its not accessible"
        return

    session.openWithCallback(execute,
                             ChoiceBox,
                             title=_("The following files were found..."),
                             list=list)
Example #5
0
    def run(self, callback, errback):
        # At the end a plugin has to call one of the functions: callback or errback
        # Callback should return with at least one of the parameter: Header, Body, Attachment
        # If empty or none is returned, nothing will be sent
        path = self.getValue('path')
        limit = self.getValue('limit')

        if not self.getValue('wakehdd'):

            def mountpoint(path):
                path = os.path.realpath(path)
                if os.path.ismount(path) or len(path) == 0: return path
                return mountpoint(os.path.dirname(path))

            # User specified to avoid HDD wakeup if it is sleeping
            from Components.Harddisk import harddiskmanager
            p = harddiskmanager.getPartitionbyMountpoint(mountpoint(path))
            if p is not None and p.uuid is not None:
                dev = harddiskmanager.getDeviceNamebyUUID(p.uuid)
                if dev is not None:
                    hdd = harddiskmanager.getHDD(dev)
                    if hdd is not None:
                        if hdd.isSleeping():
                            # Don't wake up HDD
                            print _("[FreeSpace] HDD is idle: ") + str(path)
                            callback()

        # Check free space on path
        if os.path.exists(path):
            stat = os.statvfs(path)
            free = (stat.f_bavail if stat.f_bavail != 0 else
                    stat.f_bfree) * stat.f_bsize / 1024 / 1024  # MB
            if limit > (free / 1024):  #GB
                if free >= 10 * 1024:  #MB
                    free = "%d GB" % (free / 1024)
                else:
                    free = "%d MB" % (free)
                # Not enough free space
                callback(SUBJECT, BODY % (path, limit, free))
            else:
                # There is enough free space
                callback()
Example #6
0
def mountpoint_chosen(option):
	if option is None:
		return

	from Screens.ChoiceBox import ChoiceBox

	print "scanning", option
	(description, mountpoint, session) = option
	res = scanDevice(mountpoint)

	list = [ (r.description, r, res[r], session) for r in res ]

	if not list:
		from Components.Harddisk import harddiskmanager
		from Components.UsageConfig import defaultStorageDevice
		p = harddiskmanager.getPartitionbyMountpoint(mountpoint)

		if mountpoint != "/":
			if p is not None and p.uuid is None: #ignore partitions with unknown or no filesystem uuid
				print "ignore", mountpoint, "because we have no uuid"
				return
			if defaultStorageDevice() == "<undefined>" or not harddiskmanager.HDDEnabledCount(): # no configured default storage device found
				if p is not None and p.isInitialized:
					print "ignore", mountpoint, "as its usable as default storage device"
					return

		description = None
		if p:
			description = p.description

		from Screens.MessageBox import MessageBox
		if access(mountpoint, F_OK|R_OK):
			session.open(MessageBox, _("No displayable files on this medium found!"), MessageBox.TYPE_ERROR, timeout = 10, title = description)
		else:
			print "ignore", mountpoint, "because its not accessible"
		return
	
	session.openWithCallback(execute, ChoiceBox, 
		title = _("The following files were found..."),
		list = list)
	def run(self, callback, errback):
		# At the end a plugin has to call one of the functions: callback or errback
		# Callback should return with at least one of the parameter: Header, Body, Attachment
		# If empty or none is returned, nothing will be sent
		path = self.getValue('path')
		limit = self.getValue('limit')
		
		if not self.getValue('wakehdd'):
			def mountpoint(path):
				path = os.path.realpath(path)
				if os.path.ismount(path) or len(path)==0: return path
				return mountpoint(os.path.dirname(path))
			
			# User specified to avoid HDD wakeup if it is sleeping
			from Components.Harddisk import harddiskmanager
			p = harddiskmanager.getPartitionbyMountpoint( mountpoint(path) )
			if p is not None and p.uuid is not None:
				dev = harddiskmanager.getDeviceNamebyUUID(p.uuid)
				if dev is not None:
					hdd = harddiskmanager.getHDD(dev)
					if hdd is not None:
						if hdd.isSleeping():
							# Don't wake up HDD
							print _("[FreeSpace] HDD is idle: ") + str(path)
							callback()
		
		# Check free space on path
		if os.path.exists( path ):
			stat = os.statvfs( path )
			free = ( stat.f_bavail if stat.f_bavail!=0 else stat.f_bfree ) * stat.f_bsize / 1024 / 1024 # MB
			if limit > (free/1024): #GB
				if free >= 10*1024:	#MB
					free = "%d GB" %(free/1024)
				else:
					free = "%d MB" %(free)
				# Not enough free space
				callback( SUBJECT, BODY % (path, limit, free) )
			else:
				# There is enough free space
				callback()
Example #8
0
    def buildHDDList(self, hd, isOfflineStorage=False, partitionNum=False):
        tot = used = free = 0
        usedprc = '0%'
        devicedata = 'Capacity: 0  Used: 0  Free: 0 '
        divpng = LoadPixmap(cached=True,
                            path=resolveFilename(
                                SCOPE_SKIN_IMAGE,
                                'skin_default/DEInfo/div-h-extended.png'))
        devicepng = onlinepng = None
        isOfflineStorageDevice = isOfflineStorage
        isConfiguredStorageDevice = isMountedPartition = isReadable = False
        uuid = currentMountpoint = partitionPath = partitionType = devicename = None
        hdd_description = device_info = ''
        numpart = 0
        onlinepng = LoadPixmap(
            cached=True,
            path=resolveFilename(SCOPE_SKIN_IMAGE,
                                 'skin_default/buttons/button_green_off.png'))
        hdd_description = hd.model()
        numpart = hd.numPartitions()
        if partitionNum is False:
            if numpart == 0:
                devicename = hd.device
                uuid = harddiskmanager.getPartitionUUID(devicename)
                partitionPath = hd.dev_path
            if numpart == 1:
                devicename = hd.device + str(numpart)
                uuid = harddiskmanager.getPartitionUUID(devicename)
                partitionPath = hd.partitionPath(str(numpart))
        else:
            devicename = hd.device + str(partitionNum)
            uuid = harddiskmanager.getPartitionUUID(devicename)
            partitionPath = hd.partitionPath(str(partitionNum))
        partitionType = harddiskmanager.getBlkidPartitionType(partitionPath)
        devicepng = LoadPixmap(
            resolveFilename(SCOPE_SKIN_IMAGE,
                            'skin_default/DEInfo/internal_hdd.png'))
        if hd.isRemovable:
            devicepng = LoadPixmap(
                resolveFilename(SCOPE_SKIN_IMAGE,
                                'skin_default/DEInfo/removable_dev.png'))
            device_info += hd.bus_description() + ' ' + _('Storage device')
        else:
            device_info += hd.bus_description() + ' ' + _('Hard disk')
        if uuid is not None:
            cfg_uuid = config.storage.get(uuid, None)
            if cfg_uuid is not None:
                if cfg_uuid['mountpoint'].value != '':
                    currentMountpoint = cfg_uuid['mountpoint'].value
                if cfg_uuid['enabled'].value:
                    isConfiguredStorageDevice = True
                    p = harddiskmanager.getPartitionbyMountpoint(
                        currentMountpoint)
                    if p is not None:
                        if p.mounted():
                            isMountedPartition = True
            if isMountedPartition:
                isReadable = True
                devicepng = LoadPixmap(
                    resolveFilename(
                        SCOPE_SKIN_IMAGE,
                        'skin_default/DEInfo/internal_hdd_mounted.png'))
                if hd.isRemovable:
                    devicepng = LoadPixmap(
                        resolveFilename(
                            SCOPE_SKIN_IMAGE,
                            'skin_default/DEInfo/removable_dev_mounted.png'))
                device_info += ' - ' + currentMountpoint
            else:
                device_info += ' - not mounted'
            if currentMountpoint:
                for line in self.dfmounts:
                    line = line.replace('part1', ' ')
                    x = line.strip().split()
                    if x[len(x) - 1].find(
                            currentMountpoint.strip()) >= 0 and len(x) > 1:
                        tot = int(x[0])
                        used = int(x[1])
                        free = int(x[2])
                        usedprc = x[3]
                        devicedata = 'Capacity: %s  Used: %s  Free: %s ' % (
                            getUnit(tot), x[len(x) - 2], getUnit(free))
                        if usedprc:
                            hdd_description += ' in use: %s' % usedprc

        return (hdd_description, hd, device_info, numpart,
                isOfflineStorageDevice, isMountedPartition, currentMountpoint,
                devicepng, onlinepng, divpng, partitionNum, isReadable,
                devicedata, tot, used, free, usedprc)