annotate Lib/plat-mac/terminalcommand.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents e7a6a4515ab0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27090
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
1 """terminalcommand.py -- A minimal interface to Terminal.app.
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
2
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
3 To run a shell command in a new Terminal.app window:
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
4
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
5 import terminalcommand
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
6 terminalcommand.run("ls -l")
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
7
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
8 No result is returned; it is purely meant as a quick way to run a script
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
9 with a decent input/output window.
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
10 """
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
11
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
12 #
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
13 # This module is a fairly straightforward translation of Jack Jansen's
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
14 # Mac/OSX/PythonLauncher/doscript.m.
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
15 #
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
16
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46629
diff changeset
17 from warnings import warnpy3k
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 46967
diff changeset
18 warnpy3k("In 3.x, the terminalcommand module is removed.", stacklevel=2)
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46629
diff changeset
19
27090
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
20 import time
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
21 import os
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
22 from Carbon import AE
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
23 from Carbon.AppleEvents import *
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
24
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
25
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
26 TERMINAL_SIG = "trmx"
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
27 START_TERMINAL = "/usr/bin/open /Applications/Utilities/Terminal.app"
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
28 SEND_MODE = kAENoReply # kAEWaitReply hangs when run from Terminal.app itself
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
29
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
30
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
31 def run(command):
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
32 """Run a shell command in a new Terminal.app window."""
46629
3f84e6ae36da Fix for #1905: PythonLauncher not working correctly on OSX 10.5/Leopard
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 29576
diff changeset
33 termAddress = AE.AECreateDesc(typeApplicationBundleID, "com.apple.Terminal")
29576
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
34 theEvent = AE.AECreateAppleEvent(kAECoreSuite, kAEDoScript, termAddress,
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
35 kAutoGenerateReturnID, kAnyTransactionID)
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
36 commandDesc = AE.AECreateDesc(typeChar, command)
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
37 theEvent.AEPutParamDesc(kAECommandClass, commandDesc)
27090
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
38
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
39 try:
29576
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
40 theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
27090
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
41 except AE.Error, why:
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
42 if why[0] != -600: # Terminal.app not yet running
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
43 raise
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
44 os.system(START_TERMINAL)
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
45 time.sleep(1)
29576
f93b919e5729 some old changes to this unused module
Just van Rossum <just@letterror.com>
parents: 27090
diff changeset
46 theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
27090
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
47
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
48
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
49 if __name__ == "__main__":
3a295ceba401 module to run commands in a Terminal.app window
Just van Rossum <just@letterror.com>
parents:
diff changeset
50 run("ls -l")