bin/resourcifier.py
changeset 34 ed14f46c0e55
parent 0 16d8024aca5e
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    27 #############################################################################
    27 #############################################################################
    28 
    28 
    29 import os
    29 import os
    30 import sys
    30 import sys
    31 import fnmatch
    31 import fnmatch
       
    32 import filecmp
    32 import optparse
    33 import optparse
    33 
    34 
    34 # ============================================================================
    35 # ============================================================================
    35 # Globals
    36 # Globals
    36 # ============================================================================
    37 # ============================================================================
   104         INPUT = options.input
   105         INPUT = options.input
   105     if options.output != sys.stdout:
   106     if options.output != sys.stdout:
   106         outputdir = os.path.dirname(options.output)
   107         outputdir = os.path.dirname(options.output)
   107         if len(outputdir) and not os.path.exists(outputdir):
   108         if len(outputdir) and not os.path.exists(outputdir):
   108             os.makedirs(outputdir)
   109             os.makedirs(outputdir)
   109         OUTPUT = open(options.output, "w")
   110         if os.path.exists(options.output):
       
   111             OUTPUT = open(options.output + ".tmp.qrc", "w")
       
   112         else:
       
   113             OUTPUT = open(options.output, "w")
   110     if options.include:
   114     if options.include:
   111         INCLUDE = options.include
   115         INCLUDE = options.include
   112     if options.exclude:
   116     if options.exclude:
   113         EXCLUDE = options.exclude
   117         EXCLUDE = options.exclude
   114     if options.indentation:
   118     if options.indentation:
   115         INDENTATION = options.indentation.replace("\\t", "\t")
   119         INDENTATION = options.indentation.replace("\\t", "\t")
   116 
   120 
   117     os.chdir(INPUT)
   121     os.chdir(INPUT)
   118     resources = index_resources()
   122     resources = index_resources()
   119     return write_qrc(OUTPUT, resources)
   123     write_qrc(OUTPUT, resources)
       
   124     OUTPUT.close()
       
   125 
       
   126     if OUTPUT != sys.stdout and OUTPUT.name != options.output:
       
   127         if filecmp.cmp(OUTPUT.name, options.output, shallow=False):
       
   128             # content identical, discard
       
   129             os.remove(OUTPUT.name)
       
   130         else:
       
   131             # content changed, overwrite
       
   132             os.remove(options.output)
       
   133             os.rename(OUTPUT.name, options.output)
   120 
   134 
   121 if __name__ == "__main__":
   135 if __name__ == "__main__":
   122     sys.exit(main())
   136     sys.exit(main())