Changeset 568 in tailor
- Timestamp:
- 08/15/05 10:30:19 (8 years ago)
- Hash name:
- 20050815083019-97f81-860b34d6a698822684707bdc261d55aef3b1ba27
- File:
-
- 1 edited
-
vcpx/shwrap.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vcpx/shwrap.py
r420 r568 4 4 # :Autore: Lele Gaifax <lele@nautilus.homeip.net> 5 5 # :Licenza: GNU General Public License 6 # 6 # 7 7 8 8 __docformat__ = 'reStructuredText' … … 28 28 from tempfile import mkstemp 29 29 from os import close 30 30 31 31 fd, self.name = mkstemp(suffix, prefix, dir, text) 32 32 close(fd) 33 33 34 34 def __del__(self): 35 35 self.shutdown() 36 36 37 37 def shutdown(self): 38 38 from os import remove 39 39 40 40 remove(self.name) 41 41 … … 52 52 FORCE_ENCODING = None 53 53 """Force the output encoding to some other charset instead of user prefs.""" 54 54 55 55 def __init__(self, command=None, cwd=None): 56 56 """Initialize a ExternalCommand instance, specifying the command … … 62 62 self.cwd = cwd 63 63 """The working directory, go there before execution.""" 64 64 65 65 self.exit_status = None 66 66 """Once the command has been executed, this is its exit status.""" … … 68 68 self._last_command = None 69 69 """Last executed command.""" 70 70 71 71 def __str__(self): 72 72 result = [] … … 78 78 for arg in self._last_command or self.command: 79 79 bs_buf = [] 80 80 81 81 # Add a space to separate this argument from the others 82 82 result.append(' ') … … 88 88 for c in arg: 89 89 if c == '\\': 90 # Don't know if we need to double yet. 90 # Don't know if we need to double yet. 91 91 bs_buf.append(c) 92 92 elif c == '"': 93 # Double backspaces. 93 # Double backspaces. 94 94 result.append('\\' * len(bs_buf)*2) 95 95 bs_buf = [] … … 102 102 result.append(c) 103 103 104 # Add remaining backspaces, if any. 104 # Add remaining backspaces, if any. 105 105 if bs_buf: 106 106 result.extend(bs_buf) … … 111 111 112 112 return ''.join(result) 113 113 114 114 def execute(self, *args, **kwargs): 115 115 """Execute the command.""" … … 118 118 from os import environ 119 119 from cStringIO import StringIO 120 120 121 121 self.exit_status = None 122 122 … … 126 126 else: 127 127 self._last_command.extend(args) 128 128 129 129 if self.VERBOSE: 130 130 stderr.write(str(self)) … … 145 145 146 146 input = kwargs.get('input') 147 147 148 148 try: 149 149 process = Popen(self._last_command, … … 158 158 self.exit_status = -1 159 159 return 160 160 161 161 if input: 162 162 input = input.encode(self.FORCE_ENCODING or getdefaultencoding()) 163 163 164 164 out = process.communicate(input=input)[0] 165 165 if out: 166 166 out = StringIO(out) 167 167 self.exit_status = process.returncode 168 168 169 169 if self.VERBOSE: 170 170 if not self.exit_status: … … 172 172 else: 173 173 stderr.write(" [Status %s]\n" % self.exit_status) 174 174 175 175 return out 176
Note: See TracChangeset
for help on using the changeset viewer.
