Subversion Repositories DevTools

Rev

Rev 165 | Rev 187 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'=====================================================
'        Name:  pkg_archive
' Description:  This library contains methods required
'               for dpkg_archive and deploy_archive 
'               manipulation. 
'=====================================================

Option Explicit

Class PkgArchive
        '================ Properties Declaration =============
        Private pRemote_Host
        Private pArchive_Path
        
        
        '==================== Properties =====================
        Public Property Let Remote_Host( SSrhost )
                pRemote_Host = SSrhost
        End Property
        
        Public Property Let Archive_Path( SSarch_path )
                pArchive_Path = UnixPath(SSarch_path)
        End Property
        
        
        '====================== Methods ======================
        '-----------------------------------------------------------------------------------------------------------------
        Private Sub Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                outUser                 = "releasem"
                outPassword     = "releasem"
        End Sub
        '-----------------------------------------------------------------------------------------------------------------
        Private Sub Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
                outUser                 = "erg\releasem"
                outPassword     = "releasem"
        End Sub
        '-----------------------------------------------------------------------------------------------------------------
        Function UnixPath( SSpath )
                If SSpath <> "" Then UnixPath = Replace( SSpath, "\", "/" )
        End Function
    '-----------------------------------------------------------------------------------------------------------------
        Sub Ensure_Read_Write ( SSpkg_name, SSpkg_version )
                Dim outMachine, outUser, outPassword
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                WScript.Echo "Allowing Read and Write on folder "& SSpkg_version 
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' Set all folders to +RWX and all files to +RW
                ' --- Commands to run ---
                'command = _
                '"cd "& pArchive_Path &" && "&_
                '"chmod a+rwx "& SSpkg_name &"; "&_
                '"cd "& SSpkg_name &" && "&_
                '"find '"& SSpkg_version &"' -type d -exec chmod a+rwx {} \; ; "&_
                '"chmod -R a+rw "& SSpkg_version &"; "
                
                command = _
                "sudo ~/sbin/make_writable "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
                
                WScript.Echo command
                
                ' --- SSH client with login details ---
                'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
                
                'WScript.Echo login_details &" """& command &""""
                
                Set sysShell = WScript.CreateObject("WScript.Shell")
                sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
                                
                
                
                'Set oExec = sysShell.Exec( login_details &" "& command )
                'Set oExec = sysShell.Exec(  login_details &" """& command &"""" )
                
                'outStrOut = oExec.StdOut.ReadAll
                'outStrErr = oExec.StdErr.ReadAll
                
                'If outStrErr <> "" Then
                '       Call Raise_Event ( enumEVENT_ERROR, "[sub:Ensure_Read_Write]", _
                '                                          "user: "& outUser & VBNewLine &_
                '                                          "command: "& command , _
                '                                          outStrErr, enum_RELEASE_NOTES_FAILED )
                'End If
                'Set oExec = Nothing
                Set sysShell = Nothing
                
        End Sub
        '-----------------------------------------------------------------------------------------------------------------      
        Sub All_Read_Only ( SSpkg_name, SSpkg_version )
                Dim outMachine, outUser, outPassword
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' Set all folders from version folder, to -W and all files to -W
                ' --- Commands to run ---
                'command = _
                '"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
                '"find '"& SSpkg_version &"' -type d -exec chmod a-w {} \; ; "&_
                '"chmod -R a-w "& SSpkg_version &"; "&_
                '"chown -R root:other "& SSpkg_version &"; "
                
                command = _
                "sudo ~/sbin/make_readonly "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
                
                WScript.Echo command
                
                ' --- SSH client with login details ---
                'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
                
                
                
                Set sysShell = WScript.CreateObject("WScript.Shell")
                sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
                
                'Set oExec = sysShell.Exec( login_details &" "& command )
                
                'outStrOut = oExec.StdOut.ReadAll
                'outStrErr = oExec.StdErr.ReadAll
                
                'If outStrErr <> "" Then
                '       Call Raise_Event ( enumEVENT_ERROR, "[sub:All_Read_Only]", _
                '                                          "user: "& outUser & VBNewLine &_
                '                                          "command: "& command , _
                '                                          outStrErr, enum_RELEASE_NOTES_FAILED )
                'End If
                
                'Set oExec = Nothing
                Set sysShell = Nothing
                
        End Sub 
        '-----------------------------------------------------------------------------------------------------------------      
        Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )
                Dim outMachine, outDpkg_root, outUser, outPassword
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' --- Commands to run ---
                ' Creates doc folder if required with rwx permissions for all
                command = _
                "cd "& pArchive_Path &"/"& SSpkg_name &"/"& SSpkg_version &" && "&_
                "mkdir -p -m a+rwx "& docFolder &"; "
                
                WScript.Echo command
                
                ' --- SSH client with login details ---
                'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
                
                
                Set sysShell = WScript.CreateObject("WScript.Shell")
                sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
                
                'Set oExec = sysShell.Exec( login_details &" """& command &"""" )
                'WScript.Echo "HERE:"& oExec
                'outStrOut = oExec.StdOut.ReadAll
                'outStrErr = oExec.StdErr.ReadAll
                
                'If outStrErr <> "" Then
                '       Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Doc_Folder]", _
                '                                          "user: "& outUser & VBNewLine &_
                '                                          "command: "& command , _
                '                                          outStrErr, enum_RELEASE_NOTES_FAILED )
                'End If
                
                'Set oExec = Nothing
                Set sysShell = Nothing
        End Sub
        '-----------------------------------------------------------------------------------------------------------------
        Sub Map_Network_Drive ( SSunc, outMappedDrive )
                Dim outUser, outPassword
                Dim ValidDrivesARR, validDrive, UsedDrives
                Dim i, WshNetwork, oDrives, oFilesys, drv
                WScript.Echo "Mapping drive..."
                
                Call Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
                
                ValidDrivesARR = Array("E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")
                Set WshNetwork = WScript.CreateObject("WScript.Network")
                Set oDrives = WshNetwork.EnumNetworkDrives
                
                ' Check for existing map
                outMappedDrive = ""                     
                For i = 0 to oDrives.Count - 1 Step 2
                        ' Reuse network map if exists
                If UCase(oDrives.Item(i+1)) = UCase(SSunc) Then
                                outMappedDrive = oDrives.Item(i)
                                Exit For
                        End If
        Next
                
                
                If outMappedDrive = "" Then
                        ' Drive need to be mapped, hence map one.
                        
                        ' Get all drive used drive letters.
                        ' NOTE: It will not display a drive if mapped but not connected.
                        Set oFilesys = CreateObject("Scripting.FileSystemObject")
                        Set oDrives = oFilesys.Drives
                        For Each drv in oDrives
                                UsedDrives = UsedDrives &"|"& drv.DriveLetter &":|"
                        Next
                        
                        For Each validDrive In ValidDrivesARR
                                If NOT InStr( UCase(UsedDrives), "|"& UCase(validDrive) &"|") > 0 Then
                                        ' used this unused drive
                                        On Error Resume Next
                                                                                
                                        WshNetwork.MapNetworkDrive validDrive, SSunc, FALSE, outUser, outPassword
                                        
                                        Call ErrorCheck ( "[sub:Map_Network_Drive]", _
                                                                          "used drives: "& UsedDrives & VBNewLine &_
                                                                          "valid letters to pick from: "& Join( ValidDrivesARR, ",") & VBNewLine &_
                                                                          "attempting to map: "& validDrive & VBNewLine &_
                                                                          "UNC: "& SSunc & VBNewLine &_
                                                                          "username: "& outUser )
                                                                          
                                        outMappedDrive = validDrive
                                        Exit For
                                End If
                        Next
                        
                End If
                
                If outMappedDrive = "" Then
                        Call Raise_Event ( enumEVENT_ERROR, "[sub:Map_Network_Drive]", _
                                                           "used drives: "& UsedDrives & VBNewLine &_
                                                           "valid drives to pick from: "& Join( ValidDrivesARR, ",") , _
                                                           "Network drive is not mapped!", enum_RELEASE_NOTES_FAILED )
                End If
                
                WScript.Echo "Using network drive: "& outMappedDrive
                
                Set oDrives = Nothing
                Set WshNetwork = Nothing
        End Sub

    '-----------------------------------------------------------------------------------------------------------------
        Sub Make_Release_Changed (apkg_name, apkg_version, artag_id, apkg_id, apv_id, aproj_id, amode_id, await)
                Dim outUser, outPassword
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                WScript.Echo "Running release changed script for "& apkg_name & " " & apkg_version 
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                command = _
                 "sudo ~/sbin/make_release_changed" &_
                 " archive=" & pArchive_Path &_
                 " pkg_name='""" & apkg_name & """'" &_
                 " pkg_version='"""& apkg_version &"""'" &_
                 " rtag_id="& artag_id &_
                 " pkg_id=" & apkg_id &_
                 " pv_id="& apv_id &_
                 " proj_id="& aproj_id &_
                 " mode_id="& amode_id &_
                 ";"
        
                WScript.Echo command
                
                ' --- SSH client with login details ---
                login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword     
                
                Set sysShell = WScript.CreateObject("WScript.Shell")
                sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, await
                                                
                Set sysShell = Nothing
                
        End Sub
    
End Class