root/trunk/umitGUI/Icons.py @ 2617

Revision 2617, 4.8 kB (checked in by xvg, 6 years ago)

Merge r5865, r5866, r5867, r5870, r5871, r5872, and r5881 from Nmap Umit branch.
Remove .dmp files from share/umit/config. There are files of the same names in share/umit/misc that are more up to date. The ones in config are not mentioned in the manifest.

Remove umit.db from the windows and macosx MANIFEST.in files. Also don't try to
copy umit.db when creating the user config directory. Running as a non-root
user made the copy fail, which caused an attempt to modify the umit.db in
/usr/share/umit/config, which caused a crash. Running as root worked because
the copy of umit.db (implemented by reading the contents then writing them
again) doesn't open the /usr/share database read-only, which creates a
zero-byte file which is then successfully copied. Files should probably be
opened read-only when doing these copies to avoid anomalies like this.

In copy_config_file, open the copied file in read-only mode to avoid accidentally creating it.

Simplify the code that loads icons and make it platform-independent.

Unify the three MANIFEST.in files now that they can be identical.

Install SVG icons on all platforms in the same way. I'm going to try to find the common parts of the setup.pys so that they might be combined.

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (C) 2005 Insecure.Com LLC.
5#
6# Author: Adriano Monteiro Marques <py.adriano@gmail.com>
7#         Cleber Rodrigues <cleber.gnu@gmail.com>
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23import gtk
24import gobject
25import re
26import sys
27import os.path
28
29from umitCore.Paths import Path
30from umitCore.UmitConf import is_maemo
31from umitCore.UmitLogging import log
32
33icon_names = (
34# Operating Systems
35    'default',
36    'freebsd',
37    'irix',
38    'linux',
39    'macosx',
40    'openbsd',
41    'redhat',
42    'shadow_man',
43    'solaris',
44    'ubuntu',
45    'unknown',
46    'win',
47# Vulnerability Levels
48    'vl_1',
49    'vl_2',
50    'vl_3',
51    'vl_4',
52    'vl_5')
53
54pixmap_path = Path.pixmaps_dir
55if pixmap_path:
56    # This is a generator that returns file names for pixmaps in the order they
57    # should be tried.
58    def get_pixmap_file_names(icon_name, size):
59        yield '%s.svg' % icon_name
60        yield '%s_%s.png' % (icon_name, size)
61
62    iconfactory = gtk.IconFactory()
63    for icon_name in icon_names:
64        for type, size in (('icon', '32'), ('logo', '75')):
65            key = '%s_%s' % (icon_name, type)
66            # Look for a usable image file.
67            for file_name in get_pixmap_file_names(icon_name, size):
68                file_path = os.path.join(pixmap_path, file_name)
69                try:
70                    pixbuf = gtk.gdk.pixbuf_new_from_file(file_path)
71                    break
72                except gobject.GError:
73                    # Try again.
74                    pass
75            else:
76                log.warn('Could not find the icon for %s at any of (%s) in %s' % (icon_name, ', '.join(get_pixmap_file_names(icon_name, size)), pixmap_path))
77                continue
78            iconset = gtk.IconSet(pixbuf)
79            iconfactory.add(key, iconset)
80            log.debug('Register %s icon name for file %s' % (key, file_path))
81    iconfactory.add_default()
82
83def get_os_icon(os_match):
84    return get_os(os_match, 'icon')
85
86def get_os_logo(os_match):
87    return get_os(os_match, 'logo')
88
89def get_os(os_match, type):
90    if os_match:
91        if re.findall('[rR][eE][dD][ ]+[hH][aA][tT]', os_match):
92            # Linux icon
93            return 'redhat_%s'%type
94        elif re.findall('[uU][bB][uU][nN][tT][uU]', os_match):
95            # Linux icon
96            return 'ubuntu_%s'%type
97        elif re.findall('[lL][iI][nN][uU][xX]', os_match):
98            # Linux icon
99            return 'linux_%s'%type
100        elif re.findall('[wW][iI][nN][dD][oO][wW][sS]', os_match):
101            #print '>>> Match windows!'
102            # Windows icon
103            return 'win_%s'%type
104        elif re.findall('[oO][pP][eE][nN][bB][sS][dD]', os_match):
105            # OpenBSD icon
106            return 'openbsd_%s'%type
107        elif re.findall('[fF][rR][eE][eE][bB][sS][dD]', os_match):
108            # FreeBSD icon
109            return 'freebsd_%s'%type
110        elif re.findall('[nN][eE][tT][bB][sS][dD]', os_match):
111            # NetBSD icon
112            return 'default_%s'%type
113        elif re.findall('[sS][oO][lL][aA][rR][iI][sS]',os_match):
114            # Solaris icon
115            return 'solaris_%s'%type
116        elif re.findall('[oO][pP][eE][nN].*[sS][oO][lL][aA][rR][iI][sS]',\
117                        os_match):
118            # OpenSolaris icon
119            return 'solaris_%s'%type
120        elif re.findall('[iI][rR][iI][xX]',os_match):
121            # Irix icon
122            return 'irix_%s'%type
123        elif re.findall('[mM][aA][cC].*[oO][sS].*[xX]',os_match):
124            # Mac OS X icon
125            return 'macosx_%s'%type
126        elif re.findall('[mM][aA][cC].*[oO][sS]',os_match):
127            # Mac OS icon
128            return 'macosx_%s'%type
129        else:
130            # Default OS icon
131            return 'default_%s'%type
132    else:
133        # This is the icon for unkown OS
134        # Can't be a scary icon, like stop, cancel, etc.
135        return 'unknown_%s'%type
136
137def get_vulnerability_logo(open_ports):
138    open_ports = int(open_ports)
139    if open_ports < 3:
140        return 'vl_1_logo'
141    elif open_ports < 5:
142        return 'vl_2_logo'
143    elif open_ports < 7:
144        return 'vl_3_logo'
145    elif open_ports < 9:
146        return 'vl_4_logo'
147    else:
148        return 'vl_5_logo'
Note: See TracBrowser for help on using the browser.