~osomon/phatch/extract-all-metadata

« back to all changes in this revision

Viewing changes to phatch/lib/openImage.py

  • Committer: spe.stani.be at gmail
  • Date: 2010-03-21 15:20:18 UTC
  • mto: (1887.1.6 windows)
  • mto: This revision was merged to the branch mainline in revision 1892.
  • Revision ID: spe.stani.be@gmail.com-20100321152018-5b2okrvh9t4eogco
refactoring system.call and making all test filenames unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
        temp_file = temp.path
170
170
        command.append(temp_file)
171
171
    try:
172
 
        output, error = system.shell(command)
 
172
        stdout, stderr, err = system.call_out_err(command)
173
173
        if os.path.exists(temp_file):
174
 
            image = Image.open(temp_file)
175
 
            image.load()  # otherwise temp file can't be deleted
 
174
            # copy() otherwise temp file can't be deleted
 
175
            image = Image.open(temp_file).copy()
176
176
            image.info['Convertor'] = app
177
177
            return image
178
178
    finally:
182
182
            os.remove(temp_file)
183
183
    message = _('Could not open image with %s.') % app + \
184
184
        '\n\n%s: %s\n\n%s: %s\n\n%s: %s' % \
185
 
        (_('Command'), command, _('Output'), output, _('Error'), error)
 
185
        (_('Command'), command, _('Output'), stdout, _('Error'), stderr)
186
186
    raise IOError(message)
187
187
 
188
188
 
213
213
                if not (key in result):
214
214
                    result[key] = value
215
215
 
216
 
            source, err = system.shell((TIFFINFO, filename))
217
 
            if 'Error' in source:
 
216
            stdout, stderr, err = system.call_out_err(
 
217
                (TIFFINFO, filename),
 
218
                universal_newlines=True,
 
219
            )
 
220
            if 'Error' in stdout:
218
221
                try:
219
222
                    temp_file = system.TempFile()
220
223
                    shutil.copy2(filename, temp_file.path)
221
 
                    source, err = system.shell((TIFFINFO, temp_file.path))
 
224
                    stdout, stderr, err = system.call_out_err(
 
225
                        (TIFFINFO, temp_file.path),
 
226
                        universal_newlines=True,
 
227
                    )
222
228
                finally:
223
229
                    if not temp:
224
230
                        temp_file.close()
225
231
            else:
226
232
                temp_file = None
227
 
            for match in RE_TIFF_FIELD.finditer(source):
 
233
            for match in RE_TIFF_FIELD.finditer(stdout):
228
234
                value = match.group(2)
229
235
                again = RE_TIFF_FIELD_IMAGE.search(value)
230
236
                if again:
304
310
                if option:
305
311
                    input.extend(option)
306
312
                input.extend([temp.path, temp_c.path])
307
 
                out, err = system.shell(input)
 
313
                stdout, stderr, err = system.call_out_err(
 
314
                    input,
 
315
                    universal_newlines=True,
 
316
                )
308
317
            finally:
309
318
                temp.close()
310
319
                temp_c.close(dest=filename)
311
 
            if out or err:
312
 
                raise Exception('tiffcp: %s%s\n%s' % (out, err, input))
 
320
            if err or stdout or stderr:
 
321
                raise Exception('tiffcp: %s%s\n%s' % (stdout, stderr, input))
313
322
            return ''
314
323
 
315
324
    else: