Discussion:
[p4] problem with programming perforce via python
Roger Day
2007-01-08 14:08:49 UTC
Permalink
I'm trying to do the following

log = logging.getLogger("hope2p4")
cmd =self.p4+' change -i -o'
p = Popen(cmd, stdout=PIPE, stdin=PIPE, close_fds=True, bufsize=1,
shell=True)
lcmd = 'Change: new\n'
(author, reason, bugnr)=metadata
lcmd += 'Description:\n\t['+ bugnr+'] '+reason+'\n'
lcmd += 'Files: \n\t'+f+'\n\n'
log.info("lcmd: "+lcmd)
p.stdin.write( lcmd )
p.stdin.close()
out =p.stdout.read()
(pre, nr, end)=out.split(' ')
return nr

A changelist number is returned, but the changelist doesn't contain any
files.

Once I've created the change-list I then go on to submit in a similar
fashion but can't because the changelist contains no files.

Any help gratefully received.

Roger
Nicholas Guarracino
2007-01-08 18:36:46 UTC
Permalink
Post by Roger Day
I'm trying to do the following
log = logging.getLogger("hope2p4")
cmd =self.p4+' change -i -o'
p = Popen(cmd, stdout=PIPE, stdin=PIPE, close_fds=True, bufsize=1,
shell=True)
lcmd = 'Change: new\n'
(author, reason, bugnr)=metadata
lcmd += 'Description:\n\t['+ bugnr+'] '+reason+'\n'
lcmd += 'Files: \n\t'+f+'\n\n'
log.info("lcmd: "+lcmd)
p.stdin.write( lcmd )
p.stdin.close()
out =p.stdout.read()
(pre, nr, end)=out.split(' ')
return nr
A changelist number is returned, but the changelist doesn't contain any
files.
Once I've created the change-list I then go on to submit in a similar
fashion but can't because the changelist contains no files.
Any help gratefully received.
I'm sure lots of people will point this out, but there are nifty Python
bindings for p4 that you might want to consider instead of doing
everything yourself:
http://public.perforce.com/guest/robert_cowham/perforce/API/python/index.html

It handles all the marshalling & parsing for you, so you can do stuff like

p4c.run_edit ('//depot/some/file')
f = file (p4c.run_where ('//depot/some/file') [0] ['path'], 'w')
f.write ('Changed by p4ython')
f.close()
change = p4c.run_change ('-o') [0]
change ['Description'] = 'My description'
p4c.input = change
p4c.run_submit ('-i')

--Nick
David Weintraub
2007-01-08 18:39:17 UTC
Permalink
I don't know anything about Python, but I did use Perl in attempting
to access Perforce via "exec" instead of the P4/Perl interface.

The biggest problem I had is that Perforce commands "fail", but still
return an error code of "0". That makes testing whether or not
something happened as expected almost impossible to tell. For example,
maybe you're not getting anything because the user running the script
isn't "logged in"

The best thing to do is get the P4/Python interface package, and write
your Python scripts using that. That will give you a better way of
checking for errors, and for making sure you actually are logged in
and have a connection.
Post by Roger Day
I'm trying to do the following
log = logging.getLogger("hope2p4")
cmd =self.p4+' change -i -o'
p = Popen(cmd, stdout=PIPE, stdin=PIPE, close_fds=True, bufsize=1,
shell=True)
lcmd = 'Change: new\n'
(author, reason, bugnr)=metadata
lcmd += 'Description:\n\t['+ bugnr+'] '+reason+'\n'
lcmd += 'Files: \n\t'+f+'\n\n'
log.info("lcmd: "+lcmd)
p.stdin.write( lcmd )
p.stdin.close()
out =p.stdout.read()
(pre, nr, end)=out.split(' ')
return nr
A changelist number is returned, but the changelist doesn't contain any
files.
Once I've created the change-list I then go on to submit in a similar
fashion but can't because the changelist contains no files.
Any help gratefully received.
Roger
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
--
--
David Weintraub
***@gmail.com
Roger Day
2007-01-10 17:59:33 UTC
Permalink
Thanks, I know about the p4 interfaces - I did not have a good experience
with the p4perl interface so I'm slightly allergic to interfaces. And I
solved my problem, thankyou.

Roger
Post by Nicholas Guarracino
Post by Roger Day
I'm trying to do the following
log = logging.getLogger("hope2p4")
cmd =self.p4+' change -i -o'
p = Popen(cmd, stdout=PIPE, stdin=PIPE, close_fds=True, bufsize=1,
shell=True)
lcmd = 'Change: new\n'
(author, reason, bugnr)=metadata
lcmd += 'Description:\n\t['+ bugnr+'] '+reason+'\n'
lcmd += 'Files: \n\t'+f+'\n\n'
log.info("lcmd: "+lcmd)
p.stdin.write( lcmd )
p.stdin.close()
out =p.stdout.read()
(pre, nr, end)=out.split(' ')
return nr
A changelist number is returned, but the changelist doesn't contain any
files.
Once I've created the change-list I then go on to submit in a similar
fashion but can't because the changelist contains no files.
Any help gratefully received.
I'm sure lots of people will point this out, but there are nifty Python
bindings for p4 that you might want to consider instead of doing
http://public.perforce.com/guest/robert_cowham/perforce/API/python/index.html
It handles all the marshalling & parsing for you, so you can do stuff
like
Post by Nicholas Guarracino
p4c.run_edit ('//depot/some/file')
f = file (p4c.run_where ('//depot/some/file') [0] ['path'], 'w')
f.write ('Changed by p4ython')
f.close()
change = p4c.run_change ('-o') [0]
change ['Description'] = 'My description'
p4c.input = change
p4c.run_submit ('-i')
--Nick
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
Loading...