Exemple #1
0
 def main(self):
     # Create global options parser.
     self.gparser = gparser = self.create_global_parser()
 
     # Declare subcommands.
     subcmds = all_cmds
 
     # subcommand completions
     scmap = {}
     for sc in subcmds:
         for n in sc.names:
             scmap[n] = sc
   
     if optcomplete:
         listcter = optcomplete.ListCompleter(scmap.keys())
         subcter = optcomplete.NoneCompleter()
         optcomplete.autocomplete(
             gparser, listcter, None, subcter, subcommands=scmap)
     elif 'COMP_LINE' in os.environ:
         return -1
 
     gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
     if args and args[0] =='help':
         sc.parser.print_help()
         sys.exit(0)
     try:
         sc.execute(args)
     except exception.BaseException,e:
         lines = e.msg.splitlines()
         for l in lines:
             log.error(l)
         #log.error(e.msg)
         sys.exit(1)
Exemple #2
0
 def completer(self):
     if optcomplete:
         try:
             cfg = config.StarFlowConfig()
             cfg.load()
             return optcomplete.ListCompleter(cfg.get_cluster_names())
         except Exception, e:
             log.error('something went wrong fix me: %s' % e)
Exemple #3
0
 def completer(self):
     if optcomplete:
         try:
             cfg = config.StarFlowConfig()
             cfg.load()
             return optcomplete.ListCompleter(cfg.get_cluster_names())
         except Exception, e:
             log.error('something went wrong fix me: %s' % e)
Exemple #4
0
 def execute(self,args):
         
     
     DE_MANAGER = de.DataEnvironmentManager()             
     if args:
         local_name = args[0]
         reg_info = DE_MANAGER.get_registry_info(local_name = local_name) 
         os.environ["WORKING_DE_PATH"] = reg_info["root_dir"]
          
     WORKING_DE = DE_MANAGER.working_de
              
     for modname in starflow.__all__:
         log.info('Importing module %s' % modname)
         fullname = starflow.__name__ + '.' + modname
         try:
             __import__(fullname)
             locals()[modname] = sys.modules[fullname]
         except ImportError,e:
             log.error("Error loading module %s: %s" % (modname, e))
Exemple #5
0
 def parse_subcommands(self,gparser, subcmds):
 
     """Parse given global arguments, find subcommand from given list of
     subcommand objects, parse local arguments and return a tuple of global
     options, selected command object, command options, and command arguments.
     Call execute() on the command object to run. The command object has members
     'gopts' and 'opts' set for global and command options respectively, you
     don't need to call execute with those but you could if you wanted to."""
     
     print self.get_description()
 
     # Build map of name -> command and docstring.
     gparser.usage += '\n\nAvailable Actions\n'
     for sc in subcmds:
         helptxt = sc.__doc__.splitlines()[3].strip()
         gparser.usage += '- %s: %s\n' % (', '.join(sc.names),
                                        helptxt)
         for n in sc.names:
             assert n not in self.subcmds_map
             self.subcmds_map[n] = sc
 
     # Declare and parse global options.
     gparser.disable_interspersed_args()
 
     gopts, args = gparser.parse_args()
     if not args:
         gparser.print_help()
         raise SystemExit("\nError: you must specify an action.")
     subcmdname, subargs = args[0], args[1:]
 
     # set debug level if specified
     if gopts.DEBUG:
         console.setLevel(DEBUG)
     # load StarFlowConfig into global options
     try:
         cfg = config.StarFlowConfig()
         cfg.load()
     except exception.ConfigNotFound,e:
         log.error(e.msg)
         e.display_options()
         sys.exit(1)
Exemple #6
0
    def parse_subcommands(self, gparser, subcmds):
        """Parse given global arguments, find subcommand from given list of
        subcommand objects, parse local arguments and return a tuple of global
        options, selected command object, command options, and command arguments.
        Call execute() on the command object to run. The command object has members
        'gopts' and 'opts' set for global and command options respectively, you
        don't need to call execute with those but you could if you wanted to."""

        print self.get_description()

        # Build map of name -> command and docstring.
        gparser.usage += '\n\nAvailable Actions\n'
        for sc in subcmds:
            helptxt = sc.__doc__.splitlines()[3].strip()
            gparser.usage += '- %s: %s\n' % (', '.join(sc.names), helptxt)
            for n in sc.names:
                assert n not in self.subcmds_map
                self.subcmds_map[n] = sc

        # Declare and parse global options.
        gparser.disable_interspersed_args()

        gopts, args = gparser.parse_args()
        if not args:
            gparser.print_help()
            raise SystemExit("\nError: you must specify an action.")
        subcmdname, subargs = args[0], args[1:]

        # set debug level if specified
        if gopts.DEBUG:
            console.setLevel(DEBUG)
        # load StarFlowConfig into global options
        try:
            cfg = config.StarFlowConfig()
            cfg.load()
        except exception.ConfigNotFound, e:
            log.error(e.msg)
            e.display_options()
            sys.exit(1)
Exemple #7
0
    def main(self):
        # Create global options parser.
        self.gparser = gparser = self.create_global_parser()

        # Declare subcommands.
        subcmds = all_cmds

        # subcommand completions
        scmap = {}
        for sc in subcmds:
            for n in sc.names:
                scmap[n] = sc

        if optcomplete:
            listcter = optcomplete.ListCompleter(scmap.keys())
            subcter = optcomplete.NoneCompleter()
            optcomplete.autocomplete(gparser,
                                     listcter,
                                     None,
                                     subcter,
                                     subcommands=scmap)
        elif 'COMP_LINE' in os.environ:
            return -1

        gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
        if args and args[0] == 'help':
            sc.parser.print_help()
            sys.exit(0)
        try:
            sc.execute(args)
        except exception.BaseException, e:
            lines = e.msg.splitlines()
            for l in lines:
                log.error(l)
            #log.error(e.msg)
            sys.exit(1)
Exemple #8
0
            return -1
    
        gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
        if args and args[0] =='help':
            sc.parser.print_help()
            sys.exit(0)
        try:
            sc.execute(args)
        except exception.BaseException,e:
            lines = e.msg.splitlines()
            for l in lines:
                log.error(l)
            #log.error(e.msg)
            sys.exit(1)
        except socket.gaierror,e:
            log.error("Unable to connect: %s" % e)
            log.error("Check your internet connection?")
            sys.exit(1)
        except Exception,e:
            import traceback
            if not gopts.DEBUG:
                traceback.print_exc()
            log.debug(traceback.format_exc())
            print
            log.error("Oops! Looks like you've found a bug in StarFlow")
            log.error("Debug file written to: %s" % static.DEBUG_FILE)
            log.error("Please submit this file, minus any private information,")
            log.error("to [email protected]")
            sys.exit(1)

    def test():
Exemple #9
0
 def ipy_shell():
     log.error("Unable to load IPython.")
     log.error("Please check that IPython is installed and working.")
     log.error("If not, you can install it via: easy_install ipython")
Exemple #10
0
            return -1

        gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
        if args and args[0] == 'help':
            sc.parser.print_help()
            sys.exit(0)
        try:
            sc.execute(args)
        except exception.BaseException, e:
            lines = e.msg.splitlines()
            for l in lines:
                log.error(l)
            #log.error(e.msg)
            sys.exit(1)
        except socket.gaierror, e:
            log.error("Unable to connect: %s" % e)
            log.error("Check your internet connection?")
            sys.exit(1)
        except Exception, e:
            import traceback
            if not gopts.DEBUG:
                traceback.print_exc()
            log.debug(traceback.format_exc())
            print
            log.error("Oops! Looks like you've found a bug in StarFlow")
            log.error("Debug file written to: %s" % static.DEBUG_FILE)
            log.error(
                "Please submit this file, minus any private information,")
            log.error("to [email protected]")
            sys.exit(1)