-
Notifications
You must be signed in to change notification settings - Fork 1
/
p4outerchanges.py
113 lines (89 loc) · 2.28 KB
/
p4outerchanges.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# This script is public domain, with not warranty or guarantee of functionality
# This script was written to minimize server-side load for highly scaled servers
#
# https://github.com/gorlak/p4scripts
#
# core python
import codecs
import locale
import math
import optparse
import os
import re
# p4api
import P4
#
# setup argument parsing
#
parser = optparse.OptionParser()
parser.add_option( "-v", "--verbose", dest="verbose", action="store_true", default=False, help="verbose output" )
( options, args ) = parser.parse_args()
if not len( args ) > 1:
print("Please specify two views to report changes fully integrated: from, to")
exit( 1 )
fromView = args[0]
toView = args[1]
import pprint
pp = pprint.PrettyPrinter( indent=4 )
if os.name != "nt":
print( "Not tested outside of windows\n" )
exit( 1 )
#
# main
#
try:
#
# connect and setup p4
#
# perl sets this differently from os.getcwd() (%CD% on windows), and p4api reads it
os.putenv( 'PWD', os.getcwd() )
p4 = P4.P4()
p4.connect()
p4.exception_level = 1 # omit warnings
info = p4.run_info()
# handle non-unicode servers by marshalling raw bytes to local encoding
encoding = 'UTF-8'
if not p4.server_unicode:
encoding = locale.getpreferredencoding()
if hasattr(p4, 'encoding'):
p4.encoding = 'raw'
def p4MarshalString( data ):
if isinstance( data, str ):
return data
elif isinstance( data, bytes ):
return data.decode( encoding )
else:
print( 'Unexpected type: ' + data )
exit( 1 )
#
# query lots of info
#
print("Fetching history of " + fromView)
changes = p4.run_changes( fromView )
lastIntegrated = None
if len(changes):
print("Checking " + str( len( changes ) ) + " changes for the last fully integrated change...")
change = 0
while change < len(changes):
cl = p4MarshalString( changes[change]['change'] )
print( "Checking interchanges of " + cl )
result = p4.run_interchanges( '-n', fromView + '@' + cl + ',' + cl, toView )
if len( result ):
change = change + 1
else:
print( "Change %s has been integrated" % cl )
break
#
# disconnect
#
p4.disconnect()
except P4.P4Exception:
print( traceback.format_exc() )
print( "\nP4 'info':" )
pp.pprint( info )
print( "\nEnvironment:" )
pp.pprint( dict(os.environ) )
exit( 1 )
except KeyboardInterrupt:
exit( 1 )