Skip to content

Instantly share code, notes, and snippets.

@rpetti
Created January 25, 2018 20:42
Show Gist options
  • Save rpetti/f250fb699b37123ea8bb13617f121e11 to your computer and use it in GitHub Desktop.
Save rpetti/f250fb699b37123ea8bb13617f121e11 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import marshal
import subprocess, shlex
import re
import os
import sys
clienthostcache = {}
def getPerforceResponse(args):
lst = []
#args = shlex.split(command)
p = subprocess.Popen(args, stdout=subprocess.PIPE)
print "Running " + " ".join(args)
try:
while 1:
dictionary = marshal.load(p.stdout)
lst.append(dictionary)
except EOFError:
pass
return lst
def login(userID):
return getPerforceResponse(["p4", "-G", "login", "-a", userID])
def getOpenedFilesForUser(userID):
return getPerforceResponse(["p4", "-G", "opened", "-u", userID])
def getClient(clientID):
return getPerforceResponse(["p4", "-G", "client", "-o", clientID])[0]
def getHostForClient(clientID):
host = "p4client"
try:
host = clienthostcache[clientID]
except KeyError:
client = getClient(clientID)
host = client.get('Host', 'p4client')
clienthostcache[clientID] = host
return host
def main():
for user in sys.argv[1:]:
print "Logging in as " + user
print login(user)
openedByUser = getOpenedFilesForUser(user)
print "Found " + str(len(openedByUser)) + " opened files for " + user
print "reverting..."
for f in openedByUser:
print "Reverting " + f['depotFile'] + " on " + f['client']
host = getHostForClient(f['client'])
response = getPerforceResponse(["p4", "-G", "-H", host, "-c", f['client'], "-u", user, "revert", "-k", f['depotFile']])
print response
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment