root/trunk/umitGUI/Icons.py @ 1306

Revision 1306, 5.7 kB (checked in by boltrix, 6 years ago)

More work on installers, umitCore.Paths and umitCore.Logging which now has been renamed to umitCore.UmitLogging?. Windows installers are working fine, yet, a script updating the Paths's configuration is need as well as more test on it. Also, Linux installers seens to be working fine. The Mac OS X App generator is half-way done, and have some issues while importing cairo yet. Also, hardcoded the paths to umitCore.Paths and made a basic test suite to ensure that it is working. More testing is needed, and probably some minor bugs shal raise.

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 re
25import sys
26import os.path
27
28from umitCore.Paths import Path
29from umitCore.UmitConf import is_maemo
30from umitCore.UmitLogging import log
31
32######################
33# Platform recognition
34PLATFORM = sys.platform
35if is_maemo():
36    PLATFORM = "maemo"
37
38icons = []
39
40icon_names = (\
41    # Operating Systems
42    'default',
43    'freebsd',
44    'irix',
45    'linux',
46    'macosx',
47    'openbsd',
48    'redhat',
49    'shadow_man',
50    'solaris',
51    'ubuntu',
52    'unknown',
53    'win',
54   
55    # Vulnerability Levels
56    'vl_1',
57    'vl_2',
58    'vl_3',
59    'vl_4',
60    'vl_5')
61
62
63
64pixmap_path = Path.pixmaps_dir
65if pixmap_path:
66    if PLATFORM == 'linux2':
67        # FIXME: This naming scheme should be more consistent
68        # All icon or all logo, and not mixed up
69        for icon_name in icon_names[0:12]:
70            file_path = os.path.join(pixmap_path, '%s.svg' % icon_name)
71            (key, val) = ('%s_icon' % icon_name, file_path)
72            if os.path.exists(file_path):
73                log.debug('Register %s icon name for file %s' % (key, val))
74                icons.append(('%s_icon' % icon_name, file_path))
75            else:
76                log.warn('Could not find %s file for icon name %s' % (val, key))
77
78        for icon_name in icon_names[12:]:
79            file_path = os.path.join(pixmap_path, '%s.svg' % icon_name)
80            (key, val) = ('%s_logo' % icon_name, file_path)
81            if os.path.exists(file_path):
82                log.debug('Register %s icon name for file %s' % (key, val))
83                icons.append(('%s_logo' % icon_name, file_path))
84            else:
85                log.warning('Could not find %s file for icon name %s' % (val, key))       
86    else:
87        for icon_name in icon_names:
88            for variant in (('icon', '32'), ('logo', '75')):
89                #log.debug('Pixmap Path: %s' % pixmap_path)
90                file_path = os.path.join(pixmap_path, '%s_%s.png' % (icon_name, variant[1]))
91                (key, val) = ('%s_%s' % (icon_name, variant[0]), file_path)
92                if os.path.exists(file_path):
93                    #log.debug('Register %s icon name for file %s' % (key, val))
94                    icons.append((key, val))
95                else:
96                    log.warn('Could not find %s file for icon name %s' % (val, key))
97
98
99iconfactory = gtk.IconFactory()
100
101for stock_id, file in icons:
102    # only load image files when our stock_id is not present
103    pixbuf = gtk.gdk.pixbuf_new_from_file(file)
104    iconset = gtk.IconSet(pixbuf)
105    iconfactory.add(stock_id, iconset)
106    iconfactory.add_default()
107
108def get_os_icon(os_match):
109    return get_os(os_match, 'icon')
110
111def get_os_logo(os_match):
112    if PLATFORM != 'linux2':
113        return get_os(os_match, 'logo')
114    return get_os(os_match, 'icon')
115
116def get_os(os_match, type):
117    if os_match:
118        if re.findall('[rR][eE][dD][ ]+[hH][aA][tT]', os_match):
119            # Linux icon
120            return 'redhat_%s'%type
121        elif re.findall('[uU][bB][uU][nN][tT][uU]', os_match):
122            # Linux icon
123            return 'ubuntu_%s'%type
124        elif re.findall('[lL][iI][nN][uU][xX]', os_match):
125            # Linux icon
126            return 'linux_%s'%type
127        elif re.findall('[wW][iI][nN][dD][oO][wW][sS]', os_match):
128            #print '>>> Match windows!'
129            # Windows icon
130            return 'win_%s'%type
131        elif re.findall('[oO][pP][eE][nN][bB][sS][dD]', os_match):
132            # OpenBSD icon
133            return 'openbsd_%s'%type
134        elif re.findall('[fF][rR][eE][eE][bB][sS][dD]', os_match):
135            # FreeBSD icon
136            return 'freebsd_%s'%type
137        elif re.findall('[nN][eE][tT][bB][sS][dD]', os_match):
138            # NetBSD icon
139            return 'default_%s'%type
140        elif re.findall('[sS][oO][lL][aA][rR][iI][sS]',os_match):
141            # Solaris icon
142            return 'solaris_%s'%type
143        elif re.findall('[oO][pP][eE][nN].*[sS][oO][lL][aA][rR][iI][sS]',\
144                        os_match):
145            # OpenSolaris icon
146            return 'solaris_%s'%type
147        elif re.findall('[iI][rR][iI][xX]',os_match):
148            # Irix icon
149            return 'irix_%s'%type
150        elif re.findall('[mM][aA][cC].*[oO][sS].*[xX]',os_match):
151            # Mac OS X icon
152            return 'macosx_%s'%type
153        elif re.findall('[mM][aA][cC].*[oO][sS]',os_match):
154            # Mac OS icon
155            return 'macosx_%s'%type
156        else:
157            # Default OS icon
158            return 'default_%s'%type
159    else:
160        # This is the icon for unkown OS
161        # Can't be a scary icon, like stop, cancel, etc.
162        return 'unknown_%s'%type
163
164def get_vulnerability_logo(open_ports):
165    open_ports = int(open_ports)
166    if open_ports < 3:
167        return 'vl_1_logo'
168    elif open_ports < 5:
169        return 'vl_2_logo'
170    elif open_ports < 7:
171        return 'vl_3_logo'
172    elif open_ports < 9:
173        return 'vl_4_logo'
174    else:
175        return 'vl_5_logo'
Note: See TracBrowser for help on using the browser.