Example #1
0
    def getSize(self, path):
        """
        @summary: Gets a tuple with size and size description with its units (bytes, Kbytes...)
        @param path: Path to calculate size.
        @return: Tuple with size and size description  
        """
        # Check if path exist
        if not os.path.exists(path):
            __log__.warning("Path does not exist. %s" % path)
            return (0, "")        
        if (os.path.isdir(path)):
            return (0, "")
        
        try:
            size = long(os.path.getsize(path))
        except:
            size = 0
        sizeDescription = ""
 
        
        if (GNOME):
            # get mime
            mime_type = gnomevfs.get_mime_type(path)
     
            uri = "file://%s" % urllib.pathname2url(path)
            fileInfo = gnomevfs.get_file_info(uri)
            
            if ((fileInfo.valid_fields & gnomevfs.FILE_INFO_FIELDS_SIZE) != 0):
                    size = fileInfo.size
                    sizeDescription = gnomevfs.format_file_size_for_display(size)
        else:
            sizeDescription = self.__getSizeDescription__(size) 
                
        return (size, sizeDescription)
Example #2
0
    def get_comment(self):
        if not self.get_is_mounted():
            # FIXME: Check if drive is set to auto-mount, and if not show "Not Mounted"
            return _("No disk inserted")
        else:
            comment = ""

            volumes = self.drive.get_mounted_volumes()
            if len(volumes) == 1:
                vol_name = volumes[0].get_display_name()
                if vol_name != self.get_name():
                    comment += volumes[0].get_display_name()

            # FIXME: If read-only drive, show allocated size instead
            try:
                space = gnomevfs.get_volume_free_space(gnomevfs.URI(self.get_uri()))
            except (TypeError, gnomevfs.Error):
                # When the URI or free space is unknown
                space = 0

            if space:
                if comment: comment += "\n"
                comment += _("Free space: %s") % gnomevfs.format_file_size_for_display(space)

            return comment
Example #3
0
def human_readable_bytes(bytes):

    try:
         import gnomevfs
         return gnomevfs.format_file_size_for_display(bytes)
    except ImportError:

        global _TERA, _GIGA, _MEGA, _KILO

        if bytes >= _TERA:
            return _("%.2f TB") % (float(bytes) / _TERA)
        elif bytes >= _GIGA:
            return _("%.2f GB") % (float(bytes) / _GIGA)
        elif bytes >= _MEGA:
            return _("%.2f MB") % (float(bytes) / _MEGA)
        elif bytes >= _KILO:
            return _("%.2f kB") % (float(bytes) / _KILO)
        else:
            return _("%d B") % bytes