Python and ClearCase setview

I wouldn't recommend setting a view, because setview itself spawn a new process.
I really prefer working with /view/viewTag/aVob/... after starting the view (cleartool startview viewTag )

The "spawn process" issue makes the all thing too complex in my opinion, and explains why you have technotes like:

  • "Setting into a view from a shell script does not process the remaining commands in the script".

Any commands that appear after the execution of cleartool setview cmview are not processed because a shell is spawned off with exec(), which replaces the current program with a new program.

This means current process's text and code segments, which in this case is the script that contains all the commands, is replaced by the program getting executed, which is the shell invoked by running cleartool setview cmview.
Hence, none of the commands are processed beyond the point of invocation of the setview.

  • "How spawned shell is handled by issuing setview -exe or -login and affect on subshell process"

The -exec variable will start a subshell process and invoke the specified command in the dynamic view specified. Control is then returned to the parent shell once the command has finished.
The -exec will not set the view in the parent shell process.
The -exec spawned subshell will inherit the Environment variables of the parent shell process; however, the Environment variables created in the child shell will not pass back into the parent shell.

So if you really want to use setview, you could (not tested directly myself):

  • have a python script calling setview
  • but that setview call would be with an -exec parameter being another python script (doing what you want to do when that /vobs is configured with the content of said set view.

Old thread, but i just had to work on this issue , so maybe of help .

In your python script

process = subprocess.Popen('usr/atria/bin/cleartool setview viewName')
(out, err) = process.communicate('python script2Name')

the .communicate can be passed new commands, as if you were passing it to a new shell (terminal).

Another way to do it would be

process = subprocess.Popen('usr/atria/bin/cleartool setview -exec "whatever command you want inside view" viewName')
(out, err) = process.communicate()