Subversion Repositories DevTools

Rev

Rev 3610 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'=====================================================
'        Name:  pkg_archive
' Description:  This library contains methods required
'               for dpkg_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                 = "vix\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, rv
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                WScript.Echo "Allowing Read and Write on folder "& SSpkg_name & "/" & SSpkg_version 
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' Make the package writable
        ' Invoke script on package server to perform the hard work
        ' It must be done under UNIX as it can't be done under windows
        '
                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 

        'WScript.Echo login_details &" """& command &""""

                Set sysShell = WScript.CreateObject("WScript.Shell")
                rv = sysShell.Run ("cmd.exe /c "& login_details &" """& command &"""", 0, True)
                Set sysShell = Nothing
        
        If ( rv <> 0 ) then
          Call Raise_Event ( enumEVENT_ERROR, "Ensure_Read_Write", "Command Failure: " & rv, "Command :" & login_details &" """& command &"""",enum_RELEASE_NOTES_FAILED   )
        End If
        
                
        End Sub
        '-----------------------------------------------------------------------------------------------------------------      
        Sub All_Read_Only ( SSpkg_name, SSpkg_version )
                Dim outMachine, outUser, outPassword, rv
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' Make package ReadOnly
                
                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 
        
        'WScript.Echo login_details &" """& command &""""
                Set sysShell = WScript.CreateObject("WScript.Shell")
                rv = sysShell.Run ("cmd.exe /c "& login_details &" """& command &"""", 0, True)
                Set sysShell = Nothing
        
        If ( rv <> 0 ) then
          Call Raise_Event ( enumEVENT_ERROR, "All_Read_Only", "Command Failure: " & rv, "Command :" & login_details &" """& command &"""",enum_RELEASE_NOTES_FAILED   )
        End If
                
        End Sub 
        '-----------------------------------------------------------------------------------------------------------------      
        Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )
                Dim outMachine, outDpkg_root, outUser, outPassword, rv
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                ' --- Commands to run ---
                command = _
                "sudo ~/sbin/make_docFolder "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"' '" & docFolder &"';"
        
                WScript.Echo command
                
                ' --- SSH client with login details ---
                login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                
        'WScript.Echo login_details &" """& command &""""
                Set sysShell = WScript.CreateObject("WScript.Shell")
                rv = sysShell.Run ("cmd.exe /c "& login_details &" """& command &"""", 0, True)
        Set sysShell = Nothing
        
        If ( rv <> 0 ) then
          Call Raise_Event ( enumEVENT_ERROR, "Create_Doc_Folder", "Command Failure: " & rv, "Command :" & login_details &" """& command &"""",enum_RELEASE_NOTES_FAILED   )
        End If
                

        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, rv
                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 & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                
        'WScript.Echo login_details &" """& command &""""
                Set sysShell = WScript.CreateObject("WScript.Shell")
                rv = sysShell.Run ("cmd.exe /c "& login_details &" """& command &"""", 0, True)
        Set sysShell = Nothing
        
        If ( rv <> 0 ) then
          Call Raise_Event ( enumEVENT_ERROR, "Make_Release_Changed", "Command Failure: " & rv, "Command :" & login_details &" """& command &"""",enum_RELEASE_NOTES_FAILED   )
        End If
                
                
        End Sub
    
    '-----------------------------------------------------------------------------------------------------------------
        Function Test_Pkg_Archive_Access ()
                Dim outUser, outPassword, rv, fv
                Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
                WScript.Echo "Test_Pkg_Archive_Access"
                
        fv = 0
                Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
                
                command = _
                 "sudo ~/sbin/make_test_access;"
        
                WScript.Echo command
                
                ' --- SSH client with login details ---
                login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
                
        WScript.Echo login_details &" """& command &""""
                Set sysShell = WScript.CreateObject("WScript.Shell")
                rv = sysShell.Run ("cmd.exe /c "& login_details &" """& command &"""", 0, True)
        Set sysShell = Nothing
        
        WScript.Echo "Results: " & rv
        If ( rv <> 55 ) then
          Call Raise_Event ( enumEVENT_ERROR, "Test_Pkg_Archive_Access", "Command Failure: " & rv, "Command :" & login_details &" """& command &"""",enum_RELEASE_NOTES_FAILED   )
          fv = 1
        End If
        
    Test_Pkg_Archive_Access = fv
    
        End Function
    
    
End Class