My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
#
# Simple python script that tries to sync up with a repository after an offline session
# with perforce. Read more about this on Perforce's technote:
#
# http://www.perforce.com/perforce/technotes/note002.html
#
#
# This script was downloaded from http://www.tilander.org/aurora
#
# (c) 2006 Jim Tilander
import sys, os, marshal

# Assume that we're on win32 or a UNIX compatible system.
if "win32" == sys.platform:
FINDCOMMAND = "dir /b /s /a-d"
else:
FINDCOMMAND = "find . -type f -print"

def doPerforceCommand( command ):
""" Returns the error code and entries as a tuple."""
stream = os.popen( command, 'rb' )
entries = []
try:
while True:
entry = marshal.load(stream)
entries.append(entry)
except EOFError:
pass

code = stream.close()
return code, entries

def processOutput(results, showDryRun):
""" Ignores the info codes and prints only the stat actions."""
for result in results:
code = result['code']
if 'info' == code:
continue

if 'stat' == code:
would = ""
if showDryRun:
would = "Would "
print '%s%s %s' % (would,result['action'], result['clientFile'])
continue

print "Unknown dict entry: %s" % str(result)

def main( argv ):
"""
Main function, parses the already stripped argv.
Will return a positive number upon failure, zero upon success.
Hardcoded DOS style find command.
"""
dryRunFlag = ''
if len(argv) > 0 and "-n" == argv[0]:
dryRunFlag = '-n'

commands = [ "p4 diff -sd ... | p4 -G -x - delete %s",
"p4 diff -se ... | p4 -G -x - edit %s",
FINDCOMMAND + " | p4 -G -x - add %s" ]

for i, command in enumerate(commands):
code, result = doPerforceCommand( command % dryRunFlag)
processOutput(result, len(dryRunFlag) > 0)
if code:
print 'Failed to run command "%s"' % (command%dryRunFlag)
return i

return 0

if __name__ == '__main__':
sys.exit( main(sys.argv[1:]) )

Change log

r2 by jim.tilander on May 26, 2008   Diff
First import from webpage
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1978 bytes, 74 lines
Powered by Google Project Hosting