home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2550 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.2 KB  |  187 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from win32api import BeginUpdateResource, UpdateResource, EndUpdateResource, Unicode
  5. U = Unicode
  6. import os
  7. import struct
  8. import glob
  9. import optparse
  10. VS_FFI_SIGNATURE = -17890115
  11. VS_FFI_STRUCVERSION = 65536
  12. VS_FFI_FILEFLAGSMASK = 63
  13. VOS_NT_WINDOWS32 = 262148
  14.  
  15. def file_flags(debug):
  16.     if debug:
  17.         return 3
  18.     return 0
  19.  
  20.  
  21. def file_type(is_dll):
  22.     if is_dll:
  23.         return 2
  24.     return 1
  25.  
  26.  
  27. def VS_FIXEDFILEINFO(maj, min, sub, build, debug = 0, is_dll = 1):
  28.     return struct.pack('lllllllllllll', VS_FFI_SIGNATURE, VS_FFI_STRUCVERSION, maj << 16 | min, sub << 16 | build, maj << 16 | min, sub << 16 | build, VS_FFI_FILEFLAGSMASK, file_flags(debug), VOS_NT_WINDOWS32, file_type(is_dll), 0, 0, 0)
  29.  
  30.  
  31. def nullterm(s):
  32.     
  33.     try:
  34.         return buffer(unicode(s)) + '\x00\x00'
  35.     except NameError:
  36.         return U(s).raw + '\x00\x00'
  37.  
  38.  
  39.  
  40. def pad32(s, extra = 2):
  41.     l = 4 - (len(s) + extra & 3)
  42.     if l < 4:
  43.         return s + '\x00' * l
  44.     return s
  45.  
  46.  
  47. def addlen(s):
  48.     return struct.pack('h', len(s) + 2) + s
  49.  
  50.  
  51. def String(key, value):
  52.     key = nullterm(key)
  53.     value = nullterm(value)
  54.     result = struct.pack('hh', len(value) / 2, 1)
  55.     result = result + key
  56.     result = pad32(result) + value
  57.     return addlen(result)
  58.  
  59.  
  60. def StringTable(key, data):
  61.     key = nullterm(key)
  62.     result = struct.pack('hh', 0, 1)
  63.     result = result + key
  64.     for k, v in data.items():
  65.         result = result + String(k, v)
  66.         result = pad32(result)
  67.     
  68.     return addlen(result)
  69.  
  70.  
  71. def StringFileInfo(data):
  72.     result = struct.pack('hh', 0, 1)
  73.     result = result + nullterm('StringFileInfo')
  74.     result = pad32(result) + StringTable('040904E4', data)
  75.     return addlen(result)
  76.  
  77.  
  78. def Var(key, value):
  79.     result = struct.pack('hh', len(value), 0)
  80.     result = result + nullterm(key)
  81.     result = pad32(result) + value
  82.     return addlen(result)
  83.  
  84.  
  85. def VarFileInfo(data):
  86.     result = struct.pack('hh', 0, 1)
  87.     result = result + nullterm('VarFileInfo')
  88.     result = pad32(result)
  89.     for k, v in data.items():
  90.         result = result + Var(k, v)
  91.     
  92.     return addlen(result)
  93.  
  94.  
  95. def VS_VERSION_INFO(maj, min, sub, build, sdata, vdata, debug = 0, is_dll = 1):
  96.     ffi = VS_FIXEDFILEINFO(maj, min, sub, build, debug, is_dll)
  97.     result = struct.pack('hh', len(ffi), 0)
  98.     result = result + nullterm('VS_VERSION_INFO')
  99.     result = pad32(result) + ffi
  100.     result = pad32(result) + StringFileInfo(sdata) + VarFileInfo(vdata)
  101.     return addlen(result)
  102.  
  103.  
  104. def stamp(pathname, options):
  105.     
  106.     try:
  107.         f = open(pathname, 'a+b')
  108.         f.close()
  109.     except IOError:
  110.         why = None
  111.         print 'WARNING: File %s could not be opened - %s' % (pathname, why)
  112.  
  113.     ver = options.version
  114.     
  115.     try:
  116.         bits = [ int(i) for i in ver.split('.') ]
  117.         (vmaj, vmin, vsub, vbuild) = bits
  118.     except (IndexError, TypeError, ValueError):
  119.         raise ValueError, '--version must be a.b.c.d (all integers) - got %r' % ver
  120.  
  121.     ifn = options.internal_name
  122.     if not ifn:
  123.         ifn = os.path.basename(pathname)
  124.     
  125.     ofn = options.original_filename
  126.     if not ofn:
  127.         ofn = os.path.basename(pathname)
  128.     
  129.     sdata = {
  130.         'Comments': options.comments,
  131.         'CompanyName': options.company,
  132.         'FileDescription': options.description,
  133.         'FileVersion': ver,
  134.         'InternalName': ifn,
  135.         'LegalCopyright': options.copyright,
  136.         'LegalTrademarks': options.trademarks,
  137.         'OriginalFilename': ofn,
  138.         'ProductName': options.product,
  139.         'ProductVersion': ver }
  140.     vdata = {
  141.         'Translation': struct.pack('hh', 1033, 1252) }
  142.     is_dll = options.dll
  143.     if is_dll is None:
  144.         is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split()
  145.     
  146.     is_debug = options.debug
  147.     if is_debug is None:
  148.         is_debug = os.path.splitext(pathname)[0].lower().endswith('_d')
  149.     
  150.     for k, v in sdata.items():
  151.         if v is None:
  152.             sdata[k] = ''
  153.             continue
  154.     
  155.     vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll)
  156.     h = BeginUpdateResource(pathname, 0)
  157.     UpdateResource(h, 16, 1, vs)
  158.     EndUpdateResource(h, 0)
  159.     if options.verbose:
  160.         print 'Stamped:', pathname
  161.     
  162.  
  163. if __name__ == '__main__':
  164.     parser = optparse.OptionParser('%prog [options] filespec ...', description = __doc__)
  165.     parser.add_option('-q', '--quiet', action = 'store_false', dest = 'verbose', default = True, help = "don't print status messages to stdout")
  166.     parser.add_option('', '--version', default = '0.0.0.0', help = 'The version number as m.n.s.b')
  167.     parser.add_option('', '--dll', help = 'Stamp the file as a DLL.  Default is to look at the\n                            file extension for .dll or .pyd.')
  168.     parser.add_option('', '--debug', help = 'Stamp the file as a debug binary.')
  169.     parser.add_option('', '--product', help = 'The product name to embed.')
  170.     parser.add_option('', '--company', help = 'The company name to embed.')
  171.     parser.add_option('', '--trademarks', help = 'The trademark string to embed.')
  172.     parser.add_option('', '--comments', help = 'The comments string to embed.')
  173.     parser.add_option('', '--copyright', help = 'The copyright message string to embed.')
  174.     parser.add_option('', '--description', metavar = 'DESC', help = 'The description to embed.')
  175.     parser.add_option('', '--internal-name', metavar = 'NAME', help = 'The internal filename to embed. If not specified\n                         the base filename is used.')
  176.     parser.add_option('', '--original-filename', help = 'The original filename to embed. If not specified\n                            the base filename is used.')
  177.     (options, args) = parser.parse_args()
  178.     if not args:
  179.         parser.error('You must supply a file to stamp.  Use --help for details.')
  180.     
  181.     for g in args:
  182.         for f in glob.glob(g):
  183.             stamp(f, options)
  184.         
  185.     
  186.  
  187.