Skip to content
Advertisement

How to retrieve submitted changelists in a day using Perforce Python API

I am new to Perforce Python API and still finding my way through it. So far I have been able to retrieve changelist information like number, desc etc, if I provide the file name. I am trying to get a list of all the submitted changelists for a specified date/time range so that I can gather information like files changed and description of each changelist etc. Is there a way to do this using the API?

Thanks

Advertisement

Answer

From a read of the less than extensive P4Python documentation and a question from the Perforce forum, this code might do the trick but bear in mind it is completely untested** so caveat emptor and all that

In the filelog command, the ... seems to be the way of requesting all files in the folder, so you only need to replace server and folder with the appropriate values.

from P4 import P4, P4Exception
p4 = P4()
p4.port = "1"
p4.user = "User"
p4.client = "Client"

try:
    p4.connect()
    changelist = p4.run_filelog('//server/folder/...@yyyy/mm/dd,@now')
    for r in changelist:
      print r.depotFile
      print r.revisions[0].time

except P4Exception:
    for e in p4.errors:
        print e

finally:
    p4.disconnect()

** Yes, I could have downloaded Perforce, installed it, added some files and then tested the code, but that seemed like a mild degree of overkill.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement