Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

Following code outputs list of today's change on file.c:

import subprocess
import datetime
curr = datetime.datetime.now()
file = "file.c"
cmd = 'p4 changes -s submitted %s@%s/%s/%s,@now' % (file, curr.year, curr.month, curr.day)
print subprocess.check_call(cmd)

Please note that, you should have been set P4PORT and P4USER in your environment before executing above script. If you donot want to set, you can use -p and -u switch for setting these in command.

In the above code, query is created for getting today's changelist on file.c. You can manipulate date and file name for achieving your desired result.

You can also use something like:

from P4 import P4, P4Exception
p4 = P4()
p4.port = "A"
p4.user = "B"
p4.client = "C"

try:
    p4.connect()
    changelist = p4.run_changes('//server/folder/...@yyyy/mm/dd,@now')
    # p4.run("change","//server/folder/...@yyyy/mm/dd,@now") works as well
    for c in changelist:
      print c.desc
      # or whatever you want, including: status, client, user, changelist...

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

finally:
    p4.disconnect()

To me, it feels more correct since it uses the P4Python API and the right run method (invoking the p4 change command), and you also get a lot more information about every changelist.

Chee

You need to add -l to List the full text of description and desc can not get by .desc
this works for me in python3

from P4 import P4, P4Exception
p4 = P4()
p4.port = "A"
p4.user = "B"
p4.client = "C"

try:
    p4.connect()
    changelist = p4.run_changes('-l', '//server/folder/...@yyyy/mm/dd,@now')
    # p4.run("change","//server/folder/...@yyyy/mm/dd,@now") works as well
    for c in changelist:
      print(c['desc'])
      # or whatever you want, including: status, client, user, changelist...

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

finally:
    p4.disconnect()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top