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

怎甘沉沦 提交于 2019-12-06 13:55:03

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/22499535/how-to-retrieve-submitted-changelists-in-a-day-using-perforce-python-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!