Search code examples
perforcep4python

How to download p4 files locally?


I have a problem with downloading files from Perforce. I need to use python for it, so p4python is the best solution i found. Here what I have:

def connect(username, password):
    p4 = P4()
    p4.port = 'bla.bla.bla.bla:port'
    p4.user = username
    p4.password = password
    p4.client = 'clientname'

    p4.connect()
    p4.run_login()
    return p4

def main(username, password):
    try:
        p4 = connect(username, password)
        p4.run_sync()
        p4.disconnect()
    except P4Exception:
        for e in p4.errors:
            print(e)

And it works for me, I get files in my workspace directory. BUT I download files to /tmp on server, so when I restart it download only files from last revision, not all the files. How can I download all files every time my workspace directory in not fill?


Solution

  • Use p4 sync -p if you want to download all the files without having the server track the state of your client. That way every time you sync, you'll always get everything -- this is intended exactly for the use case you describe where you just want to grab all the files in a temp location, do something with them, and then throw them away.