Rev 29 | Rev 5513 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
Option Explicit'=====================================================' Name: common_subs.vbs' Description: Contains list of common subs and functions'====================================================='-----------------------------------------------------------------------------------------------------------------' NOTE: This is NOT USED' It is here only to satisfy Application variable in asp which VBS don't know aboutFunction Application( sParam )If sParam = "TNS_NAME" ThenApplication = ""ElseIf sParam = "RELEASE_MANAGER_LOGIN" ThenApplication = ""End IfEnd Function'-----------------------------------------------------------------------------------------------------------------Function ReadFile( SSpath )Dim filesys, rfileSet filesys = CreateObject("Scripting.FileSystemObject")'On Error Resume NextIf filesys.FileExists ( SSpath ) ThenSet rfile = filesys.OpenTextFile( SSpath, 1, false)ReadFile = rfile.ReadAllrfile.closeElse'Call RaiseEvent ( enumEVENT_ERROR, "[sub:ReadFile]", _' "File: "& SSpath, _' "File not found!" )End If'Call ErrorCheck ( "[sub:ReadFile]", NULL )Set filesys = nothingEnd Function'-----------------------------------------------------------------------------------------------------------------Sub SaveBatchFile( SSpath, SSfilename, SScontent )Dim filesys, filetxtSet filesys = CreateObject("Scripting.FileSystemObject")WScript.Echo "Saving file "& SSpath &"\"& SSfilename &" ..."On Error Resume NextSet filetxt = filesys.CreateTextFile( SSpath &"\"& SSfilename, True )filetxt.WriteLine(SScontent)filetxt.CloseCall ErrorCheck ( "[sub:SaveFile]", NULL )WScript.Echo "File Saved: "& SSpath &"\"& SSfilenameSet filetxt = nothingSet filesys = nothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Function NicePath(path)NicePath = Replace(path," " , "",1,-1)NicePath = Replace(NicePath,"/" , "-",1,-1)NicePath = Replace(NicePath,"--" , "-",1,-1)End Function'-----------------------------------------------------------------------------------------------------------------Sub SaveFile( SSDate, SSversion, SSrelease, SSpath, SSfilename, SScontent )Dim filesys, filetxt, folderSet filesys = CreateObject("Scripting.FileSystemObject")WScript.Echo "Saving file "& SSpath &"\"& SSfilename &" ..."On Error Resume NextSet folder = filesys.CreateFolder(SSpath &"\"& SSrelease)Set folder2 = filesys.CreateFolder(SSpath &"\"& SSrelease &"\"& SSversion)Set folder3 = filesys.CreateFolder(SSpath &"\"& SSrelease &"\"& SSversion &"\"& SSDate)Set filetxt = filesys.CreateTextFile( SSpath &"\"& SSrelease &"\"& SSversion &"\"& SSDate &"\"& SSfilename, True )filetxt.WriteLine(SScontent)filetxt.Close'Call ErrorCheck ( "[sub:SaveFile]", Null )WScript.Echo "File Saved: "& SSpath &"\"& SSfilenameSet folder2 = nothingSet folder = nothingSet filetxt = nothingSet filesys = nothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub DeleteFile( SSpath )Dim filesysSet filesys = CreateObject("Scripting.FileSystemObject")If filesys.FileExists(SSpath) Thenfilesys.DeleteFile SSpathEnd IfSet filesys = nothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub DeleteFolder( SSpath )Dim filesysSet filesys = CreateObject ("Scripting.FileSystemObject")If filesys.FolderExists( SSpath ) Thenfilesys.DeleteFolder SSpath, TRUEEnd IfEnd Sub'-----------------------------------------------------------------------------------------------------------------Function Folder_Is_Empty ( sPath )Dim filesys, oFolderSet filesys = CreateObject("Scripting.FileSystemObject")If filesys.FolderExists( sPath ) ThenSet oFolder = filesys.GetFolder( sPath )If ( oFolder.Files.Count + oFolder.SubFolders.Count ) > 0 ThenFolder_Is_Empty = FALSEElseFolder_Is_Empty = TRUEEnd IfElseFolder_Is_Empty = TRUEEnd IfEnd Function'-----------------------------------------------------------------------------------------------------------------Function GetQuery ( sQryName )GetQuery = ReadFile( QUERIES_PATH &"\"& sQryName )End Function'-----------------------------------------------------------------------------------------------------------------Function NVL ( SSvalue )If IsNull(SSvalue) Or SSvalue = "" ThenNVL = " "ElseNVL = SSvalueEnd IfEnd Function'-----------------------------------------------------------------------------------------------------------------Function Format_FileName( sPkg_name, sPkg_version, nPv_id )Dim name, versionname = Replace( sPkg_name, " ", "_")version = Replace( sPkg_version, " ", "")version = Replace( version, ".", "_")Format_FileName = RELESE_NOTES_PERFIX &"_"& nPv_id &"_"& name &"_"& version &".html"End Function'-----------------------------------------------------------------------------------------------------------------Function Get_Application_Path ()Dim tempSTRtempSTR = WScript.ScriptFullNameGet_Application_Path = Left( tempSTR, InStrRev( tempSTR, "\", InStrRev( tempSTR, "\" ) -1 ) )End Function'-----------------------------------------------------------------------------------------------------------------Sub Include_File ( SSFile )Dim myIncludemyInclude = ReadFile( SSFile )myInclude = Replace ( myInclude, "<%", "" ) ' Remove ASP tagsmyInclude = Replace ( myInclude, "%>", "" ) ' Remove ASP tagsExecute( myInclude )End Sub'-----------------------------------------------------------------------------------------------------------------Sub CRC_cksum ( SSfile_name, outCRC, outSize )Dim sysShell, crcDump, oExec, outStdErr, outStrOut, crcARRSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( AppPath & CKSUM_EXE &" """& SSfile_name &"""" )outStdErr = oExec.StdErr.ReadLineoutStrOut = oExec.StdOut.ReadLineIf outStdErr = "" ThencrcDump = Trim( outStrOut )crcDump = Replace ( crcDump, VBNewLine, "" ) ' Remove newline charactersWhile InStr( crcDump, " ") > 0crcDump = Replace ( crcDump, " ", " " ) ' Ensure single space between itemsWendcrcARR = Split ( crcDump, " " ) ' Split with spaceoutCRC = crcARR(0)outSize = crcARR(1)ElseoutCRC = -1 ' Error occuerd during cksum. Can be no read permissionsoutSize = -1End IfSet sysShell = nothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub CRC_modcrc ( SSfile_name, SSfile_path, outCRC, outSize )Dim sysShell, crcDump, oExec, outStdErr, outStrOut, crcARRSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( AppPath & MODCRC_EXE &" -m="& SSfile_path & SSfile_name &" -i=thx" )outStdErr = oExec.StdErr.ReadLineoutStrOut = oExec.StdOut.ReadLineIf outStdErr = "" ThencrcDump = Trim( outStrOut )crcDump = Replace ( crcDump, VBNewLine, "" ) ' Remove newline charactersWhile InStr( crcDump, " ") > 0crcDump = Replace ( crcDump, " ", " " ) ' Ensure single space between itemsWendcrcARR = Split ( crcDump, " " ) ' Split with spaceoutCRC = crcARR(4)outSize = crcARR(6)ElseoutCRC = -1 ' Error occuerd during cksum. Can be no read permissionsoutSize = -1End IfSet sysShell = nothingEnd Sub'-----------------------------------------------------------------------------------------------------------------'Sub RaiseEvent ( eventType, SSlocation, SSvalues, SSerror_message )' Dim WshShell, WshNetwork, objArgs, i, agrSTR, SSmsg' Set WshShell = WScript.CreateObject("WScript.Shell")' Set WshNetwork = WScript.CreateObject("WScript.Network")'' Set objArgs = WScript.Arguments' For i = 0 to objArgs.Count - 1' agrSTR = agrSTR & objArgs(i) & vbNewLine' Next'' ' Compose Message' SSmsg = _' "-- Script Info --"& VBNewLine &_' "Host Name: "& WshNetwork.ComputerName & VBNewLine &_' "Script Name: "& WScript.ScriptName & VBNewLine & VBNewLine &_' "-- Script Parameters --"& VBNewLine &_' agrSTR &_' VBNewLine &_' "-- Error Location --"& VBNewLine &_' SSlocation & VBNewLine &_' VBNewLine &_' "-- Values --"& VBNewLine &_' SSvalues & VBNewLine &_' VBNewLine &_' "-- Error Message --"& VBNewLine &_' SSerror_message & VBNewLine'' '-- Raise this message at these places...' Wscript.Echo SSmsg' WshShell.LogEvent eventType, SSmsg' 'Call Alert_Admin ( SSmsg )' '----------------------------------------'' Set WshShell = Nothing'' 'If Not IsNull(sDBmsg) Then Call Write_To_Release_Notes_Info ( parPv_id, sDBmsg )' If eventType = enumEVENT_ERROR Then WScript.Quit ' Only Quit if Error''End Sub'-----------------------------------------------------------------------------------------------------------------'Sub ErrorCheck ( ERRlocation, ERRvals )' If Err.Number <> 0 Then' Call RaiseEvent ( enumEVENT_ERROR, ERRlocation, ERRvals, Err.Source &" "& Err.Description )' End If' Err.Clear'End Sub'-----------------------------------------------------------------------------------------------------------------Sub Alert_Admin ( SSmsg )'Call Send_Email ( adminEmail, adminEmail, "Windows Script Alert!", SSmsg )End Sub'-----------------------------------------------------------------------------------------------------------------Sub Send_Email ( SSfrom, SSto, SSsubject, SSbody )'Dim objCDOMail'Set objCDOMail = CreateObject("CDONTS.NewMail")''objCDOMail.From = Request.Form("firstName") & " " & Request.Form("lastName") & " <" & strReturnEmailAddress & ">"'objCDOMail.From = SSfrom'objCDOMail.To = SSto''objCDOMail.Cc = strCCEmailAddress''objCDOMail.Bcc = strBCCEmailAddress'objCDOMail.Subject = SSsubject'objCDOMail.BodyFormat = 1 ' 0 = HTML, 1 = Plain'objCDOMail.MailFormat = 1 ' 0 = MIME, 1 = Text'objCDOMail.Importance = 0 ' 0 = High, 1 = Medium, 2 = Low''objCDOMail.attachFile ("c:\images\mypicture.gif") ' you can also attach files'objCDOMail.Body = SSbody''objCDOMail.Send'Set objCDOMail = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Get_PV_ID ( SSpkg_name, SSpkg_version, outPV_ID)Dim Query_String, rsTempIf outPV_ID <> "" Then Exit Sub ' PV_ID already assignedQuery_String = _" SELECT pv.pv_id"&_" FROM packages pkg,"&_" package_versions pv"&_" WHERE pv.pkg_id = pkg.pkg_id"&_" AND pkg.pkg_name = '"& SSpkg_name &"'"&_" AND pv.pkg_version = '"& SSpkg_version &"'"Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) ThenoutPV_ID = rsTemp("pv_id")ElseCall Raise_Event ( enumEVENT_ERROR, "[sub:Get_PV_ID]", _"pkg_name: "& SSpkg_name & VBNewLine &_"pkg_version: "& SSpkg_version , _"pkg_name and/or pkg_version not found in Release Manager database!", enum_RELEASE_NOTES_FAILED )End IfrsTemp.CloseSet rsTemp = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Function Get_Package_Type ( NNpv_id )Dim Query_String, rsTempQuery_String = ReadFile( AppPath & QUERIES_FOLDER & "\package_type.sql" )OraDatabase.Parameters.Add "PV_ID", NNpv_id, ORAPARM_INPUT, ORATYPE_NUMBEROraDatabase.Parameters.Add "enumBASE_VIEW_PRODUCTS", enumBASE_VIEW_PRODUCTS, ORAPARM_INPUT, ORATYPE_NUMBERSet rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) ThenIf Not IsNull( rsTemp("message") ) ThenGet_Package_Type = Eval(rsTemp("message"))ElseGet_Package_Type = enumPKG_TYPE_GENERIC_DPKGEnd IfElseGet_Package_Type = enumPKG_TYPE_GENERIC_DPKGEnd IfWScript.Echo "Package Type : "& Get_Package_TypeOraDatabase.Parameters.Remove "PV_ID"OraDatabase.Parameters.Remove "enumBASE_VIEW_PRODUCTS"rsTemp.CloseSet rsTemp = NothingEnd Function'-----------------------------------------------------------------------------------------------------------------Sub Get_Pkg_Name_Version ( NNpv_id, outPkg_name, outPkg_version )Dim Query_String, rsTempQuery_String = _" SELECT pkg.pkg_name, pv.pkg_version"&_" FROM packages pkg,"&_" package_versions pv"&_" WHERE pv.pkg_id = pkg.pkg_id"&_" AND pv.pv_id = "& NNpv_idSet rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) ThenoutPkg_name = rsTemp("pkg_name")outPkg_version = rsTemp("pkg_version")ElseCall Raise_Event ( enumEVENT_ERROR, "[sub:Get_Pkg_Name_Version]", _"PV_ID: "& NNpv_id , _"PV_ID not found in Release Manager database!", enum_RELEASE_NOTES_FAILED )End IfrsTemp.CloseSet rsTemp = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Check_Requirements_To_Proceed ( nPv_id )Dim Query_String, rsTemp' Exit if Release Notyes Generation is forcedIf objArgs.Named.Item("f") <> "" Then Exit SubQuery_String = _" SELECT pv.release_notes_info"&_" FROM package_versions pv"&_" WHERE pv.pv_id = "& nPv_idSet rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))If rsTemp("release_notes_info") <> enum_RELEASE_NOTES_GENERATING ThenWScript.Echo "Exiting this job. release_notes_info in [PACKAGE_VERSIONS] table is ("& rsTemp("release_notes_info") &")"WScript.Echo "Expected value is ("& enum_RELEASE_NOTES_GENERATING &")"Call Raise_Event ( enumEVENT_ERROR, "[sub:Check_Requirements_To_Proceed]", _"PV_ID: "& nPv_id , _"Exiting this job. release_notes_info in [PACKAGE_VERSIONS] table is ("& rsTemp("release_notes_info") &")", NULL )End IfrsTemp.CloseSet rsTemp = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------'Sub Write_To_Release_Notes_Info ( nPv_id, sMsg )' WScript.Echo "Writing message to release_notes_info in [PACKAGE_VERSIONS] table."' WScript.Echo sMsg' OraSession.BeginTrans' OraDatabase.ExecuteSQL " UPDATE package_versions "&_' " SET release_notes_info = '"& sMsg &"'"&_' " WHERE pv_id = "& nPv_id' OraSession.CommitTrans'End Sub'-----------------------------------------------------------------------------------------------------------------Function FormatTextBox ( SSstr )If SSstr <> "" Or NOT IsNull(SSstr) ThenFormatTextBox = Replace ( SSstr, VBNewLine, "<br>")End IfEnd Function'-----------------------------------------------------------------------------------------------------------------Function HTML_Encode ( sSTR )Dim tempSTRtempSTR = sSTRIf IsNull( tempSTR ) Or tempSTR = "" ThenHTML_Encode = ""ElsetempSTR = Replace ( tempSTR, "&", "&" )tempSTR = Replace ( tempSTR, "<", "<" )tempSTR = Replace ( tempSTR, ">", ">" )HTML_Encode = tempSTREnd IfEnd Function'-----------------------------------------------------------------------------------------------------------------------------Function EuroDate ( dDate )' Ensures Euro Date format DD/MM/YYYYIf IsNull(dDate) Then Exit FunctionEuroDate = Day(dDate) &"/"& Month(dDate) &"/"& Year(dDate)End Function'-----------------------------------------------------------------------------------------------------------------------------Function DateReversed ( dDate )' Ensures Reverse Date format YYYY-MM-DDIf IsNull(dDate) Then Exit FunctionDateReversed = Year(dDate) &"-"& Month(dDate) &"-"& Day(dDate)End Function'-----------------------------------------------------------------------------------------------------------------------------Function EuroDateTime ( dDate )' Ensures Euro DateTime format DD/MM/YYYY H24:MIN:SSIf IsNull(dDate) Then Exit FunctionEuroDateTime = Day(dDate) &"/"& Month(dDate) &"/"& Year(dDate) &" "& FormatDateTime( dDate, 4 )End Function'-----------------------------------------------------------------------------------------------------------------