Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# python
import lx
from P4 import P4
from P4 import Progress
from P4 import P4Exception
# Path to which folder to sync
PATH = "//..."
class PerforceProgress(Progress):
def __init__(self, monitor):
Progress.__init__(self)
self.monitor = monitor
self.last_position = 0
def done(self, fail):
self.fail = fail
def init(self, type):
self.type = type
def setDescription(self, description, units):
pass
def setTotal(self, total):
pass
def update(self, position):
self.monitor.step(position - self.last_position)
self.position = position
if __name__ == '__main__':
p4 = P4()
try:
p4.connect()
# Get list of all the files and their size
sizes = p4.run_sizes(PATH)
# Initalize our monitor object with the total number of files expected to sync
monitor = lx.Monitor()
monitor.init(len(sizes))
# This is the task we expect to take a considerable time, thankfully we now have a progress bar for the user.
callback = PerforceProgress(monitor)
p4.run_sync("-f", "-q", PATH, progress=callback)
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