def __str__(self):
        if self.file_name is not None:
            s = "{}\n".format(os.path.split(self.file_name)[1])
        else:
            s = self.ext
        if self.datetime:  # type: datetime.datetime
            s += "Datetime in metadata: {}\n".format(
                self.datetime.strftime("%c"))
            if not datetime_roughly_equal(self.datetime, self.fs_datetime):
                s += "Differs from datetime on file system: {}\n".format(
                    self.fs_datetime.strftime("%c"))
        else:
            s += "Datetime on file system: {}\n".format(
                self.fs_datetime.strftime("%c"))

        s += "Disk cache after metadata read:\n[{}]\n".format(self.in_memory)
        if self.minimum_read_size_in_bytes_datetime is not None:
            s += "Minimum read size to extract datetime: {} of {}\n".format(
                format_size_for_user(self.minimum_read_size_in_bytes_datetime),
                format_size_for_user(self.file_size),
            )
        if self.minimum_read_size_in_bytes_thumbnail:
            s += "Minimum read size to extract thumbnail: {} of {}\n".format(
                format_size_for_user(
                    self.minimum_read_size_in_bytes_thumbnail),
                format_size_for_user(self.file_size),
            )
        if self.minimum_metadata_read_size_in_bytes_all is not None:
            s += "Minimum read size to extract variety of tags: {}\n".format(
                format_size_for_user(
                    self.minimum_metadata_read_size_in_bytes_all))
        else:
            s += "Could not extract variety of tags with minimal read\n"
        return s
    def __init__(self, parent=None, bytes_downloaded: int=0, download_size: int=0) -> None:
        super().__init__(parent)
        self.rapidApp = parent # type: 'RapidWindow'

        self.setModal(True)
        self.setSizeGripEnabled(False)

        self.download_size_display = format_size_for_user(download_size, zero_string='0 KB')
        bytes_downloaded_display = format_size_for_user(bytes_downloaded, zero_string='0 KB')

        # Translators: shows how much of a file has been downloaded e.g  123 KB of 1.3 MB
        # Translators: %(variable)s represents Python code, not a plural of the term
        # variable. You must keep the %(variable)s untranslated, or the program will
        # crash.
        self.text = _('%(downloaded)s of %(total)s')
        self.message = QLabel(
            self.text % dict(downloaded=bytes_downloaded_display, total=self.download_size_display)
        )

        self.progressBar = QProgressBar()
        self.progressBar.setMinimumWidth(standardProgressBarWidth())
        self.progressBar.setMaximum(download_size)
        self.progressBar.setValue(bytes_downloaded)

        buttonBox = QDialogButtonBox(QDialogButtonBox.Cancel)
        translateDialogBoxButtons(buttonBox)
        buttonBox.rejected.connect(self.reject)

        grid = QGridLayout()
        grid.addWidget(self.message, 0, 0, 1, 2)
        grid.addWidget(self.progressBar, 1, 0, 1, 2)
        grid.addWidget(buttonBox, 2, 0, 1, 2)
        self.setLayout(grid)
        self.setWindowTitle(_('Downloading...'))
Пример #3
0
def dump_camera_details() -> None:
    import itertools

    context = gp.Context()
    cameras = autodetect_cameras(context)
    for model, port in cameras:
        is_mtp_device = camera_is_mtp_device(camera_port=port)
        c = Camera(
            model=model,
            port=port,
            is_mtp_device=is_mtp_device,
            context=context,
        )
        if not c.camera_initialized:
            logging.error("Camera %s could not be initialized", model)
        else:
            print()
            print(c.display_name)
            print("=" * len(c.display_name))
            print(f"\nMTP: {is_mtp_device}")
            print()
            if not c.specific_folder_located:
                print("Specific folder was not located")
            else:
                print(
                    "Specific folders:",
                    ", ".join(itertools.chain.from_iterable(
                        c.specific_folders)),
                )
                print("Can fetch thumbnails:", c.can_fetch_thumbnails)

                sc = c.get_storage_media_capacity()
                if not sc:
                    print("Unable to determine storage media capacity")
                else:
                    title = "Storage capacity"
                    print("\n{}\n{}".format(title, "-" * len(title)))
                    for ss in sc:
                        print("\nPath: {}\nCapacity: {}\nFree {}".format(
                            ss.path,
                            format_size_for_user(ss.bytes_total),
                            format_size_for_user(ss.bytes_free),
                        ))
                sd = c.get_storage_descriptions()
                if not sd:
                    print("Unable to determine storage descriptions")
                else:
                    title = "Storage description(s)"
                    print("\n{}\n{}".format(title, "-" * len(title)))
                    for ss in sd:
                        print("\n{}".format(ss))

        c.free_camera()
 def updateProgress(self, bytes_downloaded: int) -> None:
     bytes_downloaded_display = format_size_for_user(bytes_downloaded,
                                                     zero_string="0 KB")
     self.message.setText(self.text %
                          dict(downloaded=bytes_downloaded_display,
                               total=self.download_size_display))
     self.progressBar.setValue(bytes_downloaded)
def analyze_videos(videos: List[VideoAttributes], verbose: bool) -> None:
    size_by_extension = defaultdict(list)
    datetime_read = defaultdict(list)
    thumbnail_extract = defaultdict(list)
    variety_read = defaultdict(list)
    variety_read_raw = defaultdict(list)

    for va in videos:
        print("%s" % va)
        size_by_extension[va.ext].append(va.bytes_cached)
        total = format_size_for_user(va.file_size)
        if va.minimum_read_size_in_bytes_datetime is not None:
            # size = format_size_for_user(va.minimum_read_size_in_bytes_datetime)
            # datetime_read[va.ext].append('{} of {}'.format(size, total))
            datetime_read[va.ext].append(
                va.minimum_read_size_in_bytes_datetime)
        if va.minimum_read_size_in_bytes_thumbnail is not None:
            # size =  format_size_for_user(va.minimum_read_size_in_bytes_thumbnail)
            # thumbnail_extract[va.ext].append('{} of {}'.format(size, total))
            thumbnail_extract[va.ext].append(
                va.minimum_read_size_in_bytes_thumbnail)
        if va.minimum_metadata_read_size_in_bytes_all is not None:
            # size =  format_size_for_user(va.minimum_metadata_read_size_in_bytes_all)
            # variety_read[va.ext].append('{} of {}'.format(size, total))
            variety_read_raw[va.ext].append(
                va.minimum_metadata_read_size_in_bytes_all)

    exts = list(size_by_extension.keys())
    exts.sort()
    print("\nKB cached after date time extraction:")
    for ext in exts:
        print(ext, Counter(size_by_extension[ext]).most_common())

    exts = list(thumbnail_extract.keys())
    exts.sort()
    print("\nThumbnail extract:")
    for ext in exts:
        print(ext, Counter(thumbnail_extract[ext]).most_common())

    exts = list(datetime_read.keys())
    exts.sort()
    print("\nDate time read:")
    for ext in exts:
        print(ext, Counter(datetime_read[ext]).most_common())

    exts = list(variety_read.keys())
    exts.sort()
    print("\nVariety of tags read:")
    for ext in exts:
        print(ext, Counter(variety_read[ext]).most_common())
        m = max(variety_read_raw[ext])
        print(ext, "max + 20% (bytes):", round(int(m) * 1.2))

    print()
    if verbose:
        for va in videos:
            print(va)
 def setDownloadSize(self, download_size: int) -> None:
     self.download_size_display = format_size_for_user(download_size,
                                                       zero_string="0 KB")
     self.progressBar.setMaximum(download_size)
    def __str__(self):
        s = ""
        if self.model is not None:
            s += "{}\n".format(self.model)
        elif self.file_name is not None:
            s += "{}\n".format(os.path.split(self.file_name)[1])
        if self.width is not None:
            s += "{}x{}\n".format(self.width, self.height)
        if self.datetime:  # type: datetime.datetime
            s += "{}\n".format(self.datetime.strftime("%c"))
        if self.iso:
            s += "ISO: {}\n".format(self.iso)
        if self.orientation is not None:
            s += "Orientation: {}\n".format(self.orientation)
        if self.has_gps:
            s += "Has GPS tag: True\n"
        if self.has_exif_thumbnail:
            s += "Exif thumbnail: {}\n".format(self.exif_thumbnail_details)
        if self.preview_source is not None:
            s += self.show_preview_source()
        if self.exif_thumbnail_and_preview_identical == False:
            # Check against False as value is one of None, True or
            # False
            s += "Exif thumbnail differs from smallest preview\n"
        if self.preview_size_and_types:
            s += "All preview images: {}\n".format(self.preview_size_and_types)

        if self.in_memory is not None:
            s += "Disk cache after exif read:\n[{}]\n".format(self.in_memory)

        if self.in_memory is not None and self.in_memory_post_thumb is not None:
            if self.in_memory != self.in_memory_post_thumb:
                s += "Disk cache after thumbnail / preview extraction:\n[{}]\n".format(
                    self.in_memory_post_thumb)
        if self.bytes_cached is not None and self.bytes_cached_post_thumb is not None:
            if self.bytes_cached == self.bytes_cached_post_thumb:
                s += "Cached: {:,}KB of {:,}KB\n".format(
                    self.bytes_cached, self.total)
            else:
                s += "Cached: {:,}KB(+{:,}KB after extraction) of {:,}KB\n".format(
                    self.bytes_cached, self.bytes_cached_post_thumb,
                    self.total)

        if self.minimum_exif_read_size_in_bytes_thumbnail is not None:
            s += "Minimum read size for thumbnail or first preview: {}\n".format(
                format_size_for_user(
                    self.minimum_exif_read_size_in_bytes_thumbnail))
        if self.minimum_exif_read_size_in_bytes_orientation is not None:
            s += "Minimum read size to extract orientation tag: {}\n".format(
                format_size_for_user(
                    self.minimum_exif_read_size_in_bytes_orientation))
        if (self.minimum_exif_read_size_in_bytes_orientation is None
                and self.orientation is not None
                and not self.analyze_previews):
            s += "Could not extract orientation tag with minimal read\n"
        if self.minimum_exif_read_size_in_bytes_datetime is not None:
            s += "Minimum read size to extract datetime tag: {}\n".format(
                format_size_for_user(
                    self.minimum_exif_read_size_in_bytes_datetime))
        if (self.minimum_exif_read_size_in_bytes_datetime is None
                and self.datetime is not None and not self.analyze_previews):
            s += "Could not extract datetime tag with minimal read\n"
        if self.minimum_metadata_read_size_in_bytes_all is not None:
            s += "Minimum read size to extract variety of tags: {}\n".format(
                format_size_for_user(
                    self.minimum_metadata_read_size_in_bytes_all))
        elif self.in_memory is not None:
            s += "Could not extract variety of tags with minimal read\n"
        return s
def analyze_photos(photos: List[PhotoAttributes], verbose: bool,
                   analyze_previews: bool) -> None:

    if analyze_previews:
        previews_by_extension = defaultdict(list)
        for pa in photos:  # type: PhotoAttributes
            previews_by_extension[pa.ext].append(
                (pa.preview_size_and_types, pa.has_exif_thumbnail))
        exts = list(previews_by_extension.keys())
        exts.sort()
        print("\nImage previews:")
        for ext in exts:
            print(ext, Counter(previews_by_extension[ext]).most_common())
            print()
        if verbose:
            print()
            for pa in photos:
                print(pa)
        return

    size_by_extension = defaultdict(list)
    orientation_read = defaultdict(list)
    datetime_read = defaultdict(list)
    variety_read = defaultdict(list)
    thumbnail_read = defaultdict(list)

    for pa in photos:  # type: PhotoAttributes
        size_by_extension[pa.ext].append(pa.bytes_cached_post_thumb)
        if pa.minimum_exif_read_size_in_bytes_orientation is not None:
            orientation_read[pa.ext].append(
                pa.minimum_exif_read_size_in_bytes_orientation)
        if pa.minimum_exif_read_size_in_bytes_datetime is not None:
            datetime_read[pa.ext].append(
                pa.minimum_exif_read_size_in_bytes_datetime)
        if pa.minimum_metadata_read_size_in_bytes_all is not None:
            variety_read[pa.ext].append(
                pa.minimum_metadata_read_size_in_bytes_all)
        if pa.minimum_exif_read_size_in_bytes_thumbnail is not None:
            thumbnail_read[pa.ext].append(
                pa.minimum_exif_read_size_in_bytes_thumbnail)

    exts = list(size_by_extension.keys())
    exts.sort()
    print("\nKB cached after thumbnail extraction:")
    for ext in exts:
        print(ext, Counter(size_by_extension[ext]).most_common())

    exts = list(thumbnail_read.keys())
    exts.sort()
    print("\nThumbnail or preview read:")
    for ext in exts:
        print(ext, Counter(thumbnail_read[ext]).most_common())
        m = max(thumbnail_read[ext])
        max_bytes = round(int(m) * 1.2)
        print(
            ext,
            "max ({}) + 20%: {} {}".format(m, max_bytes,
                                           format_size_for_user(max_bytes)),
        )

    exts = list(orientation_read.keys())
    exts.sort()
    print("\nOrientation tag read:")
    for ext in exts:
        print(ext, Counter(orientation_read[ext]).most_common())

    exts = list(datetime_read.keys())
    exts.sort()
    print("\nDate time tag read:")
    for ext in exts:
        print(ext, Counter(datetime_read[ext]).most_common())

    exts = list(variety_read.keys())
    exts.sort()
    print("\nVariety of tags read:")
    for ext in exts:
        print(ext, Counter(variety_read[ext]).most_common())
        m = max(variety_read[ext])
        print(ext, "max + 20%:", round(int(m) * 1.2))

    print()
    if verbose:
        for pa in photos:
            print(pa)

    file_formats = FileFormatSQL()
    for pa in photos:  # type: PhotoAttributes
        file_formats.add_format(pa)
def make_body_details(
    bytes_total: int,
    bytes_free: int,
    files_to_display: DisplayingFilesOfType,
    marked: FileTypeCounter,
    photos_size_to_download: int,
    videos_size_to_download: int,
) -> BodyDetails:
    """
    Gather the details to render for destination storage usage
    for photo and video downloads, and their backups.

    :param bytes_total:
    :param bytes_free:
    :param files_to_display:
    :param marked:
    :param photos_size_to_download:
    :param videos_size_to_download:
    :return:
    """

    bytes_total_text = format_size_for_user(bytes_total, no_decimals=0)
    existing_bytes = bytes_total - bytes_free
    existing_size = format_size_for_user(existing_bytes)

    photos = videos = photos_size = videos_size = ""

    if files_to_display != DisplayingFilesOfType.videos:
        # Translators: %(variable)s represents Python code, not a plural of the term
        # variable. You must keep the %(variable)s untranslated, or the program will
        # crash.
        photos = _("%(no_photos)s Photos") % {
            "no_photos": thousands(marked[FileType.photo])
        }
        photos_size = format_size_for_user(photos_size_to_download)
    if files_to_display != DisplayingFilesOfType.photos:
        # Translators: %(variable)s represents Python code, not a plural of the term
        # variable. You must keep the %(variable)s untranslated, or the program will
        # crash.
        videos = _("%(no_videos)s Videos") % {
            "no_videos": thousands(marked[FileType.video])
        }
        videos_size = format_size_for_user(videos_size_to_download)

    size_to_download = photos_size_to_download + videos_size_to_download
    comp1_file_size_sum = photos_size_to_download
    comp2_file_size_sum = videos_size_to_download
    comp3_file_size_sum = existing_bytes
    comp1_text = photos
    comp2_text = videos
    comp3_text = _("Used")
    comp4_text = _("Excess")
    comp1_size_text = photos_size
    comp2_size_text = videos_size
    comp3_size_text = existing_size

    bytes_to_use = size_to_download + existing_bytes
    percent_used = ""

    if bytes_total == 0:
        bytes_free_of_total = _("Device size unknown")
        comp4_file_size_sum = 0
        comp4_size_text = 0
        comp3_size_text = 0
    elif bytes_to_use > bytes_total:
        bytes_total_ = bytes_total
        bytes_total = bytes_to_use
        excess_bytes = bytes_to_use - bytes_total_
        comp4_file_size_sum = excess_bytes
        comp4_size_text = format_size_for_user(excess_bytes)
        # Translators: %(variable)s represents Python code, not a plural of the term
        # variable. You must keep the %(variable)s untranslated, or the program will
        # crash.
        bytes_free_of_total = _("No space free on %(size_total)s device"
                                ) % dict(size_total=bytes_total_text)
    else:
        comp4_file_size_sum = 0
        comp4_size_text = 0
        bytes_free = bytes_total - bytes_to_use
        # Translators: %(variable)s represents Python code, not a plural of the term
        # variable. You must keep the %(variable)s untranslated, or the program will
        # crash.
        bytes_free_of_total = _("%(size_free)s free of %(size_total)s") % dict(
            size_free=format_size_for_user(bytes_free, no_decimals=1),
            size_total=bytes_total_text,
        )

    return BodyDetails(
        bytes_total_text=bytes_total_text,
        bytes_total=bytes_total,
        percent_used_text=percent_used,
        bytes_free_of_total=bytes_free_of_total,
        comp1_file_size_sum=comp1_file_size_sum,
        comp2_file_size_sum=comp2_file_size_sum,
        comp3_file_size_sum=comp3_file_size_sum,
        comp4_file_size_sum=comp4_file_size_sum,
        comp1_text=comp1_text,
        comp2_text=comp2_text,
        comp3_text=comp3_text,
        comp4_text=comp4_text,
        comp1_size_text=comp1_size_text,
        comp2_size_text=comp2_size_text,
        comp3_size_text=comp3_size_text,
        comp4_size_text=comp4_size_text,
        color1=QColor(CustomColors.color1.value),
        color2=QColor(CustomColors.color2.value),
        color3=QColor(CustomColors.color3.value),
        displaying_files_of_type=files_to_display,
    )