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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import verstamp
  7. import fnmatch
  8. import string
  9. import win32api
  10. numStamped = 0
  11. g_patterns = [
  12.     '*.dll',
  13.     '*.pyd',
  14.     '*.exe',
  15.     '*.ocx']
  16.  
  17. def walk(arg, dirname, names):
  18.     global numStamped
  19.     (vars, debug, descriptions) = arg
  20.     for name in names:
  21.         for pat in g_patterns:
  22.             if fnmatch.fnmatch(name, pat):
  23.                 pathname = os.path.join(dirname, name)
  24.                 (base, ext) = os.path.splitext(name)
  25.                 if base[-2:] == '_d':
  26.                     name = base[:-2] + ext
  27.                 
  28.                 is_dll = ext.lower() != '.exe'
  29.                 if descriptions.has_key(os.path.normcase(name)):
  30.                     desc = descriptions[os.path.normcase(name)]
  31.                     
  32.                     try:
  33.                         verstamp.stamp(vars, pathname, desc, is_dll = is_dll)
  34.                         numStamped = numStamped + 1
  35.                     except win32api.error:
  36.                         (hr, func, desc) = None
  37.                         print 'Could not stamp', pathname, 'Error', hr, '-', desc
  38.                     except:
  39.                         None<EXCEPTION MATCH>win32api.error
  40.                     
  41.  
  42.                 None<EXCEPTION MATCH>win32api.error
  43.                 print 'WARNING: description not provided for:', name
  44.                 continue
  45.         
  46.     
  47.  
  48.  
  49. def load_descriptions(fname, vars):
  50.     retvars = { }
  51.     descriptions = { }
  52.     lines = open(fname, 'r').readlines()
  53.     for i in range(len(lines)):
  54.         line = string.strip(lines[i])
  55.         if line != '' and line[0] != '#':
  56.             idx1 = string.find(line, ' ')
  57.             idx2 = string.find(line, '\t')
  58.             if idx1 == -1 or idx2 < idx1:
  59.                 idx1 = idx2
  60.             
  61.             if idx1 == -1:
  62.                 print 'ERROR: bad syntax in description file at line %d.' % (i + 1)
  63.                 sys.exit(1)
  64.             
  65.             key = line[:idx1]
  66.             val = string.strip(line[idx1:])
  67.             if key in vars:
  68.                 retvars[key] = val
  69.             else:
  70.                 descriptions[key] = val
  71.         key in vars
  72.     
  73.     if not retvars.has_key('product'):
  74.         print 'ERROR: description file is missing the product name.'
  75.         sys.exit(1)
  76.     
  77.     if not retvars.has_key('major'):
  78.         print 'ERROR: description file is missing the major version number.'
  79.         sys.exit(1)
  80.     
  81.     if not retvars.has_key('minor'):
  82.         print 'ERROR: description file is missing the minor version number.'
  83.         sys.exit(1)
  84.     
  85.     return (retvars, descriptions)
  86.  
  87.  
  88. def scan(build, root, desc, **custom_vars):
  89.     global numStamped
  90.     numStamped = 0
  91.     
  92.     try:
  93.         build = string.atoi(build)
  94.     except ValueError:
  95.         print 'ERROR: build number is not a number: %s' % build
  96.         sys.exit(1)
  97.  
  98.     debug = 0
  99.     varList = [
  100.         'major',
  101.         'minor',
  102.         'sub',
  103.         'company',
  104.         'copyright',
  105.         'trademarks',
  106.         'product']
  107.     (vars, descriptions) = load_descriptions(desc, varList)
  108.     vars['build'] = build
  109.     vars.update(custom_vars)
  110.     arg = (vars, debug, descriptions)
  111.     os.path.walk(root, walk, arg)
  112.     print 'Stamped %d files.' % numStamped
  113.  
  114. if __name__ == '__main__':
  115.     if len(sys.argv) != 4:
  116.         print "ERROR: incorrect invocation. See script's header comments."
  117.         sys.exit(1)
  118.     
  119.     apply(scan, tuple(sys.argv[1:]))
  120.  
  121.