-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digipres_props_extension.py
executable file
·83 lines (71 loc) · 3.09 KB
/
digipres_props_extension.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Nautilus panel extension to return digital preservation info.
1. Install: $ sudo apt-get install nautilus-python.
2. Then place this file in: ~/.local/share/nautilus-python/extensions
3. Copy digipres_helpers.py to the same folder as well.
When you right-click files in nautilus you will see a new digital preservation
panel that will tell you some information about the file. The information can
be highlighted and selected as well so you have easy access to it if needed.
Resources:
- Extension docs: https://projects-old.gnome.org/nautilus-python/documentation/html/index.html
- Media example: https://github.com/atareao/nautilus-columns
- Nautilus examples: https://github.com/GNOME/nautilus-python/tree/13d40c16dbf2df4dd007ae7961aa86aa235c8020/examples
"""
from __future__ import print_function, unicode_literals
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
from digipres_helpers import HashHandler, SiegfriedRunner
from gi.repository import GObject, Gtk, Nautilus
class MD5SumPropertyPage(GObject.GObject, Nautilus.PropertyPageProvider):
"""Property page extension subclass for Nautilus."""
def __init__(self):
"""Class constructor."""
pass
def get_property_pages(self, files):
"""Return a property page for the information we're interested in."""
if len(files) != 1:
return
file = files[0]
if file.get_uri_scheme() != "file":
return
if file.is_directory():
return
file_name = unquote(file.get_uri()[7:])
self.property_label = Gtk.Label("Digipres")
self.property_label.show()
self.property_label.show()
self.hbox = Gtk.Box(homogeneous=False, orientation=1, spacing=0)
self.hbox.show()
puid, format_name = SiegfriedRunner().get_format_puid_pair(file_name)
# List of tuples to output in order. The first tuple is a label. The
# second determines whether a user can select the information e.g. to
# copy-and-paste somewhere else.
labels = [
("", True),
("\tDigital preservation information:", False),
("\n", False),
("\tFormat: {}".format(format_name), True),
("\tFormat ID: {}".format(puid), True),
("\tMD5: {}".format(HashHandler().get_hash(file_name, "md5")), True),
("\n", False),
("\tGenerated by: ", False),
("\t -- nautilus-python:", False),
("\t -- digtal preservation extension", False),
("\t -- v1.0", False),
("\t -- by @beet_keeper, MMXIX", False),
]
for label in labels:
gtk_label = Gtk.Label(label[0], selectable=label[1])
gtk_label.set_alignment(0, 0.5)
gtk_label.show()
self.hbox.pack_start(gtk_label, False, False, 0)
return (
Nautilus.PropertyPage(
name="NautilusPython::md5_sum",
label=self.property_label,
page=self.hbox,
),
)