Rev 177 | Blame | 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 about'' Within IIS these data items are provide by global.asa, which is in the root' of the IIS server.'Function 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.closeElseCall Raise_Event ( enumEVENT_ERROR, "[sub:ReadFile]", _"File: "& SSpath, _"File not found!", enum_RELEASE_NOTES_FAILED )End IfCall ErrorCheck ( "[sub:ReadFile]", NULL )Set filesys = nothingEnd Function'-----------------------------------------------------------------------------------------------------------------Sub SaveFile( 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'-----------------------------------------------------------------------------------------------------------------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 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 Raise_Event ( eventType, SSlocation, SSvalues, SSerror_message, sDBmsg )Dim WshShell, WshNetwork, objArgs, i, agrSTR, SSmsgSet WshShell = WScript.CreateObject("WScript.Shell")Set WshNetwork = WScript.CreateObject("WScript.Network")Set objArgs = WScript.ArgumentsFor i = 0 to objArgs.Count - 1agrSTR = agrSTR & objArgs(i) & VBNewLineNext' Compose MessageSSmsg = _"-- 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 SSmsgWshShell.LogEvent eventType, SSmsg'Call Alert_Admin ( SSmsg )'----------------------------------------Set WshShell = NothingIf Not IsNull(sDBmsg) Then Call Write_To_Release_Notes_Info ( parPv_id, sDBmsg )If eventType = enumEVENT_ERROR Then WScript.Quit ' Only Quit if ERROREnd Sub'-----------------------------------------------------------------------------------------------------------------Sub ErrorCheck ( ERRlocation, ERRvals )If Err.Number <> 0 ThenCall Raise_Event ( enumEVENT_ERROR, ERRlocation, ERRvals, Err.Source &" "& Err.Description, enum_RELEASE_NOTES_FAILED )End IfErr.ClearEnd 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, rsPackageVersions, rsRunLevel, rsReleaseConfig, rsReleaseTags' Exit if Release Notyes Generation is forcedIf objArgs.Named.Item("f") <> "" Then Exit SubQuery_String = _" SELECT pv.release_notes_info, pv.pkg_id"&_" FROM package_versions pv"&_" WHERE pv.pv_id = "& nPv_idSet rsPackageVersions = OraDatabase.CreateDynaset( Query_String, cint(0))If rsPackageVersions("release_notes_info") <> enum_RELEASE_NOTES_GENERATING ThenWScript.Echo "Exiting this job. release_notes_info in [PACKAGE_VERSIONS] table is ("& rsPackageVersions("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 ("& rsPackageVersions("release_notes_info") &")", NULL )End If' Do not proceed if the build daemon is building a version of the package. This is an attempt to make sure that' release notes generation does not cause a problem for the build daemons, such as might be the case if and when' it manipulates file ownership later on, etc (see DEVI-48682). This is not a foolproof method to prevent the problem,' but it should reduce the likelyhood of it occuringDim mustAbortmustAbort = FALSEQuery_String = _" SELECT * "&_" FROM run_level rl"&_" WHERE rl.current_pkg_id_being_built = "& rsPackageVersions("pkg_id")Set rsRunLevel = OraDatabase.CreateDynaset( Query_String, cint(0))'For each run_level table entry...Do While (NOT rsRunLevel.BOF) AND (NOT rsRunLevel.EOF) AND (mustAbort = FALSE)' Make sure that the release configuration shows that there is a daemon hostname associated with this' run_level table entry.Query_String = _" SELECT rtag_id, daemon_hostname"&_" FROM release_config"&_" WHERE rcon_id = "& rsRunLevel("rcon_id")Set rsReleaseConfig = OraDatabase.CreateDynaset( Query_String, cint(0))If (rsReleaseConfig.RecordCount > 0) AND NOT IsNull(rsReleaseConfig("daemon_hostname")) Then' ought to check the validity of the daemon hostname - will have to wait for these to be configured metadata' before we can do that though, unless we hard-code the valid names here somewhere.' Anyway, the hostname is not null so it looks like the run_level entry is one we cannot dis-regard' if the run level is ACTIVE (3) then abortIf rsRunLevel("current_run_level") = 3 ThenmustAbort = TRUEElse' run level must be WAITING, PAUSED, etc, so examine the official state of the release to see if' it is still open in some wayQuery_String = _" SELECT official"&_" FROM release_tags"&_" WHERE rtag_id = "& rsReleaseConfig("rtag_id")Set rsReleaseTags = OraDatabase.CreateDynaset( Query_String, cint(0))If (rsReleaseTags.RecordCount > 0) Then' If release is not closed or archivedIf NOT (IsNull(rsReleaseTags("official")) OR (rsReleaseTags("official") = "Y") OR (rsReleaseTags("official") = "A")) Then' release is still open (OPEN or RESTRICTED, or CCB Mode) so abortmustAbort = TRUEEnd IfEnd IfrsReleaseTags.CloseSet rsReleaseTags = NothingEnd IfEnd IfrsReleaseConfig.CloseSet rsReleaseConfig = NothingrsRunLevel.MoveNextLoopIf (mustAbort) ThenWScript.Echo "Exiting this job. Build Daemon is currently building this/another version of this package."WScript.Echo "Try again later."Call Raise_Event ( enumEVENT_ERROR, "[sub:Check_Requirements_To_Proceed]", _"PV_ID: "& nPv_id & VBNewLine & "PKG_ID: "& rsPackageVersions("pkg_id"), _"Exiting this job. Build Daemon is currently building this/another version of this package.", NULL )End IfrsRunLevel.CloseSet rsRunLevel = NothingrsPackageVersions.CloseSet rsPackageVersions = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Write_To_Release_Notes_Info ( nPv_id, sMsg )WScript.Echo "Writing message to release_notes_info in [PACKAGE_VERSIONS] table."OraSession.BeginTransIf IsNULL(sMsg) ThenWScript.Echo "NULL"OraDatabase.ExecuteSQL " UPDATE package_versions "&_" SET release_notes_info = NULL"&_" WHERE pv_id = "& nPv_idElseWScript.Echo sMsgOraDatabase.ExecuteSQL " UPDATE package_versions "&_" SET release_notes_info = '"& sMsg &"'"&_" WHERE pv_id = "& nPv_idEnd IfOraSession.CommitTransEnd 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 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'-----------------------------------------------------------------------------------------------------------------Sub Get_Release_Info (APV_ID, ByRef ARTAG_ID, ByRef APKG_ID)Dim Query_String, rsTempQuery_String = _" SELECT rc.rtag_id, pv.pkg_id"&_" FROM package_versions pv, release_content rc"&_" WHERE rc.pv_id = " & APV_ID &_" AND pv.pv_id = rc.pv_id"Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) ThenARTAG_ID = rsTemp("rtag_id")APKG_ID = rsTemp("pkg_id")ElseCall Raise_Event ( enumEVENT_ERROR, "[sub:Get_Release_Info]", _"PV_ID: "& APV_ID & VBNewLine ,_"pv_id not found in release_content table!", enum_RELEASE_NOTES_FAILED )End IfrsTemp.CloseSet rsTemp = NothingEnd Sub