diff options
author | Jeffrey C Honig <jeffrey.honig@windriver.com> | 2012-07-17 00:03:59 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-07-18 14:29:29 +0100 |
commit | 76a16c0c11f4df5aeebbf2af6e63b1a739aac354 (patch) | |
tree | 9fe0439822e3cbc66ac2d99b46d38df88b0587e1 /meta | |
parent | 04c2ee40f6bba6c0446c8df5ef78ab42d3cf0270 (diff) | |
download | poky-76a16c0c11f4df5aeebbf2af6e63b1a739aac354.tar.gz |
terminal.py: Fix Xfce on ubuntu/debian; some cleanup
* Xfce class was setting and passing wrong variable for ubuntu/debian.
* Xfce class was using -e instead of -x for passing command. The former creates
a shell escape nightmare
* Clean up local and instance/class variables with same name but different usage.
* Remove side-effect and directly return formatted command for clarity.
(From OE-Core rev: b2ee5c5e34cdc3d65ca7b5da3486360a74d6c500)
Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oe/terminal.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py index 43639d5ddd..28abf147b9 100644 --- a/meta/lib/oe/terminal.py +++ b/meta/lib/oe/terminal.py | |||
@@ -28,11 +28,10 @@ class Registry(oe.classutils.ClassRegistry): | |||
28 | class Terminal(Popen): | 28 | class Terminal(Popen): |
29 | __metaclass__ = Registry | 29 | __metaclass__ = Registry |
30 | 30 | ||
31 | def __init__(self, command, title=None, env=None): | 31 | def __init__(self, sh_cmd, title=None, env=None): |
32 | self.format_command(command, title) | 32 | fmt_sh_cmd = self.format_command(sh_cmd, title) |
33 | |||
34 | try: | 33 | try: |
35 | Popen.__init__(self, self.command, env=env) | 34 | Popen.__init__(self, fmt_sh_cmd, env=env) |
36 | except OSError as exc: | 35 | except OSError as exc: |
37 | import errno | 36 | import errno |
38 | if exc.errno == errno.ENOENT: | 37 | if exc.errno == errno.ENOENT: |
@@ -40,16 +39,16 @@ class Terminal(Popen): | |||
40 | else: | 39 | else: |
41 | raise | 40 | raise |
42 | 41 | ||
43 | def format_command(self, command, title): | 42 | def format_command(self, sh_cmd, title): |
44 | fmt = {'title': title or 'Terminal', 'command': command} | 43 | fmt = {'title': title or 'Terminal', 'command': sh_cmd} |
45 | if isinstance(self.command, basestring): | 44 | if isinstance(self.command, basestring): |
46 | self.command = shlex.split(self.command.format(**fmt)) | 45 | return shlex.split(self.command.format(**fmt)) |
47 | else: | 46 | else: |
48 | self.command = [element.format(**fmt) for element in self.command] | 47 | return [element.format(**fmt) for element in self.command] |
49 | 48 | ||
50 | class XTerminal(Terminal): | 49 | class XTerminal(Terminal): |
51 | def __init__(self, command, title=None, env=None): | 50 | def __init__(self, sh_cmd, title=None, env=None): |
52 | Terminal.__init__(self, command, title, env) | 51 | Terminal.__init__(self, sh_cmd, title, env) |
53 | if not os.environ.get('DISPLAY'): | 52 | if not os.environ.get('DISPLAY'): |
54 | raise UnsupportedTerminal(self.name) | 53 | raise UnsupportedTerminal(self.name) |
55 | 54 | ||
@@ -75,14 +74,14 @@ class Konsole(XTerminal): | |||
75 | command = 'konsole -T "{title}" -e {command}' | 74 | command = 'konsole -T "{title}" -e {command}' |
76 | priority = 2 | 75 | priority = 2 |
77 | 76 | ||
78 | def __init__(self, command, title=None, env=None): | 77 | def __init__(self, sh_cmd, title=None, env=None): |
79 | # Check version | 78 | # Check version |
80 | vernum = check_konsole_version("konsole") | 79 | vernum = check_konsole_version("konsole") |
81 | if vernum: | 80 | if vernum: |
82 | if vernum.split('.')[0] == "2": | 81 | if vernum.split('.')[0] == "2": |
83 | logger.debug(1, 'Konsole from KDE 4.x will not work as devshell, skipping') | 82 | logger.debug(1, 'Konsole from KDE 4.x will not work as devshell, skipping') |
84 | raise UnsupportedTerminal(self.name) | 83 | raise UnsupportedTerminal(self.name) |
85 | XTerminal.__init__(self, command, title, env) | 84 | XTerminal.__init__(self, sh_cmd, title, env) |
86 | 85 | ||
87 | class XTerm(XTerminal): | 86 | class XTerm(XTerminal): |
88 | command = 'xterm -T "{title}" -e {command}' | 87 | command = 'xterm -T "{title}" -e {command}' |
@@ -95,8 +94,8 @@ class Rxvt(XTerminal): | |||
95 | class Screen(Terminal): | 94 | class Screen(Terminal): |
96 | command = 'screen -D -m -t "{title}" -S devshell {command}' | 95 | command = 'screen -D -m -t "{title}" -S devshell {command}' |
97 | 96 | ||
98 | def __init__(self, command, title=None, env=None): | 97 | def __init__(self, sh_cmd, title=None, env=None): |
99 | Terminal.__init__(self, command, title, env) | 98 | Terminal.__init__(self, sh_cmd, title, env) |
100 | logger.warn('Screen started. Please connect in another terminal with ' | 99 | logger.warn('Screen started. Please connect in another terminal with ' |
101 | '"screen -r devshell"') | 100 | '"screen -r devshell"') |
102 | 101 | ||
@@ -104,18 +103,18 @@ class Screen(Terminal): | |||
104 | def prioritized(): | 103 | def prioritized(): |
105 | return Registry.prioritized() | 104 | return Registry.prioritized() |
106 | 105 | ||
107 | def spawn_preferred(command, title=None, env=None): | 106 | def spawn_preferred(sh_cmd, title=None, env=None): |
108 | """Spawn the first supported terminal, by priority""" | 107 | """Spawn the first supported terminal, by priority""" |
109 | for terminal in prioritized(): | 108 | for terminal in prioritized(): |
110 | try: | 109 | try: |
111 | spawn(terminal.name, command, title, env) | 110 | spawn(terminal.name, sh_cmd, title, env) |
112 | break | 111 | break |
113 | except UnsupportedTerminal: | 112 | except UnsupportedTerminal: |
114 | continue | 113 | continue |
115 | else: | 114 | else: |
116 | raise NoSupportedTerminals() | 115 | raise NoSupportedTerminals() |
117 | 116 | ||
118 | def spawn(name, command, title=None, env=None): | 117 | def spawn(name, sh_cmd, title=None, env=None): |
119 | """Spawn the specified terminal, by name""" | 118 | """Spawn the specified terminal, by name""" |
120 | logger.debug(1, 'Attempting to spawn terminal "%s"', name) | 119 | logger.debug(1, 'Attempting to spawn terminal "%s"', name) |
121 | try: | 120 | try: |
@@ -123,10 +122,10 @@ def spawn(name, command, title=None, env=None): | |||
123 | except KeyError: | 122 | except KeyError: |
124 | raise UnsupportedTerminal(name) | 123 | raise UnsupportedTerminal(name) |
125 | 124 | ||
126 | pipe = terminal(command, title, env) | 125 | pipe = terminal(sh_cmd, title, env) |
127 | output = pipe.communicate()[0] | 126 | output = pipe.communicate()[0] |
128 | if pipe.returncode != 0: | 127 | if pipe.returncode != 0: |
129 | raise ExecutionError(pipe.command, pipe.returncode, output) | 128 | raise ExecutionError(sh_cmd, pipe.returncode, output) |
130 | 129 | ||
131 | def check_konsole_version(konsole): | 130 | def check_konsole_version(konsole): |
132 | import subprocess as sub | 131 | import subprocess as sub |