Changeset 96 for Xml/Validator/Backend/mateTiff.py
- Timestamp:
- 09/19/07 16:51:12 (14 months ago)
- Files:
-
- 1 modified
-
Xml/Validator/Backend/mateTiff.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Xml/Validator/Backend/mateTiff.py
r93 r96 8 8 """ 9 9 10 import sys 10 import sys, os, tempfile 11 11 import getopt 12 12 import Image … … 25 25 26 26 def main(argv=None): 27 print "At present this destroys multi plane TIFF files - kill process to stop changes being applied" 27 28 if argv is None: 28 29 argv = sys.argv … … 58 59 # read the xml from the tiff 59 60 theXml = image.tag[270] 60 print "Processing file : %s\n" % aFilename 61 print theXml 62 print "" 61 # print "Processing file : %s\n" % aFilename 62 # print theXml 63 # print "" 64 theNewXml = edited_text(theXml) 65 image.tag[270] = theNewXml 66 print "At present this destroys multi plane TIFF files - are you sure you want to save? y/n" 67 confirm = sys.stdin.readline()[:-1] 68 print 'confirm = \'%s\'' %(confirm) 69 if confirm in ['y', 'Y', 'Yes', 'YES', 'yes']: 70 print "Saving..." 71 image.save(aFilename) 72 print "done" 73 else: 74 print "Skipped" 63 75 64 76 … … 67 79 print >> sys.stderr, "\t for help use --help" 68 80 return 2 81 82 ''' From Python Cookbook [#10.6]''' 83 ''' Edited as original version would not work for an editor that had an argument e.g. "mate -w" ''' 84 def what_editor(): 85 editor = os.getenv('VISUAL') or os.getenv('EDITOR') 86 if not editor: 87 if sys.playform == 'windows': 88 editor = 'Notepad.Exe' 89 else: 90 editor = 'vi' 91 return editor 69 92 70 93 def edited_text(starting_text=''): 94 temp_fd, temp_filename = tempfile.mkstemp(text=True) 95 os.write(temp_fd, starting_text) 96 os.close(temp_fd) 97 #editor = what_editor() 98 #x = os.spawnlp(os.P_WAIT, editor, editor, temp_filename) 99 x = os.spawnlp(os.P_WAIT, "mate", "mate", "-w", temp_filename) 100 if x: 101 raise RuntimeError, "Can't run %s %s (%s)" % (editor, temp_filename,x) 102 result = open(temp_filename).read() 103 os.unlink(temp_filename) 104 return result 105 71 106 if __name__ == "__main__": 72 107 sys.exit(main())
