from subprocess import * import string, sys import os import cmd import readline import curses class Console(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) self.prompt = "JonnuxCommand>>> " def do_title(self, arg): """Displays the welcome message that is displayed when Jonnux is first run again""" print """ ############################################ ############################################ ## Jonnux 1.0.3 ## ## Type help for info ## ## Or type help 'subject' ## ## For specific help ## ## Have Fun!... ## ############################################ ############################################ """ def do_about(self, arg): """About Jonnux""" print "Jonnux is a Python powered Command Line Interpreter. We hold internal commands as well as the capability to exexute external commands via the 'shell' command. For more information about Jonnux visit us on sourceforge: http://jonnux.sourceforge.net" def do_credits(self, arg): """Displays the credits of Jonnux""" print """By Jonny from http://netshed.info, contact him/us at jonny@netshed.info, visit the project website at: http://jonnux.sourceforge.net""" def do_shortcuts(self, arg): """The Shortcuts that can be used in Jonnux""" print """CTRL + B Moves the cursor backward one character. CTRL + C Cancels the currently running command. CTRL + D Logs out of the current session. CTRL + F Moves the cursor forward one character. CTRL + H Erase one character. Similar to pressing backspace. CTRL + P Paste previous line and/or lines. CTRL + S Stops all output on screen (XOFF). CTRL + Q Turns all output stopped on screen back on (XON). CTRL + U Erases the complete line. ? Shortcut to the 'help' command ! Shortcut to the 'shell' command """ def do_hist(self, args): """Displays the commands recently used on Jonnux""" print self._hist def do_exit(self, args): """Exit Jonnux, alternativley use the Cntrl + D shortcut""" return -1 def do_EOF(self, args): """Quit on the system, EOF = End of File. Exit Jonnux """ return self.do_exit(args) def do_shell(self, args): """Use an external system command whilst in Jonnux, such as sudo. For example to use the sudo system command type 'shell sudo' or '! sudo', the '!' symbol can also be used instead of the 'shell' command, remember the commands used in Jonnux may have an effect on your computer through this command!""" os.system(args) def do_help(self, args): """ Get help on a certain subject 'help' or '?' prints a list of commands for use on Jonnux 'help ' or '? ' gives help on Note, when using 'help ' you do not use the '' symbols, for example, type 'help exit' for information about the exit command. 'help ' will not work """ cmd.Cmd.do_help(self, args) def preloop(self): """Initialization before prompting user for commands. Despite the claims in the Cmd documentaion, Cmd.preloop() is not a stub. """ cmd.Cmd.preloop(self) self._hist = [] self._locals = {} self._globals = {} def postloop(self): """Loop """ cmd.Cmd.postloop(self) print "Exiting Jonnux... have a nice day" ,r def precmd(self, line): """ After a line has been executed """ self._hist += [ line.strip() ] return line def postcmd(self, stop, line): """ Post Commands """ return stop def emptyline(self): """Do not pass the previously used code on Jonnux""" pass def default(self, line): """Execute as python whilst outside of Jonnux """ try: exec(line) in self._locals, self._globals except Exception, e: print e.__class__, ":", e r= raw_input("""\033[1;37m\n ############################################ ############################################ ## Jonnux 1.0.3 ## ## Type help for info ## ## Or type help 'subject' ## ## For specific help ## ## Have Fun!... ## ############################################ ############################################ ~~~~~~~~~~~~~~~~~~~~ Please enter your name to continue: """) print """ \033[1;32mWelcome,""" ,r print""" \033[1;31m*Warning*: The font color scheme used on Jonnux will carry on running even after the use of the commands 'exit' or 'EOF'. To exit the color schemes and to reset your terminal, simply type 'reset' after use...Enjoy. \033[1;37m\n """ if __name__ == '__main__': console = Console() console . cmdloop()