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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32con
  5. import string
  6. import traceback
  7. import win32com.client as win32com
  8. import win32com.client.gencache as win32com
  9. import pythoncom
  10. import time
  11. import os
  12. constants = win32com.client.constants
  13. win32com.client.gencache.EnsureModule('{783CD4E0-9D54-11CF-B8EE-00608CC9A71F}', 0, 5, 0)
  14. error = 'vssutil error'
  15.  
  16. def GetSS():
  17.     ss = win32com.client.Dispatch('SourceSafe')
  18.     ss.Open(pythoncom.Missing, pythoncom.Missing, pythoncom.Missing)
  19.     return ss
  20.  
  21.  
  22. def test(projectName):
  23.     ss = GetSS()
  24.     project = ss.VSSItem(projectName)
  25.     for item in project.GetVersions(constants.VSSFLAG_RECURSYES):
  26.         print item.VSSItem.Name, item.VersionNumber, item.Action
  27.     
  28.  
  29.  
  30. def SubstituteInString(inString, evalEnv):
  31.     substChar = '$'
  32.     fields = string.split(inString, substChar)
  33.     newFields = []
  34.     for i in range(len(fields)):
  35.         didSubst = 0
  36.         strVal = fields[i]
  37.         if i % 2 != 0:
  38.             
  39.             try:
  40.                 strVal = eval(strVal, evalEnv[0], evalEnv[1])
  41.                 newFields.append(strVal)
  42.                 didSubst = 1
  43.             traceback.print_exc()
  44.             print 'Could not substitute', strVal
  45.  
  46.         
  47.         if not didSubst:
  48.             newFields.append(strVal)
  49.             continue
  50.     
  51.     return string.join(map(str, newFields), '')
  52.  
  53.  
  54. def SubstituteInFile(inName, outName, evalEnv):
  55.     inFile = open(inName, 'r')
  56.     
  57.     try:
  58.         outFile = open(outName, 'w')
  59.         
  60.         try:
  61.             while None:
  62.                 line = inFile.read()
  63.                 if not line:
  64.                     break
  65.                 
  66.             outFile.close()
  67.         finally:
  68.             inFile.close()
  69.  
  70.         return None
  71.  
  72.  
  73.  
  74. def VssLog(project, linePrefix = '', noLabels = 5, maxItems = 150):
  75.     lines = []
  76.     num = 0
  77.     labelNum = 0
  78.     for i in project.GetVersions(constants.VSSFLAG_RECURSYES):
  79.         num = num + 1
  80.         if num > maxItems:
  81.             break
  82.         
  83.         commentDesc = itemDesc = ''
  84.         if i.Action[:5] == 'Added':
  85.             continue
  86.         
  87.         if len(i.Label):
  88.             labelNum = labelNum + 1
  89.             itemDesc = i.Action
  90.         else:
  91.             itemDesc = i.VSSItem.Name
  92.             if str(itemDesc[-4:]) == '.dsp':
  93.                 continue
  94.             
  95.         if i.Comment:
  96.             commentDesc = '\n%s\t%s' % (linePrefix, i.Comment)
  97.         
  98.         lines.append('%s%s\t%s%s' % (linePrefix, time.asctime(time.localtime(int(i.Date))), itemDesc, commentDesc))
  99.         if labelNum > noLabels:
  100.             break
  101.             continue
  102.     
  103.     return string.join(lines, '\n')
  104.  
  105.  
  106. def SubstituteVSSInFile(projectName, inName, outName):
  107.     import win32api
  108.     if win32api.GetFullPathName(inName) == win32api.GetFullPathName(outName):
  109.         raise RuntimeError, 'The input and output filenames can not be the same'
  110.     win32api.GetFullPathName(inName) == win32api.GetFullPathName(outName)
  111.     sourceSafe = GetSS()
  112.     project = sourceSafe.VSSItem(projectName)
  113.     label = None
  114.     for version in project.Versions:
  115.         if version.Label:
  116.             break
  117.             continue
  118.     else:
  119.         print 'Couldnt find a label in the sourcesafe project!'
  120.         return None
  121.     vss_label = None.Label
  122.     vss_date = time.asctime(time.localtime(int(version.Date)))
  123.     now = time.asctime(time.localtime(time.time()))
  124.     SubstituteInFile(inName, outName, (locals(), globals()))
  125.  
  126.  
  127. def CountCheckouts(item):
  128.     num = 0
  129.     if item.Type == constants.VSSITEM_PROJECT:
  130.         for sub in item.Items:
  131.             num = num + CountCheckouts(sub)
  132.         
  133.     elif item.IsCheckedOut:
  134.         num = num + 1
  135.     
  136.     return num
  137.  
  138.  
  139. def GetLastBuildNo(project):
  140.     i = GetSS().VSSItem(project)
  141.     lab = None
  142.     for version in i.Versions:
  143.         lab = str(version.Label)
  144.         if lab:
  145.             return lab
  146.     
  147.  
  148.  
  149. def MakeNewBuildNo(project, buildDesc = None, auto = 0, bRebrand = 0):
  150.     if buildDesc is None:
  151.         buildDesc = 'Created by Python'
  152.     
  153.     ss = GetSS()
  154.     i = ss.VSSItem(project)
  155.     num = CountCheckouts(i)
  156.     if num > 0:
  157.         msg = 'This project has %d items checked out\r\n\r\nDo you still want to continue?' % num
  158.         import win32ui
  159.         if win32ui.MessageBox(msg, project, win32con.MB_YESNO) != win32con.IDYES:
  160.             return None
  161.     
  162.     oldBuild = buildNo = GetLastBuildNo(project)
  163.     if buildNo is None:
  164.         buildNo = '1'
  165.         oldBuild = '<None>'
  166.     else:
  167.         
  168.         try:
  169.             buildNo = string.atoi(buildNo)
  170.             if not bRebrand:
  171.                 buildNo = buildNo + 1
  172.             
  173.             buildNo = str(buildNo)
  174.         except ValueError:
  175.             raise error, 'The previous label could not be incremented: %s' % oldBuild
  176.  
  177.     if not auto:
  178.         dialog = dialog
  179.         import pywin.mfc
  180.         buildNo = dialog.GetSimpleInput('Enter new build number', buildNo, '%s - Prev: %s' % (project, oldBuild))
  181.         if buildNo is None:
  182.             return None
  183.     
  184.     i.Label(buildNo, 'Build %s: %s' % (buildNo, buildDesc))
  185.     if auto:
  186.         print 'Branded project %s with label %s' % (project, buildNo)
  187.     
  188.     return buildNo
  189.  
  190. if __name__ == '__main__':
  191.     tp = '\\Python\\Python Win32 Extensions'
  192.     SubstituteVSSInFile(tp, 'd:\\src\\pythonex\\win32\\win32.txt', 'd:\\temp\\win32.txt')
  193.  
  194.