1

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!

Jon
  • 121
  • 1
  • 10

2 Answers2

1

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")
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • Thanks for the reply! This worked better than anything I had previously tried with Popen, but it's still not quite doing the trick. I'm still having to manually enter my comment. Do you know why this could be? – Jon Jun 19 '15 at 18:50
  • @Jon, I was looking for the list of commands but the answer below has provided the man page, you can and should use `subprocess.check_call` passing the list of args – Padraic Cunningham Jun 19 '15 at 18:58
  • Thanks for the follow-up! What would the list of args be in this case? I guess that's the most confusing thing for me. Could I just say subprocess.check_call('cleartool co ' + pathname, 'comment')? – Jon Jun 19 '15 at 19:10
1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the reply! I'm not entirely certain if I'll be required to have a comment, but upon trying this code, I get a little popup saying that a comment needs to be entered, with an "Abort" button for me to press. – Jon Jun 19 '15 at 18:55
  • @Jon I have edited the answer: `-c xxx` or `-nc` means there won't be any popup – VonC Jun 19 '15 at 18:55
  • The -c xxx line works beautifully! Thanks so much! Unfortunately, the -nc line doesn't prevent the popup for me. I think -c xxx will be sufficient for my needs, but I'm not certain yet. Anyways, thanks so much, you've helped me significantly. – Jon Jun 19 '15 at 18:59
  • @Jon speaking of python, make sure to avoid `cleartool setview` if you are using dynamic view: http://stackoverflow.com/a/10252612/6309. Use the full path of the dynamic view instead: http://stackoverflow.com/a/18457541/6309 – VonC Jun 19 '15 at 19:02
  • Thanks for the links! Views aren't a concern at the moment, but if that becomes necessary, I'll look into it! – Jon Jun 19 '15 at 19:12