summaryrefslogtreecommitdiff
path: root/examples/block-size-column.py
blob: c59d3e6fab29044fb783b998854c26ae8238761e (plain)
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
import os

try:
    # Python 3.
    from urllib.parse import unquote
except:
    # Python 2.
    from urllib import unquote

from gi.repository import GObject, Caja

class ColumnExtension(GObject.GObject, Caja.ColumnProvider, Caja.InfoProvider):
    def __init__(self):
        pass
    
    def get_columns(self):
        return Caja.Column(name="CajaPython::block_size_column",
                               attribute="block_size",
                               label="Block size",
                               description="Get the block size"),

    def update_file_info(self, file):
        if file.get_uri_scheme() != 'file':
            return
        
        filename = unquote(file.get_uri()[7:])
        
        file.add_string_attribute('block_size', str(os.stat(filename).st_blksize))