codekingpro/portable-devtools
114k
1# vss.py -- Source Control using Microsoft VSS.2 3# Provides routines for checking files out of VSS.4#5# Uses an INI file very similar to how VB integrates with VSS - even6# as far as using the same name.7 8# The file must be named "Mssccprj.scc", and be in the format of9# an INI file. This file may be in a parent directory, in which10# case the project name will be built from what is specified in the11# ini file, plus the path from the INI file to the file itself.12#13# The INI file should have a [Python] section, and a14# Project=Project Name15# and optionally16# Database=??17 18 19import os20import sys21import traceback22 23import win32api24import win32ui25 26g_iniName = "Mssccprj.scc" # Use the same INI name as VB!27 28g_sourceSafe = None29 30 31def FindVssProjectInfo(fullfname):32 """Looks up the file system for an INI file describing the project.33 34 Looking up the tree is for ni style packages.35 36 Returns (projectName, pathToFileName) where pathToFileName contains37 the path from the ini file to the actual file.38 """39 path, fnameonly = os.path.split(fullfname)40 origPath = path41 project = ""42 retPaths = [fnameonly]43 while not project:44 iniName = os.path.join(path, g_iniName)45 database = win32api.GetProfileVal("Python", "Database", "", iniName)46 project = win32api.GetProfileVal("Python", "Project", "", iniName)47 if project:48 break49 # No valid INI file in this directory - look up a level.50 path, addpath = os.path.split(path)51 if not addpath: # Root?52 break53 retPaths.insert(0, addpath)54 if not project:55 win32ui.MessageBox(56 "%s\r\n\r\nThis directory is not configured for Python/VSS" % origPath57 )58 return59 return project, "/".join(retPaths), database60 61 62def CheckoutFile(fileName):63 global g_sourceSafe64 import pythoncom65 66 ok = 067 # Assumes the fileName has a complete path,68 # and that the INI file can be found in that path69 # (or a parent path if a ni style package)70 try:71 import win32com.client72 import win32com.client.gencache73 74 mod = win32com.client.gencache.EnsureModule(75 "{783CD4E0-9D54-11CF-B8EE-00608CC9A71F}", 0, 5, 076 )77 if mod is None:78 win32ui.MessageBox(79 "VSS does not appear to be installed. The TypeInfo can not be created"80 )81 return ok82 83 rc = FindVssProjectInfo(fileName)84 if rc is None:85 return86 project, vssFname, database = rc87 if g_sourceSafe is None:88 g_sourceSafe = win32com.client.Dispatch("SourceSafe")89 # SS seems a bit wierd. It defaults the arguments as empty strings, but90 # then complains when they are used - so we pass "Missing"91 if not database:92 database = pythoncom.Missing93 g_sourceSafe.Open(database, pythoncom.Missing, pythoncom.Missing)94 item = g_sourceSafe.VSSItem("$/%s/%s" % (project, vssFname))95 item.Checkout(None, fileName)96 ok = 197 except pythoncom.com_error as exc:98 win32ui.MessageBox(exc.strerror, "Error checking out file")99 except:100 typ, val, tb = sys.exc_info()101 traceback.print_exc()102 win32ui.MessageBox("%s - %s" % (str(typ), str(val)), "Error checking out file")103 tb = None # Cleanup a cycle104 return ok105 