2

I need to find a command to get the active view name from Clearcase, so I can ask the user if they would like to set that as their default path. The following does not work. Any options besides this?

out, err = subprocess.Popen([r"cleartool", "xxx", "-xxxxx"],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE).communicate()
return out
einpoklum
  • 118,144
  • 57
  • 340
  • 684
Shankar Kumar
  • 2,197
  • 6
  • 25
  • 32

3 Answers3

4

cleartool pwv will only give you the name of the view.
To get the path:

cleartool pwv -root

G:\ means probably a snapshot view, since all dynamic views are usually mounted (MVFS) on the drive M:\ by default (but they could be subst'ed to a drive letter as well).
For snapshot views, a drive letter different from C:\ means the actual path of the snapshot view has been subst (Windows command) to a drive letter in order to shorten its path.

See "To use the subst command to access snapshot views (Windows)"

Assigning a snapshot view root directory to a drive letter with the subst command provides slightly better performance than making the snapshot view a shared directory

So if you are on G:\norbt5_ed_hil_dev and want the full path after a cleartool pwv, you can:

cleartool pwv -root

If that returns you only G:\, then you need to call the commands subst to see the full path where G:\ has been assigned.

subst

Or, in python (as in the example):

os.system('subst')

And parse the result.


Note: As explained in "Python and ClearCase setview", pwv wouldn't work in a dynamic view started with setview on Unix (setview doesn't exist on Windows), because it creates a sub-process.
If you are on Unix working with dynamic view, don't use setview (as illustrated here).
Always use cleartool startview <view_tag>, and then the full path of the dynamic view:

/view/AViewName/vobs/aVob/...

A cleartool pwv -root would then return /view/AViewName.


On Windows, if cleartool pwv is used in a dynamic view, then the name of the view returned by cleartool pwv -short is enough:

The path of the root folder of a dynamic view on Windows is always:

m:\view_tag

even if the view has been subst to a different drive letter.
You don't need the -root.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It worked when I when I first tried it, but now only the short command works. I also tried subprocess.Popen(["cleartool","startview"]) before the command, but that didn't help. Why does it work some times but not others? – Shankar Kumar Jun 17 '14 at 18:37
  • @ShankarKumar is your view a snapshot or a dynamic one? – VonC Jun 17 '14 at 18:38
  • @ShankarKumar "Why does it work some times but not others?" Because `cleartool startview` won't assign the dynamic view to a drive letter like `G:`. It will only start and mount the view on `M:` (the MVFS drive). You don't need `G:` (which is or isn't assigned to your view). Use `M:` which is always valid for *any* dynamic started view. – VonC Jun 17 '14 at 18:45
  • But why was it returning "M:\view_tag" before and now just "view_tag"? How will I use the full address if I need it? Should I just say "M:\\"+"view_tag"? – Shankar Kumar Jun 17 '14 at 18:48
  • 1
    @ShankarKumar yes, to be sure, use `cleartool pwv -short`, and add `M:\\ ` in front of the view tag returned by `pwv`: that will *always* be a valid dynamic view path on Windows. – VonC Jun 17 '14 at 18:50
  • @ShankarKumar note that a dynamic view must be started first: `cleartool startview `: if you know which view to start, then you don't even need `pwv`: the path will always be (for a started view) `M:\`. If the view isn't started, but was subst to `G:` in the past, then use the windows command `subst` to get the path it was subst'd: `M:\`: you will get back the view tag that way. Again, `pwv` wouldn't be needed. – VonC Jun 17 '14 at 19:02
0

cleartool pwv is the command to see the active view name. cleartool pwv -short gives a nicer output.

jkitchen
  • 900
  • 11
  • 16
  • I tried the following command: subprocess.Popen([r"cleartool", "pwv", "-short"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate() But it returned "** NONE **". I have ClearCase open so I'm not sure what the problem is.. – Shankar Kumar Jun 17 '14 at 15:43
  • What do you get when you type `cleartool pwv -short` in the terminal (outside of Python)? Usually, "** NONE **" means you don't have a view set. – jkitchen Jun 17 '14 at 15:49
  • cleartool: Error: Cannot get view info for current view: No such file or directory. – Shankar Kumar Jun 17 '14 at 15:59
  • What do you mean by having a view "set"? I have the view shortcut visible in Clearcase – Shankar Kumar Jun 17 '14 at 16:00
  • Is this ClearCase on Windows or Linux? In Linux, you type `cleartool setview ` – jkitchen Jun 17 '14 at 16:08
  • Sorry to bug you again, but is there a way to get the full path of the view name? Right now, it returns "norbt5_ed_hil_dev", but I would like the path, like "G:\\norbt5_ed_hil_dev" – Shankar Kumar Jun 17 '14 at 16:14
0

You don't have to invoke any binary to determine the current view. Outside Python (= in a command shell), the following works:

echo $CLEARCASE_CMDLINE | cut -d\  -f2

as cleartool sets

CLEARCASE_CMDLINE=setview eyalroz_2020_01_add_restrict

when it puts you into a set-view-shell. This also means that, in Python, you can execute the following:

print( os.environ['HOME'].split(' ')[1] )
einpoklum
  • 118,144
  • 57
  • 340
  • 684