Jump to content


How to get labels of a workspace using P4Python ?

P4Python perforce

  • Please log in to reply
4 replies to this topic

#1 pratik

pratik

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 11 September 2014 - 10:08 AM

Code:

from P4 import P4,P4Exception # Import the module
p4 = P4() # Create the P4 instance
p4.port = "p4training.us.sony.com:1666"
p4.user = "pratik.prajapati"
p4.client = "wks_3" # Set some environment variables

try: # Catch exceptions with try/except
	p4.connect() # Connect to the Perforce Server
	label_data = p4.run("labels")
	print "\n labels = ", label_data
	p4.disconnect() # Disconnect from the Server
except P4Exception:
	for e in p4.errors: # Display errors
		print e

Above code displayed labels of all depots.

How could i get labels of a particular depot or workspace ?

#2 brettb

brettb

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 11 September 2014 - 10:26 AM

You can do something like:

p4.run_labels("//img/...")

#3 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 11 September 2014 - 10:55 AM

Originally posted to the perforce-user mailing list by: Michael Mirman


I didn't think labels are really tied to a particular depot.
Are you saying, you would like to have those labels, where a particular depot is in the View?
If so, I would go grepping the spec depot - something like this:
p4 grep -e "//myfavoritedepot/" //spec/label/...

You can easily convert this CLI to your API.

--
Michael Mirman
MathWorks, Inc.
508-647-7555


-----Original Message-----
From: perforce-user-bounces@perforce.com [mailto:perforce-user-bounces@perforce.com] On Behalf Of pratik
Sent: Thursday, September 11, 2014 6:10 AM
To: perforce-user@perforce.com
Subject: [p4] How to get labels of a workspace using P4Python ?


Posted on behalf of forum user 'pratik'.

Code:

from P4 import P4,P4Exception # Import the module p4 = P4() # Create the P4
instance p4.port = "p4training.us.sony.com:1666" p4.user =
"pratik.prajapati" p4.client = "wks_3" # Set some
environment variables try: # Catch exceptions with try/except p4.connect() #
Connect to the Perforce Server label_data = p4.run("labels") print
"\n labels = ", label_data p4.disconnect() # Disconnect from the
Server except P4Exception: for e in p4.errors: # Display errors print e  
Above code displayed labels of all depots.

How could i get labels of a particular depot or workspace ?



--
Please click here to see the post in its original format:
  http://forums.perfor...-using-p4python
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user


#4 Lennart Kjellén

Lennart Kjellén

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationSweden

Posted 11 September 2014 - 11:16 AM

The commands "p4 labels //mydepot/..." and "p4 labels @myworkspace" list all labels with files within mydepot and myworkspace respectively. Using P4Python method syntax it would be e.g.

p4.run("labels", "//mydepot/...") and p4.run("labels", "@myworkspace")

This, however, will only list labels with actual files tagged within the depot or workspace in question. Automatic labels associated with a certain changelist will not be listed even though they might also be relevant for the depot or workspace. To find such labels you will have to look at the View of all labels as suggested by Michael Mirman.

#5 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 11 September 2014 - 02:10 PM

Originally posted to the perforce-user mailing list by: Michael Mirman


Quote

This, however, will only list labels with actual files tagged within the depot
or workspace in question. Automatic labels...

Excellent point. My brain is firmly planted in the automatic labels world (we disallowed static labels a long time ago in fear that it would be too expensive. Now it wouldn’t be that bad, but we never needed to go back on that decision.)

And now I plan to somewhat contradict myself in my previous suggestion for grepping the spec depot.

Apparently, having View in an automatic label and not having a View makes a difference.
We used automatic labels as pure aliases to change levels.
However, the logic in "p4 files path@label" is different in these cases, which caused to *remove* the View in most of the labels.

If the Label has a View, then "p4 files path@label" does not return the files added after the change level specified in the label.
If there is no View, it does.

So... for those automatic labels that don’t have views, grep will not do anything useful.
Fortunately for us, we have enough of a naming convention for labels not to need that grep.

--Michael Mirman
508-647-7555
MathWorks, Inc.
3 Apple Hill Dr, Natick, MA 01760

-----Original Message-----
From: perforce-user-bounces@perforce.com [mailto:perforce-user-bounces@perforce.com] On Behalf Of Lennart Kjellén
Sent: Thursday, September 11, 2014 7:20 AM
To: perforce-user@perforce.com
Subject: Re: [p4] How to get labels of a workspace using P4Python ?


Posted on behalf of forum user 'Lennart Kjellén'.

The commands "p4 labels //mydepot/..." and "p4 labels
@myworkspace" list all labels with files within mydepot and myworkspace
respectively. Using P4Python method syntax it would be e.g.

p4.run("labels", "//mydepot/...") and
p4.run("labels", "@myworkspace")

This, however, will only list labels with actual files tagged within the depot
or workspace in question. Automatic labels associated with a certain changelist
will not be listed even though they might also be relevant for the depot or
workspace. To find such labels you will have to look at the View of all labels
as suggested by Michael Mirman.



--
Please click here to see the post in its original format:
  http://forums.perfor...-using-p4python
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user







Also tagged with one or more of these keywords: P4Python, perforce

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users