pythonwin and configuration management

Geoff Talvola gtalvola at nameconnector.com
Fri May 11 15:18:30 EDT 2001


At 06:34 PM 5/11/01 +0000, Robert Cowham wrote:
>Is there any more documentation on how to link in a CM tool into Python win,
>e.g. for check out/in of modules?
>
>TIA
>Robert

I think it only supports checkout, nothing else.  But that in itself is 
useful.  I was able to modify it to support Perforce as follows:

What I did was to replace the Visual SourceSafe-specific "vss.py" file in 
Pythonwin/pywin/framework/editor with the file below.  Then I selected the 
"VSS Integration" checkbox in the Options.  Then I restarted 
Pythonwin.  Now, whenever I try to edit a read-only file, Pythonwin 
automatically asks me if I want to check out the file, and if I say Yes, it 
checks it out in Perforce.

If you're a Perforce user, you can use this replacement vss.py file as-is.

If you want the Pythonwin GUI to actually say "Perforce" instead of "VSS", 
you're on your own.  I didn't care enough to bother.


--

- Geoff Talvola
   gtalvola at NameConnector.com



###################
# replacement for Pythonwin/pywin/framework/editor/vss.py
# that supports Perforce
import win32api, win32pipe, string, os

def CheckoutFile(fileName):
     """
     This gets called by Pythonwin whenever it wants to check out a file.
     """
     fileName = getLongPathName(fileName)
     input, output = win32pipe.popen4('p4 edit "%s"' % fileName)
     input.close()
     result = output.read()
     output.close()
     if string.find(result, 'opened for edit') < 0:
         win32api.MessageBox(0, result, 'Unable to Check Out File')
         return 0
     else:
         return 1

def getLongPathName(path):
     """
     Converts all 8.3 portions of the given path into their full long names.
     """
     if os.path.ismount(path):
         return path
     beginning, end = os.path.split(path)
     if end == '':
         return path
     beginning = getLongPathName(beginning)
     if os.path.exists(path):
         ends = win32api.FindFiles(path)
         if len(ends) == 1:
             end = ends[0][8]
     return os.path.join(beginning, end)









More information about the Python-list mailing list