Add files via upload
[PyCatFile.git] / pyshell.py
blob1d0dc59e523f91e2b5772bfa4df0380aa53c19d1
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: 5/15/2024 Ver. 0.11.4 RC 1 - Author: cooldude2k $
17 '''
19 from __future__ import division, absolute_import, print_function;
20 import sys, os, traceback, code, re, readline, pycatfile;
21 from sys import argv;
22 from pycatfile import *;
24 taskfound=False;
25 if(len(sys.argv)<2):
26 taskfound=True;
27 ps1="PyShell "+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"> ";
28 cmdinput=None;
29 print("PyShell "+sys.version+" on "+sys.platform+os.linesep+"Loaded Python module "+pycatfile.__program_name__+" "+pycatfile.__version__+os.linesep);
30 while(True):
31 try:
32 cmdinput = code.InteractiveConsole().raw_input(ps1);
33 except KeyboardInterrupt:
34 print("\nKeyboardInterrupt");
35 except EOFError:
36 print("");
37 sys.exit(0);
38 except Exception:
39 traceback.print_exc();
40 ## exec(str(cmdinput));
41 try:
42 exec(code.compile_command(str(cmdinput)));
43 except Exception:
44 traceback.print_exc();
45 sys.exit(0);
47 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"):
48 taskfound=True;
49 ps1="PyShell "+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"> ";
50 cmdinput=None;
51 print("PyShell "+sys.version+" on "+sys.platform+os.linesep+"Loaded Python module "+pycatfile.__program_name__+" "+pycatfile.__version__+os.linesep);
52 while(True):
53 try:
54 cmdinput = code.InteractiveConsole().raw_input(ps1);
55 except KeyboardInterrupt:
56 print("\nKeyboardInterrupt");
57 except EOFError:
58 print("");
59 sys.exit(0);
60 except Exception:
61 traceback.print_exc();
62 ## exec(str(cmdinput));
63 try:
64 exec(code.compile_command(str(cmdinput)));
65 except Exception:
66 traceback.print_exc();
67 sys.exit(0);
69 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"):
70 taskfound=True;
71 if(len(sys.argv)<3):
72 print(str("command: "+sys.argv[0]+os.linesep+"arguments: "+sys.argv[1]+os.linesep+"error: syntax error missing arguments"));
73 sys.exit(0);
74 shebang = "".join(open(sys.argv[2], "r").readlines());
75 exec(compile(str(shebang), "", "exec"));
76 sys.exit(0);
78 if(sys.argv[1]=="version" or sys.argv[1]=="ver" or sys.argv[1]=="getversion" or sys.argv[1]=="getver"):
79 taskfound=True;
80 print(pycatfile.__version__);
81 sys.exit(0);
83 if(sys.argv[1]=="exec" or sys.argv[1]=="run" or sys.argv[1]=="execute"):
84 taskfound=True;
85 argcmd = list(sys.argv);
86 argcmd[0:1] = [];
87 argcmd = list(argcmd);
88 argcmd[0:1] = [];
89 argcmd = list(argcmd);
90 argcmd = " ".join(argcmd);
91 exec(argcmd);
93 if(not taskfound):
94 print(str("command: "+sys.argv[0]+os.linesep+"arguments: "+sys.argv[1]+os.linesep+"error: syntax error missing arguments"));
95 sys.exit(0);