Jump to content


Unable to edit existing workspace using p4python

client workspace p4python

  • Please log in to reply
4 replies to this topic

#1 gr8giz

gr8giz

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 04 January 2018 - 01:05 AM

I am new to programming using python and p4python.

I want to modify an existing workspace by using p4python. However, instead of modifying existing workspace, it is creating new one with same name as existing one and modifying the new one's attributes.

Here is what I am trying to do:

from P4 import P4,P4Exception # Import the module
p4 = P4() # Create the P4 instance

try: # Catch exceptions with try/except
p4.connect() # Connect to the Perforce server

client = p4.fetch_client("xyz") #Fetch an existing client xyz
client_root = "H:/ABC" # change client's root
client["Root"] = client_root
client["Description"] = "created by gr8giz" #change description
p4.save_client(client)
print client["Root"]

p4.disconnect() # Disconnect from the server
except P4Exception:
#some exception handling code



#2 ytt1515234

ytt1515234

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 09 January 2018 - 06:16 AM

Here is the code that I change the attributes of an exist client, hope it could help:

tmp = self.p4.fetch_client(self.p4.client)
tmp['Options'] = 'allwrite clobber nocompress unlocked nomodtime normdir'
self.p4.input = tmp
self.p4.run(['client', '-i'])

#3 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 976 posts

Posted 09 January 2018 - 05:14 PM

View Postgr8giz, on 04 January 2018 - 01:05 AM, said:

I want to modify an existing workspace by using p4python. However, instead of modifying existing workspace, it is creating new one with same name as existing one and modifying the new one's attributes.

Could you explain a little more how you arrived at the conclusion that this is what's happening?  It's not possible for two clients to have the same name, so why do you believe the "xyz" client that exists after you make your changes is a "new" client as opposed to a modified version of your old one?

#4 gr8giz

gr8giz

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 January 2018 - 01:08 AM

View PostSambwise, on 09 January 2018 - 05:14 PM, said:

Could you explain a little more how you arrived at the conclusion that this is what's happening?  It's not possible for two clients to have the same name, so why do you believe the "xyz" client that exists after you make your changes is a "new" client as opposed to a modified version of your old one?
Yes you are right, I checked the 2 names have a differing '_', so it was a mistake on my part. I was able to get the script working.

#5 gr8giz

gr8giz

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 January 2018 - 01:08 AM

View Postytt1515234, on 09 January 2018 - 06:16 AM, said:

Here is the code that I change the attributes of an exist client, hope it could help:

tmp = self.p4.fetch_client(self.p4.client)
tmp['Options'] = 'allwrite clobber nocompress unlocked nomodtime normdir'
self.p4.input = tmp
self.p4.run(['client', '-i'])
Thanks





Also tagged with one or more of these keywords: client, workspace, p4python

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users