Beispiel #1
0
 def configure_mac(cls, configuration=None):
     """ configure the way to open a file for mac """
 
     if configuration is None:
         configuration = {'text_editor': None,
                          'eps_viewer':None,
                          'web_browser':None}
     
     for key in configuration:
         if key == 'text_editor':
             # Treat text editor ONLY text base editor !!
             if configuration[key] and not misc.which(configuration[key]):
                 logger.warning('Specified text editor %s not valid.' % \
                                                          configuration[key])
             elif configuration[key]:
                 # All is good
                 cls.text_editor = configuration[key]
                 continue
             #Need to find a valid default
             if os.environ.has_key('EDITOR'):
                 cls.text_editor = os.environ['EDITOR']
             else:
                 cls.text_editor = cls.find_valid(
                                     ['vi', 'emacs', 'vim', 'gedit', 'nano'],
                                      'text editor')
           
         elif key in ['eps_viewer', 'web_browser']:
             if configuration[key]:
                 cls.eps_viewer = configuration[key]
                 continue
Beispiel #2
0
 def open_mac_program(self, program, file_path):
   """ open a text with the text editor """
   
   if not program:
       # Ask to mac manager
       os.system('open %s' % file_path)
   elif misc.which(program):
       # shell program
       subprocess.call([program, file_path])
   else:
      # not shell program
      os.system('open -a %s %s' % (program, file_path))
Beispiel #3
0
 def find_valid(possibility, program='program'):
     """find a valid shell program in the list"""
     
     for p in possibility:
         if misc.which(p):
             logger.warning('Using default %s \"%s\". ' % (program, p) + \
                          'Set another one in ./input/mg5_configuration.txt')
             return p
     
     logger.warning('No valid %s found. ' % program + \
                                'Please set in ./input/mg5_configuration.txt')
     return None