Search code examples
pythonsubprocessclearcase

Getting present working view in Clearcase


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

Solution

  • 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.