Skip to content

Commit 1a12dd7

Browse files
author
Serge Guelton
committed
python 2/3 compat: commands vs subprocess
Differential Revision: https://reviews.llvm.org/D59584 llvm-svn: 356995
1 parent 25f9094 commit 1a12dd7

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed

lldb/examples/python/delta.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# available.
1717
#----------------------------------------------------------------------
1818

19-
import commands
2019
from __future__ import print_function
2120

2221
import optparse

lldb/examples/python/gdbremote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#----------------------------------------------------------------------
1818

1919
import binascii
20-
import commands
20+
import subprocess
2121
import json
2222
import math
2323
import optparse

lldb/examples/python/globals.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from __future__ import print_function
1111

1212
import lldb
13-
import commands
1413
import optparse
1514
import os
1615
import shlex

lldb/examples/python/memory.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
# (lldb) command script import /path/to/cmdtemplate.py
1010
#----------------------------------------------------------------------
1111

12-
import commands
1312
from __future__ import print_function
1413

1514
import platform
1615
import os
1716
import re
1817
import sys
1918

19+
if sys.version_info.major == 2:
20+
import commands as subprocess
21+
else:
22+
import subprocess
23+
2024
try:
2125
# Just try for LLDB in case PYTHONPATH is already correctly setup
2226
import lldb
@@ -26,7 +30,7 @@
2630
platform_system = platform.system()
2731
if platform_system == 'Darwin':
2832
# On Darwin, try the currently selected Xcode directory
29-
xcode_dir = commands.getoutput("xcode-select --print-path")
33+
xcode_dir = subprocess.getoutput("xcode-select --print-path")
3034
if xcode_dir:
3135
lldb_python_dirs.append(
3236
os.path.realpath(
@@ -53,7 +57,6 @@
5357
print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
5458
sys.exit(1)
5559

56-
import commands
5760
import optparse
5861
import shlex
5962
import string

lldb/examples/python/performance.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# export PYTHONPATH=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python
99
#----------------------------------------------------------------------
1010

11-
import commands
1211
from __future__ import print_function
1312

1413
import optparse
@@ -20,6 +19,11 @@
2019
import time
2120
import types
2221

22+
if sys.version_info.major == 2:
23+
import commands as subprocess
24+
else:
25+
import subprocess
26+
2327
#----------------------------------------------------------------------
2428
# Code that auto imports LLDB
2529
#----------------------------------------------------------------------
@@ -32,7 +36,7 @@
3236
platform_system = platform.system()
3337
if platform_system == 'Darwin':
3438
# On Darwin, try the currently selected Xcode directory
35-
xcode_dir = commands.getoutput("xcode-select --print-path")
39+
xcode_dir = subprocess.getoutput("xcode-select --print-path")
3640
if xcode_dir:
3741
lldb_python_dirs.append(
3842
os.path.realpath(
@@ -303,7 +307,7 @@ def __init__(self, pid):
303307
self.value = dict()
304308

305309
def Measure(self):
306-
output = commands.getoutput(self.command).split("\n")[-1]
310+
output = subprocess.getoutput(self.command).split("\n")[-1]
307311
values = re.split('[-+\s]+', output)
308312
for (idx, stat) in enumerate(values):
309313
multiplier = 1

lldb/examples/python/process_events.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
# export PYTHONPATH=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python
99
#----------------------------------------------------------------------
1010

11-
import commands
1211
from __future__ import print_function
1312

1413
import optparse
1514
import os
1615
import platform
1716
import sys
1817

18+
if sys.version_info.major == 2:
19+
import commands as subprocess
20+
else:
21+
import subprocess
22+
1923
#----------------------------------------------------------------------
2024
# Code that auto imports LLDB
2125
#----------------------------------------------------------------------
@@ -28,7 +32,7 @@
2832
platform_system = platform.system()
2933
if platform_system == 'Darwin':
3034
# On Darwin, try the currently selected Xcode directory
31-
xcode_dir = commands.getoutput("xcode-select --print-path")
35+
xcode_dir = subprocess.getoutput("xcode-select --print-path")
3236
if xcode_dir:
3337
lldb_python_dirs.append(
3438
os.path.realpath(

lldb/examples/python/stacks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/python
22
from __future__ import print_function
33
import lldb
4-
import commands
54
import optparse
65
import shlex
76

lldb/examples/python/types.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# (lldb) command script import /path/to/cmdtemplate.py
1010
#----------------------------------------------------------------------
1111

12-
import commands
1312
from __future__ import print_function
1413

1514
import platform
@@ -18,6 +17,11 @@
1817
import signal
1918
import sys
2019

20+
if sys.version_info.major == 2:
21+
import commands as subprocess
22+
else:
23+
import subprocess
24+
2125
try:
2226
# Just try for LLDB in case PYTHONPATH is already correctly setup
2327
import lldb
@@ -27,7 +31,7 @@
2731
platform_system = platform.system()
2832
if platform_system == 'Darwin':
2933
# On Darwin, try the currently selected Xcode directory
30-
xcode_dir = commands.getoutput("xcode-select --print-path")
34+
xcode_dir = subprocess.getoutput("xcode-select --print-path")
3135
if xcode_dir:
3236
lldb_python_dirs.append(
3337
os.path.realpath(
@@ -54,7 +58,6 @@
5458
print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly")
5559
sys.exit(1)
5660

57-
import commands
5861
import optparse
5962
import shlex
6063
import time

lldb/scripts/verify_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
import commands
3+
import subprocess
44
import optparse
55
import os
66
import os.path
@@ -11,7 +11,7 @@
1111
def extract_exe_symbol_names(arch, exe_path, match_str):
1212
command = 'dsymutil --arch %s -s "%s" | grep "%s" | colrm 1 69' % (
1313
arch, exe_path, match_str)
14-
(command_exit_status, command_output) = commands.getstatusoutput(command)
14+
(command_exit_status, command_output) = subprocess.getstatusoutput(command)
1515
if command_exit_status == 0:
1616
if command_output:
1717
return command_output[0:-1].split("'\n")

0 commit comments

Comments
 (0)