Esempio n. 1
0
 def _get_text_data(self, filepath):
     ''' Creates a tEXt dictionary for <filepath>. '''
     mime = mimetypes.guess_type(filepath)[0] or 'unknown/mime'
     uri = portability.uri_prefix() + pathname2url(
         i18n.to_unicode(os.path.normpath(filepath)))
     stat = os.stat(filepath)
     # MTime could be floating point number, so convert to long first to have a fixed point number
     mtime = str(stat.st_mtime)
     size = str(stat.st_size)
     format, width, height = image_tools.get_image_info(filepath)
     return {
         'tEXt::Thumb::URI': uri,
         'tEXt::Thumb::MTime': mtime,
         'tEXt::Thumb::Size': size,
         'tEXt::Thumb::Mimetype': mime,
         'tEXt::Thumb::Image::Width': str(width),
         'tEXt::Thumb::Image::Height': str(height),
         'tEXt::Software': 'MComix %s' % constants.VERSION
     }
    def collect_files_from_subdir(self, path, filter, recursive=False):
        ''' Finds archives within C{path} that match the
        L{Gtk.FileFilter} passed in C{filter}. '''

        for root, dirs, files in os.walk(path):
            for file in files:
                full_path = os.path.join(root, file)
                mimetype = mimetypes.guess_type(
                    full_path)[0] or 'application/octet-stream'
                filter_info = Gtk.FileFilterInfo()
                filter_info.contains = Gtk.FileFilterFlags.FILENAME | Gtk.FileFilterFlags.MIME_TYPE
                filter_info.filename = full_path
                filter_info.mime_type = mimetype

                if (filter == self._all_files_filter
                        or filter.filter(filter_info)):
                    yield full_path

            if not recursive:
                break