File: md5sum-property-page.py

package info (click to toggle)
nemo-python 5.6.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 384 kB
  • sloc: xml: 1,732; ansic: 795; python: 157; makefile: 9
file content (47 lines) | stat: -rw-r--r-- 1,296 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import hashlib
import urllib

from gi.repository import Nemo, Gtk, GObject

class MD5SumPropertyPage(GObject.GObject, Nemo.PropertyPageProvider):
    def __init__(self):
        pass

    def get_property_pages(self, files):
        if len(files) != 1:
            return

        file = files[0]
        if file.get_uri_scheme() != 'file':
            return

        if file.is_directory():
            return

        filename = urllib.unquote(file.get_uri()[7:])

        self.property_label = Gtk.Label('MD5Sum')
        self.property_label.show()

        self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
        self.hbox.show()

        label = Gtk.Label('MD5Sum:')
        label.show()
        self.hbox.pack_start(label, False, False, 0)

        self.value_label = Gtk.Label()
        self.hbox.pack_start(self.value_label, False, False, 0)

        md5sum = hashlib.md5()
        with open(filename,'rb') as f:
            for chunk in iter(lambda: f.read(8192), ''):
                md5sum.update(chunk)
        f.close()

        self.value_label.set_text(md5sum.hexdigest())
        self.value_label.show()

        return Nemo.PropertyPage(name="NemoPython::md5_sum",
                                 label=self.property_label,
                                 page=self.hbox),