Changeset 49677


Ignore:
Timestamp:
Dec 12, 2011, 5:46:00 AM (13 years ago)
Author:
martinl
Message:

g.extension.py: be tidy citizen also on Windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/branches/develbranch_6/gui/scripts/g.extension.py

    r49611 r49677  
    271271    except HTTPError:
    272272        grass.fatal(_("GRASS Addons <%s> not found") % options['extension'])
    273    
     273
     274    grass.message(_("Installation of <%s> successfully finished.") % options['extension'])
     275
    274276# install extension
    275277def install_extension():
     
    280282    if grass.find_program(options['extension'], ['--help']):
    281283        grass.warning(_("Extension <%s> already installed. Will be updated...") % options['extension'])
    282 
     284   
    283285    if sys.platform == "win32":
    284286        install_extension_win()
    285287    else:
    286288        install_extension_other()
     289   
     290    # cleanup build cruft
     291    if not flags['s']:
     292        tidy_citizen()
     293   
     294    if not os.environ.has_key('GRASS_ADDON_PATH') or \
     295            not os.environ['GRASS_ADDON_PATH']:
     296        grass.warning(_('This add-on module will not function until you set the '
     297                        'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
    287298   
    288299    # manual page: fix href
     
    310321            fd.close()
    311322
    312     # symlink for binaries needed, see http://trac.osgeo.org/grass/changeset/49124
    313     src = None
    314     if sys.platform == 'win32':
    315         bin_ext = '.exe'
    316         sct_ext  = '.bat'
    317     else:
    318         bin_ext = sct_ext = ''
    319    
    320     if os.path.exists(os.path.join(options['prefix'], 'bin',
    321                                    options['extension'] + bin_ext)):
    322         src = os.path.join(options['prefix'], 'bin', options['extension']) + bin_ext
    323         dst = os.path.join(options['prefix'], options['extension']) + bin_ext
    324     else:
    325         if sys.platform == 'win32':
    326             pdir = 'bin'
    327         else:
    328             pdir = 'scripts'
    329         if os.path.exists(os.path.join(options['prefix'], pdir,
    330                                        options['extension'] + sct_ext)):
    331             src = os.path.join(options['prefix'], pdir, options['extension']) + sct_ext
    332             dst = os.path.join(options['prefix'], options['extension']) + sct_ext
    333    
    334     if src and not os.path.exists(dst):
    335         if sys.platform == 'win32':
    336             shutil.copyfile(src, dst)
    337         else:
    338             os.symlink(src, dst)
    339    
    340     if not os.environ.has_key('GRASS_ADDON_PATH') or \
    341             not os.environ['GRASS_ADDON_PATH']:
    342         grass.warning(_('This add-on module will not function until you set the '
    343                         'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
    344 
    345323# install extension on other plaforms
    346324def install_extension_other():
     
    428406        grass.message(_("Installation of <%s> successfully finished.") % options['extension'])
    429407   
    430     # cleanup build cruft
    431     if not flags['s']:
    432         # move script/ and bin/ to main dir
    433         if os.path.exists(os.path.join(options['prefix'], 'bin', options['extension'])):
    434             shutil.move(os.path.join(options['prefix'], 'bin', options['extension']),
    435                         os.path.join(options['prefix'], options['extension']))
     408# remove dir if empty
     409def remove_empty_dir(path):
     410    if os.path.exists(path) and not os.listdir(path):
     411        os.removedirs(path)
     412
     413# see http://lists.osgeo.org/pipermail/grass-dev/2011-December/056938.html
     414def tidy_citizen():
     415    if sys.platform == 'win32':
     416        EXT_BIN = '.exe'
     417        EXT_SCT = '.bat'
     418    else:
     419        EXT_BIN = EXT_SCT = ''
     420   
     421    # move script/ and bin/ to main dir
     422    if os.path.exists(os.path.join(options['prefix'], 'bin', options['extension']) + EXT_BIN):
     423        shutil.move(os.path.join(options['prefix'], 'bin', options['extension']) + EXT_BIN,
     424                    os.path.join(options['prefix'], options['extension']) + EXT_BIN)
     425    if sys.platform == 'win32':
     426        if os.path.exists(os.path.join(options['prefix'], 'bin', options['extension']) + EXT_SCT):
     427            shutil.move(os.path.join(options['prefix'], 'bin', options['extension']) + EXT_SCT,
     428                        os.path.join(options['prefix'], options['extension']) + EXT_SCT)
     429    else:
    436430        if os.path.exists(os.path.join(options['prefix'], 'scripts', options['extension'])):
    437431            shutil.move(os.path.join(options['prefix'], 'scripts', options['extension']),
    438432                        os.path.join(options['prefix'], options['extension']))
    439        
    440         # if empty, rmdir scripts/ and bin/
    441         if os.path.exists(os.path.join(options['prefix'], 'bin')):
    442             if os.listdir(os.path.join(options['prefix'], 'bin')) == []:
    443                 os.removedirs(os.path.join(options['prefix'], 'bin'))
    444        
    445         if os.path.exists(os.path.join(options['prefix'], 'scripts')):
    446             if os.listdir(os.path.join(options['prefix'], 'scripts')) == []:
    447                 os.removedirs(os.path.join(options['prefix'], 'scripts'))
    448        
    449         # move man/ into docs/
    450         if os.path.exists(os.path.join(options['prefix'], 'man', 'man1', options['extension'] + '.1')):
    451             shutil.move(os.path.join(options['prefix'], 'man', 'man1', options['extension'] + '.1'),
    452                         os.path.join(options['prefix'], 'docs', 'man', 'man1', options['extension'] + '.1'))
    453        
    454         # if empty, rmdir man/man1
    455         if os.path.exists(os.path.join(options['prefix'], 'man', 'man1')):
    456             if os.listdir(os.path.join(options['prefix'], 'man', 'man1')) == []:
    457                 os.removedirs(os.path.join(options['prefix'], 'man', 'man1'))
    458        
    459         # if empty, rmdir man/
    460         if os.path.exists(os.path.join(options['prefix'], 'man')):
    461             if os.listdir(os.path.join(options['prefix'], 'man')) == []:
    462                 os.removedirs(os.path.join(options['prefix'], 'man'))
    463    
    464     if not os.environ.has_key('GRASS_ADDON_PATH') or \
    465             not os.environ['GRASS_ADDON_PATH']:
    466         grass.warning(_('This add-on module will not function until you set the '
    467                         'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
    468 
     433   
     434    # move man/ into docs/
     435    if os.path.exists(os.path.join(options['prefix'], 'man', 'man1', options['extension'] + '.1')):
     436        shutil.move(os.path.join(options['prefix'], 'man', 'man1', options['extension'] + '.1'),
     437                    os.path.join(options['prefix'], 'docs', 'man', 'man1', options['extension'] + '.1'))
     438       
     439    # if empty, rmdir bin, etc, man, scripts
     440    for d in ('bin', 'etc', os.path.join('man', 'man1'), 'man', 'scripts'):
     441        remove_empty_dir(os.path.join(options['prefix'], d))
     442   
    469443# remove existing extension (reading XML file)
    470444def remove_extension(force = False):
Note: See TracChangeset for help on using the changeset viewer.