示例#1
0
文件: console.py 项目: Emantor/pysc
    def interact(self, banner=None):
        """Closely emulate the interactive Python console.

        The optional banner argument specify the banner to print
        before the first interaction; by default it prints a banner
        similar to the one printed by the real Python interpreter,
        followed by the current class name in parentheses (so as not
        to confuse this with the real interpreter -- since it's so
        close!).

        """
        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "
        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "
        cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
        if banner is None:
            self.write("Python %s on %s\n%s\n(%s)\n" %
                       (sys.version, sys.platform, cprt,
                        self.__class__.__name__))
        else:
            self.write("%s\n" % str(banner))
        more = 0
        self.run = True
        while self.run:
            try:
                if more:
                    prompt = sys.ps2
                else:
                    prompt = sys.ps1
                try:
                    line = self.raw_input(prompt)
                    # Can be None if sys.stdin was redefined
                    encoding = getattr(sys.stdin, "encoding", None)
                    if encoding and not isinstance(line, str):
                        line = line.decode(encoding)
                    if not self.run:
                        break
                except EOFError:
                    self.write("\n")
                    try:
                        from usi.api import systemc
                        systemc.stop()

                    except ImportError:
                        break
                else:
                    more = self.push(line)
            except KeyboardInterrupt:
                self.write("\nKeyboardInterrupt\n")
                self.resetbuffer()
                more = 0
示例#2
0
文件: console.py 项目: woaidr/emc2-1
    def interact(self, banner=None):
        """Closely emulate the interactive Python console.

        The optional banner argument specify the banner to print
        before the first interaction; by default it prints a banner
        similar to the one printed by the real Python interpreter,
        followed by the current class name in parentheses (so as not
        to confuse this with the real interpreter -- since it's so
        close!).

        """
        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "
        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "
        cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
        if banner is None:
            self.write(
                "Python %s on %s\n%s\n(%s)\n" %
                (sys.version, sys.platform, cprt, self.__class__.__name__))
        else:
            self.write("%s\n" % str(banner))
        more = 0
        self.run = True
        while self.run:
            try:
                if more:
                    prompt = sys.ps2
                else:
                    prompt = sys.ps1
                try:
                    line = self.raw_input(prompt)
                    # Can be None if sys.stdin was redefined
                    encoding = getattr(sys.stdin, "encoding", None)
                    if encoding and not isinstance(line, str):
                        line = line.decode(encoding)
                    if not self.run:
                        break
                except EOFError:
                    self.write("\n")
                    try:
                        from usi.api import systemc
                        systemc.stop()

                    except ImportError:
                        break
                else:
                    more = self.push(line)
            except KeyboardInterrupt:
                self.write("\nKeyboardInterrupt\n")
                self.resetbuffer()
                more = 0
示例#3
0
def stop(*k, **kw):
    if api.is_running():
        api.stop()
    from usi import shell
    if shell.is_running():
        shell.stop()
示例#4
0
文件: systemc.py 项目: Emantor/pysc
def stop(*k, **kw):
  if api.is_running():
      api.stop()
  from usi import shell
  if shell.is_running():
      shell.stop()