Last active
August 9, 2021 13:44
-
-
Save rondreas/91285ba08984c018c3657d5670798f2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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