Esempio n. 1
0
    def do_connect(self, args):
        """
Connect to a Mercury instance
usage: connect [--port <port>] ip
Use adb forward tcp:31415 tcp:31415 when using an emulator or usb-connected device
        """

        # Define command-line arguments using argparse
        parser = BaseArgumentParser(prog='connect', add_help=False)
        parser.add_argument('ip')
        parser.add_argument('--port', '-p', metavar='<port>')

        try:
            # Split arguments using shlex - this means that parameters with spaces can be used - escape " characters inside with \
            splitargs = parser.parse_args(shlex.split(args))

            if not splitargs:
                return

            # Get session ip
            sessionip = splitargs.ip

            # Get session port
            if (splitargs.port):
                sessionport = int(splitargs.port)
            else:
                sessionport = 31415

            # Create new session object - display success/failure with session id
            newsession = Session(splitargs.ip, sessionport, "bind")

            # Check if connection can be established
            if newsession.executeCommand("core", "ping", None).data == "pong":

                # Start new session
                subconsole = Menu(newsession)
                subconsole.cmdloop()

            else:
                print "\n**Network Error** Could not connect to " + sessionip + ":" + str(
                    sessionport) + "\n"

        # FIXME: Choose specific exceptions to catch
        except Exception:
            print sys.exc_info()[0]
Esempio n. 2
0
    def do_connect(self, args):
        """
Connect to a Mercury instance
usage: connect [--port <port>] ip
Use adb forward tcp:31415 tcp:31415 when using an emulator or usb-connected device
        """

        # Define command-line arguments using argparse
        parser = BaseArgumentParser(prog = 'connect', add_help = False)
        parser.add_argument('ip')
        parser.add_argument('--port', '-p', metavar = '<port>')

        try:
            # Split arguments using shlex - this means that parameters with spaces can be used - escape " characters inside with \
            splitargs = parser.parse_args(shlex.split(args))
            
            if not splitargs:
                return

            # Get session ip
            sessionip = splitargs.ip

            # Get session port
            if (splitargs.port):
                sessionport = int(splitargs.port)
            else:
                sessionport = 31415

            # Create new session object - display success/failure with session id
            newsession = Session(splitargs.ip, sessionport, "bind")

            # Check if connection can be established
            if newsession.executeCommand("core", "ping", None).data == "pong":

                # Start new session
                subconsole = Menu(newsession)
                subconsole.cmdloop()

            else:
                print "\n**Network Error** Could not connect to " + sessionip + ":" + str(sessionport) + "\n"

        # FIXME: Choose specific exceptions to catch
        except Exception:
            print sys.exc_info()[0]
Esempio n. 3
0
    def __init__(self):
        """
When using a resource file as input, remember to always end the file with "exit" command,
otherwise Mercury will enter in an infinite loop.
        """
        parser = BaseArgumentParser(prog='mercury.py', add_help=False)
        parser.add_argument('--resource', '-r', metavar='<resource>')

        sys.argv.remove(sys.argv[0])

        splitargs = parser.parse_args(sys.argv)

        if splitargs is not None:
            resourceFile = splitargs.resource
            if resourceFile is not None:
                sys.stdin = open(resourceFile)
        else:
            raise AttributeError()

        BaseCmd.__init__(self, None)
        self.prompt = "mercury> "
        self.intro = """
Esempio n. 4
0
    def __init__(self):
        """
When using a resource file as input, remember to always end the file with "exit" command,
otherwise Mercury will enter in an infinite loop.
        """
        parser = BaseArgumentParser(prog = 'mercury.py', add_help = False)
        parser.add_argument('--resource', '-r', metavar = '<resource>')

        sys.argv.remove(sys.argv[0])

        splitargs = parser.parse_args(sys.argv)

        if splitargs is not None:
            resourceFile = splitargs.resource
            if resourceFile is not None:
                sys.stdin = open(resourceFile)
        else:
            raise AttributeError()

        BaseCmd.__init__(self, None)
        self.prompt = "mercury> "
        self.intro = """