From: Greg Ercolano <erco@(email surpressed)>
Subject: [WINDOWS/ADMIN] How to force drive mapping within submit scripts,
   Date: Fri, 23 Jan 2009 16:23:03 -0500
Msg# 1831
View Complete Thread (0 article) | All Threads
    This subject has been covered before, but just to tie
    it all up into a single article..

                             * * *

    You can have the submit scripts try to detect and fix
    broken drive maps on the fly by adding logic to the 'render'
    section of the submit script just before the render is invoked.

    Drives can be mapped with the DOS 'net use' command, eg:

        NET USE Z: \\YOURSERVER\YOURSHARE3 /PERSISTENT:YES

    You can add commands like this to the MAIN_Render() section
    of the script. Since in some cases the maps can time out,
    you may have to first delete the broken map before re-creating it.

    Some example perl code to do all this:

        if ( $G::iswindows && ! -d "z:/" )
        {
            my $cmd = "net use z: /delete < nul";
            print "Z: NOT MAPPED -- FORCE UNMAP FIRST: $cmd\n";
            system($cmd);

            $cmd = "net use z: \\\\yourserver\\yourshare1 /PERSISTENT:YES < nul";
            print "Z: MAPPING WITH: $cmd\n";
            system($cmd);
        }

    Note that *backslashes* have to be used for the pathname of this
    DOS command, so be sure to 'double up' your slashes, since backslashes
    are an escape character in perl (and most all scripting languages).

    Some python equivalent code for the above:

        if ( Rush.IsWindows() and not os.path.isdir("z:/") ):
            cmd = "net use z: /delete < nul"
            sys.stdout.write("Z: NOT MAPPED -- FORCE UNMAP FIRST: " + cmd + "\n")
            sys.stdout.flush()
            os.system(cmd)
        
            cmd = "net use z: \\\\yourserver\\yourshare /PERSISTENT:YES < nul"
            sys.stdout.write("Z: MAPPING WITH: " + cmd + "\n")
            sys.stdout.flush()
            os.system(cmd)

    This should be fine if the drive mappings are needed for the
    renderer.

    But if the drive mapping is needed to find the submit script
    or the log directory, that's a problem better solved by making
    sure those paths are UNC instead of drive map paths.
    This prevents the catch-22 situation on the render nodes
    where rush can't run the script to fix the drive maps if rush
    is told to invoke the script with a drive map path that doesn't
    yet exist.

    In this case, you have to ensure the pathname to the script
    *and* log directory are both UNC paths so rush can run the script.
    Then the script can fix the drive mappings up so the renderer can
    run successfully.

    Fortunately, you can force the submit form to fix drive map paths
    during submit by modifying the FixPath() function in .common.pl
    on your fileserver, so that the pathname is fixed just before the
    job is submitted to Rush; this will handle translating the drive letters
    into a UNC equivalent.

    See the lines commented with "# ADD THIS LINE" in the following
    to handle changing several different drive mappings:

        sub FixPath($)
        {
            my ($path) = @_;
            [..stuff snipped..]

            $path =~ s%/\./%/%g;                # /foo/./bar -> /foo/bar

            $path =~ s%^z:%//yourserver/share1%gi;      # ADD THIS LINE: z: -> //yourserver/share1
            $path =~ s%^y:%//yourserver/share2%gi;      # ADD THIS LINE: y: -> //yourserver/share2
            $path =~ s%^x:%//yourserver/share3%gi;      # ADD THIS LINE: x: -> //yourserver/share3

            return($path);
        }

    The python scripts can be modified similarly in the lib/RushSiteSettings.py
    file's similarly named FixPath() function.

        def FixPath(path):

            [..stuff snipped..]

            path = re.sub("^[zZ]:", "//server/share1", path)  # ADD THIS LINE: z: -> //server/share1
            path = re.sub("^[yY]:", "//server/share2", path)  # ADD THIS LINE: y: -> //server/share2
            path = re.sub("^[xX]:", "//server/share3", path)  # ADD THIS LINE: x: -> //server/share3

            return(path)

    UPDATE:
    With newer versions of Rush 103, you don't have to edit the perl or python scripts,
    and can use the rush/etc/path_convert file to configure drive mappings and pathname
    translations; see: http://seriss.com/rush.103.00/rush/rush-path_convert.html

[EDIT: 12/11/2017 -- Added python equivalent examples and Rush 103 path_convert link.]