3

I would like to set to a clearcase view from a python script, and then execute commands within that view. I have tried using various methods outlined here:

subprocess

but I have not had any success. Does anyone know how to accomplish this?

user1347345
  • 61
  • 2
  • 3

2 Answers2

4

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:

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.

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.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have a problem with accessing the views through /view. I am trying to run a set of commands in all views, to do this I would have to set each view to make the view available through /view. Also, this script needs to be run regularly and views are only available through /view for temporary amount of time. Thanks for the response. – user1347345 Apr 20 '12 at 19:59
  • @user1347345: just don't. If you know the name of the view you need to access, start it and it will be there at `/view/viewTag/...`. Pass that `viewTag` name as a parameter to your scripts, and they will access the right path. Much simpler than dealing with sub-shell. – VonC Apr 20 '12 at 20:07
  • @user1347345 I have edited my answer with a possible '`setview`' solution... but I still find the all process too cumbersome. Using directly the full path would be the preferred way. – VonC Apr 20 '12 at 20:21
  • Some commands can be executed within the viewtag directly (using startview command) in the view directory. However I also found out that some commands can only be executed when /vobs/litho is set, therefor I use the setview -exec. Note: setview -exec will take longer to process. Because it need to start/set the view (does some stuff in the background). Where startview is more 'lightweight'. – Melroy van den Berg Nov 27 '14 at 09:24
  • @VonC Thanks for your fast reply. In our company we have `ccmake` a wrapper, I think, to build the source-code in the stream. This command expects a valid /vobs/litho link to the view content. – Melroy van den Berg Nov 27 '14 at 09:27
  • Ow, I think it's a modified version of this: http://www.cmake.org/cmake/help/v3.0/manual/ccmake.1.html – Melroy van den Berg Nov 27 '14 at 09:42
  • @danger89 Ok, I haven't been using ccmake, so I wasn't aware of that specific limitation. – VonC Nov 27 '14 at 10:10
3

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()
  • Thanks, that works. Additional question: don't you know, is there a way to print output of the script before it ends? I'd like to start a build in that manner, but process.communicate will wait till the end of the process. In my case it takes ~30 mins =( – Anton Pilyak Nov 26 '19 at 10:02
  • 1
    Have a look at this if you are really want to have it. https://eli.thegreenplace.net/2017/interacting-with-a-long-running-child-process-in-python/ I actually have long builds as well, but chose not to try live debug, as it way running as part of a Jenkins stage anyway. Not worth to live debug in my opinion. – Mohit Yadav Nov 27 '19 at 11:18
  • Thanks for the link and for the advice, it seems like it is not worth to try it in my case as well, can leave it as it is now – Anton Pilyak Nov 27 '19 at 22:14