Show
Ignore:
Timestamp:
09/25/07 06:56:58 (6 years ago)
Author:
xvg
Message:

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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/umitGUI/Icons.py

    r1306 r2617  
    2222 
    2323import gtk 
     24import gobject 
    2425import re 
    2526import sys 
     
    3031from umitCore.UmitLogging import log 
    3132 
    32 ###################### 
    33 # Platform recognition 
    34 PLATFORM = sys.platform 
    35 if is_maemo(): 
    36     PLATFORM = "maemo" 
    37  
    38 icons = [] 
    39  
    40 icon_names = (\ 
    41     # Operating Systems 
     33icon_names = ( 
     34# Operating Systems 
    4235    'default', 
    4336    'freebsd', 
     
    5245    'unknown', 
    5346    'win', 
    54      
    55     # Vulnerability Levels 
     47# Vulnerability Levels 
    5648    'vl_1', 
    5749    'vl_2', 
     
    6052    'vl_5') 
    6153 
    62  
    63  
    6454pixmap_path = Path.pixmaps_dir 
    6555if 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)) 
     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 
    7575            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  
    99 iconfactory = gtk.IconFactory() 
    100  
    101 for 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) 
     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)) 
    10681    iconfactory.add_default() 
    10782 
     
    11085 
    11186def get_os_logo(os_match): 
    112     if PLATFORM != 'linux2': 
    113         return get_os(os_match, 'logo') 
    114     return get_os(os_match, 'icon') 
     87    return get_os(os_match, 'logo') 
    11588 
    11689def get_os(os_match, type):