<s> from __future__ import absolute_import , division , print_function <EOL> import sys <EOL> import optparse <EOL> from glue import __version__ <EOL> from glue . logger import logger <EOL> def parse ( argv ) : <EOL> """<STR_LIT>""" <EOL> usage = """<STR_LIT>""" <EOL> parser = optparse . OptionParser ( usage = usage , <EOL> version = str ( __version__ ) ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , default = False ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , default = False ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT:test>' , <EOL> help = "<STR_LIT>" , default = False ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" , default = False ) <EOL> err_msg = verify ( parser , argv ) <EOL> if err_msg : <EOL> sys . stderr . write ( '<STR_LIT>' % err_msg ) <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> return parser . parse_args ( argv ) <EOL> def verify ( parser , argv ) : <EOL> """<STR_LIT>""" <EOL> opts , args = parser . parse_args ( argv ) <EOL> err_msg = None <EOL> if opts . script and opts . restore : <EOL> err_msg = "<STR_LIT>" <EOL> elif opts . script and opts . config : <EOL> err_msg = "<STR_LIT>" <EOL> elif opts . script and len ( args ) != <NUM_LIT:1> : <EOL> err_msg = "<STR_LIT>" <EOL> elif opts . restore and len ( args ) != <NUM_LIT:1> : <EOL> err_msg = "<STR_LIT>" <EOL> return err_msg <EOL> def die_on_error ( msg ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> try : <EOL> return func ( * args , ** kwargs ) <EOL> except Exception as e : <EOL> import traceback <EOL> from glue . external . qt import get_qapp <EOL> get_qapp ( ) <EOL> from glue . utils . qt import QMessageBoxPatched as QMessageBox <EOL> m = "<STR_LIT>" % ( msg , e ) <EOL> detail = str ( traceback . format_exc ( ) ) <EOL> if len ( m ) > <NUM_LIT> : <EOL> detail = "<STR_LIT>" % ( m , detail ) <EOL> m = m [ : <NUM_LIT> ] + '<STR_LIT>' <EOL> qmb = QMessageBox ( QMessageBox . Critical , "<STR_LIT>" , m ) <EOL> qmb . setDetailedText ( detail ) <EOL> qmb . show ( ) <EOL> qmb . raise_ ( ) <EOL> qmb . exec_ ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> return wrapper <EOL> return decorator <EOL> @ die_on_error ( "<STR_LIT>" ) <EOL> def restore_session ( gluefile ) : <EOL> """<STR_LIT>""" <EOL> from glue . app . qt import GlueApplication <EOL> return GlueApplication . restore_session ( gluefile ) <EOL> @ die_on_error ( "<STR_LIT>" ) <EOL> def load_data_files ( datafiles ) : <EOL> """<STR_LIT>""" <EOL> from glue . core . data_collection import DataCollection <EOL> from glue . core . data_factories import auto_data , load_data <EOL> dc = DataCollection ( ) <EOL> for df in datafiles : <EOL> dc . append ( load_data ( df , auto_data ) ) <EOL> return dc <EOL> def run_tests ( ) : <EOL> from glue import test <EOL> test ( ) <EOL> def start_glue ( gluefile = None , config = None , datafiles = None ) : <EOL> """<STR_LIT>""" <EOL> import glue <EOL> from glue . app . qt import GlueApplication <EOL> load_plugins ( ) <EOL> datafiles = datafiles or [ ] <EOL> data , hub = None , None <EOL> if gluefile is not None : <EOL> app = restore_session ( gluefile ) <EOL> return app . start ( ) <EOL> if config is not None : <EOL> glue . env = glue . config . load_configuration ( search_path = [ config ] ) <EOL> if datafiles : <EOL> data = load_data_files ( datafiles ) <EOL> if not data : <EOL> data = glue . core . DataCollection ( ) <EOL> hub = data . hub <EOL> session = glue . core . Session ( data_collection = data , hub = hub ) <EOL> ga = GlueApplication ( session = session ) <EOL> return ga . start ( ) <EOL> @ die_on_error ( "<STR_LIT>" ) <EOL> def execute_script ( script ) : <EOL> """<STR_LIT>""" <EOL> execfile ( script ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> def get_splash ( ) : <EOL> """<STR_LIT>""" <EOL> from glue . external . qt import QtGui <EOL> from glue . external . qt . QtCore import Qt <EOL> import os <EOL> pth = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> pm = QtGui . QPixmap ( pth ) <EOL> splash = QtGui . QSplashScreen ( pm , Qt . WindowStaysOnTopHint ) <EOL> splash . show ( ) <EOL> return splash <EOL> def main ( argv = sys . argv ) : <EOL> opt , args = parse ( argv [ <NUM_LIT:1> : ] ) <EOL> if opt . verbose : <EOL> logger . setLevel ( "<STR_LIT>" ) <EOL> logger . info ( "<STR_LIT>" , sys . argv ) <EOL> if opt . test : <EOL> return run_tests ( ) <EOL> elif opt . restore : <EOL> start_glue ( gluefile = args [ <NUM_LIT:0> ] , config = opt . config ) <EOL> elif opt . script : <EOL> execute_script ( args [ <NUM_LIT:0> ] ) <EOL> else : <EOL> has_file = len ( args ) == <NUM_LIT:1> <EOL> has_files = len ( args ) > <NUM_LIT:1> <EOL> has_py = has_file and args [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) <EOL> has_glu = has_file and args [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) <EOL> if has_py : <EOL> execute_script ( args [ <NUM_LIT:0> ] ) <EOL> elif has_glu : <EOL> start_glue ( gluefile = args [ <NUM_LIT:0> ] , config = opt . config ) <EOL> elif has_file or has_files : <EOL> start_glue ( datafiles = args , config = opt . config ) <EOL> else : <EOL> start_glue ( config = opt . config ) <EOL> _loaded_plugins = set ( ) <EOL> _installed_plugins = set ( ) <EOL> def load_plugins ( ) : <EOL> import setuptools <EOL> logger . info ( "<STR_LIT>" . format ( setuptools . __version__ ) ) <EOL> from glue . _plugin_helpers import iter_plugin_entry_points , PluginConfig <EOL> config = PluginConfig . load ( ) <EOL> for item in iter_plugin_entry_points ( ) : <EOL> if not item . module_name in _installed_plugins : <EOL> _installed_plugins . add ( item . name ) <EOL> if item . module_name in _loaded_plugins : <EOL> logger . info ( "<STR_LIT>" . format ( item . name ) ) <EOL> continue <EOL> if not config . plugins [ item . name ] : <EOL> continue <EOL> try : <EOL> function = item . load ( ) <EOL> function ( ) <EOL> except Exception as exc : <EOL> logger . info ( "<STR_LIT>" . format ( item . name , exc ) ) <EOL> else : <EOL> logger . info ( "<STR_LIT>" . format ( item . name ) ) <EOL> _loaded_plugins . add ( item . module_name ) <EOL> try : <EOL> config . save ( ) <EOL> except Exception as e : <EOL> logger . warn ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv ) ) </s>
