Small update
[PyCatFile.git] / pyshell.py
blob0f923f40106589af9b56e6d0998e9b8524348b1b
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
13 Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
14 Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: pyshell.py - Last Update: 7/10/2024 Ver. 0.13.12 RC 1 - Author: cooldude2k $
17 '''
19 from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
20 import sys
21 import os
22 import traceback
23 import code
24 import re
25 import readline
26 import pycatfile
27 from sys import argv
28 from pycatfile import *
30 taskfound = False
31 if(len(sys.argv) < 2):
32 taskfound = True
33 ps1 = "PyShell " + \
34 str(sys.version_info[0])+"."+str(sys.version_info[1]
35 )+"."+str(sys.version_info[2])+"> "
36 cmdinput = None
37 print("PyShell "+sys.version+" on "+sys.platform+os.linesep+"Loaded Python module " +
38 pycatfile.__program_name__+" "+pycatfile.__version__+os.linesep)
39 while(True):
40 try:
41 cmdinput = code.InteractiveConsole().raw_input(ps1)
42 except KeyboardInterrupt:
43 print("\nKeyboardInterrupt")
44 except EOFError:
45 print("")
46 sys.exit(0)
47 except Exception:
48 traceback.print_exc()
49 # exec(str(cmdinput));
50 try:
51 exec(code.compile_command(str(cmdinput)))
52 except Exception:
53 traceback.print_exc()
54 sys.exit(0)
56 if(sys.argv[1] == "sh" or sys.argv[1] == "shell" or sys.argv[1] == "pysh" or sys.argv[1] == "pyshell" or sys.argv[1] == "python"):
57 taskfound = True
58 ps1 = "PyShell " + \
59 str(sys.version_info[0])+"."+str(sys.version_info[1]
60 )+"."+str(sys.version_info[2])+"> "
61 cmdinput = None
62 print("PyShell "+sys.version+" on "+sys.platform+os.linesep+"Loaded Python module " +
63 pycatfile.__program_name__+" "+pycatfile.__version__+os.linesep)
64 while(True):
65 try:
66 cmdinput = code.InteractiveConsole().raw_input(ps1)
67 except KeyboardInterrupt:
68 print("\nKeyboardInterrupt")
69 except EOFError:
70 print("")
71 sys.exit(0)
72 except Exception:
73 traceback.print_exc()
74 # exec(str(cmdinput));
75 try:
76 exec(code.compile_command(str(cmdinput)))
77 except Exception:
78 traceback.print_exc()
79 sys.exit(0)
81 if(sys.argv[1] == "shebang" or sys.argv[1] == "shabang" or sys.argv[1] == "hashbang" or sys.argv[1] == "poundbang" or sys.argv[1] == "hashexclam" or sys.argv[1] == "hashpling"):
82 taskfound = True
83 if(len(sys.argv) < 3):
84 print(str("command: "+sys.argv[0]+os.linesep+"arguments: " +
85 sys.argv[1]+os.linesep+"error: syntax error missing arguments"))
86 sys.exit(0)
87 shebang = "".join(open(sys.argv[2], "r").readlines())
88 exec(compile(str(shebang), "", "exec"))
89 sys.exit(0)
91 if(sys.argv[1] == "version" or sys.argv[1] == "ver" or sys.argv[1] == "getversion" or sys.argv[1] == "getver"):
92 taskfound = True
93 print(pycatfile.__version__)
94 sys.exit(0)
96 if(sys.argv[1] == "exec" or sys.argv[1] == "run" or sys.argv[1] == "execute"):
97 taskfound = True
98 argcmd = list(sys.argv)
99 argcmd[0:1] = []
100 argcmd = list(argcmd)
101 argcmd[0:1] = []
102 argcmd = list(argcmd)
103 argcmd = " ".join(argcmd)
104 exec(argcmd)
106 if(not taskfound):
107 print(str("command: "+sys.argv[0]+os.linesep+"arguments: " +
108 sys.argv[1]+os.linesep+"error: syntax error missing arguments"))
109 sys.exit(0)