0

I am using the p4 Python module to try and open several files for edit. Basically I have a list of files that I am grabbing from a txt document. I then do some formatting to each item in the list and append those items to an empty list. My method is not the most efficient but I am just trying to get this to work before optimizing.

edit_files = []

with open('C:\\Users\\rgriffin\Desktop\\replace.txt', 'r' )as f:
    for line in f:
        l = line.partition(',')[0]
        e = l.replace('#(', '')
        r = e.replace('U:\\', '//Stream/main/')
        q= r.replace('\\', '/')
        edit_files.append(q)
f.close

for i in edit_files:
    p4.run("edit" , i) 

With this code I get an error:

[Warning]: '"//Stream/main/Data/anims/stuff/char/Emotion_Angry.hkx" - file(s) not on client.'

If I change the last line to this...

p4.run("edit" , "//Stream/main/Data/anims/stuff/char/Emotion_Angry.hkx") 

The file is checked out as expected. I did a type check and i is a string.

Input data:

#("U:\Data\anims\stuff\char\Emotion_Angry_Partial.hkx", "u:\Assets\Actors\stuff\char\Animation\char_Idle.max")
5
  • Did you tried print i ? what is the input txt document format ? Commented Jul 16, 2013 at 20:34
  • Seems like quotes(") are there in your in your query. Try running p4.run("edit" , i.replace('"','')) Commented Jul 16, 2013 at 20:36
  • print(i) results in "//Stream/main/Data/anims/stuff/car/Emotion_Angry.hkx" My text document is plain text. p4.run("edit" , i.replace('"','')) results in File "F:\replaceFile.py", line 27, in <module> p4.run("edit" , i.replace('"','')) File "C:\Python33\lib\site-packages\P4.py", line 533, in run result = P4API.P4Adapter.run(self, *self.__flatten(args)) P4.P4Exception: [P4#run] Warnings during command execution( "p4 edit " ) [Warning]: '\n - file(s) not on client.' Commented Jul 16, 2013 at 20:39
  • 1
    there you go. You have extra quotes. Use : p4.run("edit" , i.replace('"','')) Commented Jul 16, 2013 at 20:41
  • I am not sure if the document type would effect this as I am creating a string and appending it to the edit_files list. Commented Jul 16, 2013 at 20:42

1 Answer 1

1

In the following command, there are quote characters at ends. Do remove them. Also seems like there are empty lines. Change

for i in edit_files:
    p4.run("edit" , i) 

to

for i in edit_files:
    f=i.replace('"','').strip()
    if len(f)>0:
      print "Opening  ["+f+"]"
      p4.run("edit" , f) 

or One liner

[p4.run("edit" , i.replace('"','').strip()) for i in edit_files if i.strip()]

Or you may want to change your populating code itself: Use:

with open('C:\\Users\\rgriffin\Desktop\\replace.txt', 'r' )as f:
    for line in f:
        l = line.partition(',')[0].replace('#(', '').replace('U:\\', '//Stream/main/').replace('\\', '/').replace('"', '').strip()
        if len(l)>0:
            edit_files.append(l)
f.close
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect thanks! On little edit. for i in edit_files: f=i.replace('"','').strip() print (f) if len(f)>0: print ("Opening ["+f+"]") p4.run("edit" , f)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.