Skip to content

Instantly share code, notes, and snippets.

@charz
Created December 18, 2013 02:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save charz/8016532 to your computer and use it in GitHub Desktop.
Save charz/8016532 to your computer and use it in GitHub Desktop.
Login to Perforce server, create a workspace and sync code to specific changelist number.
#!/env/bin/python
from P4 import P4, P4Exception
import json
p4 = P4()
p4.user = "charz"
p4.password = "mypassword"
p4.port = "tcp:192.168.1.2:1666"
p4.client = "auto-build"
p4.connect()
print p4
try:
client = p4.fetch_client("auto-build")
client["Root"] = "/home/charz/Work/Build_root"
client["View"] = [ "//depot/tools/... //%s/tools... "% p4.client , ]
p4.save_client(client)
p4.run_login()
# aa = p4.run_sync('-f')
aa = p4.run('sync', '-f', '@2022')
a1 = p4.run('changes', '-m1', '%s/tools/...#have'% client["Root"])
print json.dumps(a1, indent=2)
# print "========================================"
# bb = p4.run('sync', '@2028')
# print json.dumps(bb, indent=2)
# a2 = p4.run('changes', '-l', '-m1', '%s/tools/...#have'% client["Root"])
# print json.dumps(a2, indent=2)
# a2 = p4.run('changes', '-l', '-m10', '%s/tools/...#have'% client["Root"])
# print json.dumps(a2, indent=2)
p4.disconnect()
except P4Exception as e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment