• Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 96 for Xml/Validator/Backend/mateTiff.py

Show
Ignore:
Timestamp:
09/19/07 16:51:12 (14 months ago)
Author:
andrew
Message:

A broken version of mateTiff - turns out the python image library does not save multi page tiffs right... back to the drawing board.

Files:
1 modified

  • Xml/Validator/Backend/mateTiff.py (modified) (4 diffs)

Legend:

Unmodified
Added
Removed
  • Xml/Validator/Backend/mateTiff.py

    r93 r96  
    88""" 
    99 
    10 import sys 
     10import sys, os, tempfile 
    1111import getopt 
    1212import Image 
    … …  
    2525 
    2626def main(argv=None): 
     27        print "At present this destroys multi plane TIFF files - kill process to stop changes being applied" 
    2728        if argv is None: 
    2829                argv = sys.argv 
    … …  
    5859                                    # read the xml from the tiff 
    5960                                        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" 
    6375                 
    6476                 
    … …  
    6779                print >> sys.stderr, "\t for help use --help" 
    6880                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" ''' 
     84def 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 
    6992 
    70  
     93def 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         
    71106if __name__ == "__main__": 
    72107        sys.exit(main()) 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/