Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96d8842

Browse files
committed
Implement idle command interface as suggested by GvR [idle-dev] 16 July
**************** PyShell: Added functionality: usage: idle.py [-c command] [-d] [-i] [-r script] [-s] [-t title] [arg] ... idle file(s) (without options) edit the file(s) -c cmd run the command in a shell -d enable the debugger -i open an interactive shell -i file(s) open a shell and also an editor window for each file -r script run a file as a script in a shell -s run $IDLESTARTUP or $PYTHONSTARTUP before anything else -t title set title of shell window Remaining arguments are applied to the command (-c) or script (-r). ****************** idles: Removed the idles script, not needed ****************** idle: Removed the IdleConf references, not required anymore
1 parent 0eb4f3e commit 96d8842

3 files changed

Lines changed: 26 additions & 38 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -709,17 +709,19 @@ def isatty(self):
709709
return 1
710710

711711
usage_msg = """\
712-
usage: idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
712+
usage: idle.py [-c command] [-d] [-i] [-r script] [-s] [-t title] [arg] ...
713713
714-
-c command run this command
715-
-d enable debugger
716-
-e edit mode; arguments are files to be edited
717-
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
718-
-t title set title of shell window
714+
idle file(s) (without options) edit the file(s)
719715
720-
When neither -c nor -e is used, and there are arguments, and the first
721-
argument is not '-', the first argument is run as a script. Remaining
722-
arguments are arguments to the script or to the command run by -c.
716+
-c cmd run the command in a shell
717+
-d enable the debugger
718+
-i open an interactive shell
719+
-i file(s) open a shell and also an editor window for each file
720+
-r script run a file as a script in a shell
721+
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
722+
-t title set title of shell window
723+
724+
Remaining arguments are applied to the command (-c) or script (-r).
723725
"""
724726

725727
class usageError:
@@ -781,29 +783,34 @@ def main(self, argv, noshell):
781783
cmd = None
782784
edit = 0
783785
debug = 0
786+
interactive = 0
787+
script = None
784788
startup = 0
785789

786790
try:
787-
opts, args = getopt.getopt(argv, "c:deist:")
791+
opts, args = getopt.getopt(argv, "c:dir:st:")
788792
except getopt.error, msg:
789793
sys.stderr.write("Error: %s\n" % str(msg))
790794
sys.stderr.write(usage_msg)
791795
sys.exit(2)
792796

793797
for o, a in opts:
794-
noshell = 0
798+
noshell = 0 # There are options, bring up a shell
795799
if o == '-c':
796800
cmd = a
797801
if o == '-d':
798802
debug = 1
799-
if o == '-e':
800-
edit = 1
803+
if o == '-i':
804+
interactive = 1
805+
if o == '-r':
806+
script = a
801807
if o == '-s':
802808
startup = 1
803809
if o == '-t':
804810
PyShell.shell_title = a
805811

806812
if noshell: edit=1
813+
if interactive and args and args[0] != "-": edit = 1
807814

808815
for i in range(len(sys.path)):
809816
sys.path[i] = os.path.abspath(sys.path[i])
@@ -860,9 +867,11 @@ def main(self, argv, noshell):
860867
shell.open_debugger()
861868
if cmd:
862869
interp.execsource(cmd)
863-
elif not edit and args and args[0] != "-":
864-
interp.execfile(args[0])
865-
870+
elif script:
871+
if os.path.isfile(script):
872+
interp.execfile(script)
873+
else:
874+
print "No script file: ", script
866875
shell.begin()
867876

868877
self.idle()

Lib/idlelib/idle

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
#! /usr/bin/env python
22

3-
import os
4-
import sys
5-
from idlelib import IdleConf
6-
7-
idle_dir = os.path.dirname(IdleConf.__file__)
8-
IdleConf.load(idle_dir)
9-
10-
# defer importing Pyshell until IdleConf is loaded
11-
from idlelib import PyShell
3+
import PyShell
124
PyShell.main()

Lib/idlelib/idles

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)