Using python to check out a file (cleartool)

1.9k views Asked by At

I'm wondering how to completely automate a checkout. I've tried

os.system('cleartool co ' + pathname)

but that still prompts me to enter a comment about the checkout. Adding more os.system() commands right after doesn't quite work -- they only execute after I've entered the comment.

I'm looking at using subprocess and maybe Popen, but I don't quite understand how they work from the documentation I can find online.

Any help would be much appreciated, thanks!

2

There are 2 answers

5
VonC On BEST ANSWER

If you don't need to enter a comment, a simple -nc would be enough:

os.system('cleartool co -nc ' + pathname)

See cleartool checkout man page.

If the comment is known, you can add it directly (-c xxx)

In both cases, the checkout becomes non-interactive, more suite to batch process.

3
Padraic Cunningham On

You can use Popen and communicate to enter the comment after calling cleartool:

from subprocess import Popen

p = Popen(['cleartool','co',pathname])

p.communicate("comment\n")