Getting present working view in Clearcase

2020-07-26 11:05发布

问题:

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

回答1:

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.



回答2:

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



回答3:

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] )