2

I would like to use the -I argument to know what is happening other than just exceptions when I sync using p4python.

The website says I can use -I for progress indicators as a console command, particularly with p4 -I sync -q.

This works in console, but I wasn't able to get it to work with P4Python, but perhaps I just didn't use it right and couldn't find any info about using it.

Do anyone know how to do this?

Goose
  • 23
  • 3

1 Answers1

1

Take a look at the Progress class referenced here:

https://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html#1131357

You probably currently have some code that looks like:

p4.connect()
p4.run_sync()

To get progress indicators, create a Progress class:

class GoosesAwesomeProgressSubclass(P4.Progress):
    def update(self,units):
        print("Progress has been made!")

and use it:

p4.progress = GoosesAwesomeProgressSubclass()
p4.connect()
p4.run_sync()
Samwise
  • 68,105
  • 3
  • 30
  • 44
  • That's great info. Though I'm having trouble using it. Should I be setting progress somehow or using a progress method for every sync or using a custom progress class somehow? – Goose Mar 22 '17 at 00:00
  • There's a progress class described in that link (P4.Progress). You subclass it and the server will invoke callbacks to communicate the progress to you. – Samwise Mar 22 '17 at 00:40
  • So I tried this `class MyProgress( Progress ): pass foo = MyProgress()` but I feel like that might be entirely wrong and I didn't see any progress being returned. Do I need to put anything in the subclass? Also, please forgive my lack of knowledge. – Goose Mar 22 '17 at 00:51
  • btw I used: `from P4 import P4, P4Exception, Progress` and it doesn't throw any errors, but it doesn't seem to give progress indicators – Goose Mar 22 '17 at 00:53
  • I added some handwavy example code to give you the idea of how you're supposed to use the Progress class (I think -- I haven't actually used it, just going off the documentation, so the code probably doesn't run as-is). – Samwise Mar 22 '17 at 01:18
  • Thank you very much for putting together an example. I'm currently using `from P4 import P4, P4Exception, Progress` and I tried running the following `class GoosesAwesomeProgressSubclass(Progress): def update(self,units): print("Progress has been made!") p4.using_progress(GoosesAwesomeProgressSubclass()) # Connecting to perforce p4.connect()` because I got the error `AttributeError: type object 'P4' has no attribute 'Progress'` but when I ran what I have above, I got the error `AttributeError: using_progress` – Goose Mar 22 '17 at 19:41
  • Make sure you're using the latest version of P4Python; the `using_progress` method is relatively new. – Samwise Mar 22 '17 at 20:31
  • It says it is already up to date. Does it matter than I'm using python 2.7? – Goose Mar 22 '17 at 22:56
  • Not sure what "it says it is already up to date" means. You might also just try setting `p4.progress = YourProgressClass()` -- the doc has a mention of `using_progress()` but I can't see any other documentation of it so maybe that's a doc error. – Samwise Mar 23 '17 at 02:38
  • Sorry, I meant pip indicated that is was up to date. I also only installed it a couple months ago, so it should be up to date. I tried what you suggested and it said there was no __call__ function. When I add one it does only what I put into the function. – Goose Mar 23 '17 at 19:02
  • Ah okay -- I'm not actually sure what version pip would install, so it's worth double-checking that (latest version according to the docs is 2014.1, although I'm also not sure offhand how you'd check the P4Python version if you didn't install it yourself). I guess the `Progress` class is in your version though since you'd have an error on the import otherwise? No idea about the `call` error, might help if I knew some of the context, but we're pretty well beyond the original question now. :) – Samwise Mar 23 '17 at 19:15
  • Thank you for all the help! – Goose Mar 27 '17 at 21:01
  • has this ever worked ? trying now with p4python v (2022.1.2405607) using_progress is nowhere in sight thus getting the attribute error and assigning to progress has no effect whatsoever. Progress class is present in the API but nothing seems to be making use of it – Newtopian Feb 21 '23 at 20:24
  • I just now gave it a try, and it looks like the `using_progress` thing is a complete fantasy but setting the `progress` attribute works fine. Updated my code snippet. – Samwise Feb 21 '23 at 20:57