File: clamtk.py

package info (click to toggle)
clamtk 5.24-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,228 kB
  • sloc: perl: 4,336; python: 34; makefile: 11
file content (64 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
#
# ClamTk, copyright (C) 2004-2015 Dave M
#
# This file is part of ClamTk
# https://bitbucket.org/dave_theunsub/clamtk-gnome
#
# ClamTk is free software; you can redistribute it and/or modify it
# under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
# Foundation; either version 1, or (at your option) any later version, or
#
# b) the "Artistic License".

import os
import urllib
import re

import locale
locale.setlocale(locale.LC_ALL, '')

import gettext
_ = lambda x: gettext.ldgettext("clamtk", x)

from gi.repository import Nautilus, GObject

class OpenTerminalExtension(GObject.GObject, Nautilus.MenuProvider):
       
    def _open_scanner(self, file):
        filename = urllib.unquote(file.get_uri()[7:])
        filename = re.escape(filename)

        #os.chdir(filename)
        os.system('clamtk %s &' % filename)
        
    def menu_activate_cb(self, menu, file):
        self._open_scanner(file)
        
    def menu_background_activate_cb(self, menu, file): 
        self._open_scanner(file)
       
    def get_file_items(self, window, files):
        if len(files) != 1:
            return
        
        file = files[0]
        #if not file.is_directory() or file.get_uri_scheme() != 'file':
        #    return
        
        item = Nautilus.MenuItem(name='NautilusPython::openscanner',
                                 label=_('Scan for threats...') ,
                                 tip=_('Scan %s for threats...') % file.get_name(),
                                 icon='clamtk')
        item.connect('activate', self.menu_activate_cb, file)
        return item,

    def get_background_items(self, window, file):
        item = Nautilus.MenuItem(name='NautilusPython::openscanner_directory',
                                 label=_('Scan directory for threats...'),
                                 tip=_('Scan this directory for threats...'),
                                 icon='clamtk')
        item.connect('activate', self.menu_background_activate_cb, file)
        return item,