Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
Option Explicit
2
'=====================================================
3
'        Name: 	common_subs.vbs
4
' Description:	Contains list of common subs and functions
5
'=====================================================
6
'-----------------------------------------------------------------------------------------------------------------
7
' NOTE: This is NOT USED
8
' It is here only to satisfy Application variable in asp which VBS don't know about
9
Function Application( sParam )
10
	If sParam = "TNS_NAME" Then
11
		Application = ""
12
	ElseIf sParam = "RELEASE_MANAGER_LOGIN" Then
13
		Application = ""
14
	End If
15
End Function
16
'-----------------------------------------------------------------------------------------------------------------
17
Function ReadFile( SSpath )
18
	Dim filesys, rfile
19
	Set filesys = CreateObject("Scripting.FileSystemObject")
20
 
21
	On Error Resume Next
22
	If filesys.FileExists ( SSpath ) Then
23
    	Set rfile = filesys.OpenTextFile( SSpath, 1, false)
24
    	ReadFile = rfile.ReadAll
25
    	rfile.close
26
    Else
27
        Call Raise_Event ( enumEVENT_ERROR, "[sub:ReadFile]", _
28
											"File: "& SSpath, _
29
						   					"File not found!", enum_RELEASE_NOTES_FAILED )
30
    End If
31
 
32
	Call ErrorCheck ( "[sub:ReadFile]", NULL )
33
 
34
	Set filesys = nothing
35
End Function
36
'-----------------------------------------------------------------------------------------------------------------
37
Sub SaveFile( SSpath, SSfilename, SScontent )
38
	Dim filesys, filetxt
39
	Set filesys = CreateObject("Scripting.FileSystemObject")
40
    WScript.Echo "Saving file "& SSpath &"\"& SSfilename &" ..."
41
 
42
	On Error Resume Next
43
	Set filetxt = filesys.CreateTextFile( SSpath &"\"& SSfilename, True )
44
	filetxt.WriteLine(SScontent)
45
	filetxt.Close
46
 
47
	Call ErrorCheck ( "[sub:SaveFile]", NULL )
48
 
49
	WScript.Echo "File Saved: "& SSpath &"\"& SSfilename
50
	Set filetxt = nothing
51
	Set filesys = nothing
52
End Sub
53
'-----------------------------------------------------------------------------------------------------------------
54
Sub DeleteFile( SSpath )
55
	Dim filesys
56
	Set filesys = CreateObject("Scripting.FileSystemObject")
57
	If filesys.FileExists(SSpath) Then
58
   		filesys.DeleteFile SSpath 
59
	End If 
60
	Set filesys = nothing
61
End Sub
62
'-----------------------------------------------------------------------------------------------------------------
63
Sub DeleteFolder( SSpath )
64
	Dim  filesys
65
	Set filesys = CreateObject ("Scripting.FileSystemObject")
66
	If filesys.FolderExists( SSpath ) Then
67
		filesys.DeleteFolder SSpath, TRUE
68
	End If
69
End Sub
70
'-----------------------------------------------------------------------------------------------------------------
71
Function Folder_Is_Empty ( sPath )
72
	Dim filesys, oFolder
73
	Set filesys = CreateObject("Scripting.FileSystemObject") 
74
 
75
	If filesys.FolderExists( sPath ) Then
76
		Set oFolder = filesys.GetFolder( sPath )  
77
		If ( oFolder.Files.Count + oFolder.SubFolders.Count ) > 0 Then
78
			Folder_Is_Empty = FALSE
79
		Else
80
			Folder_Is_Empty = TRUE
81
		End If
82
	Else
83
		Folder_Is_Empty = TRUE
84
	End If
85
 
86
End Function
87
'-----------------------------------------------------------------------------------------------------------------
88
Function NVL ( SSvalue )
89
	If IsNull(SSvalue) Or SSvalue = "" Then
90
		NVL = " "
91
	Else
92
		NVL = SSvalue
93
	End If
94
End Function
95
'-----------------------------------------------------------------------------------------------------------------
96
Function Format_FileName( sPkg_name, sPkg_version, nPv_id )
97
	Dim name, version
98
	name =  Replace( sPkg_name, " ", "_")
99
	version = Replace( sPkg_version, " ", "")
100
	version = Replace( version, ".", "_")
101
 
102
	Format_FileName = RELESE_NOTES_PERFIX &"_"& nPv_id &"_"& name &"_"& version &".html"
103
End Function
104
'-----------------------------------------------------------------------------------------------------------------
105
Function Get_Application_Path ()
106
	Dim tempSTR
107
	tempSTR = WScript.ScriptFullName
108
 
109
	Get_Application_Path = Left( tempSTR, InStrRev( tempSTR, "\", InStrRev( tempSTR, "\" ) -1 ) )
110
End Function
111
'-----------------------------------------------------------------------------------------------------------------
112
Sub Include_File ( SSFile )
113
	Dim myInclude
114
	myInclude = ReadFile( SSFile )
115
	myInclude = Replace ( myInclude, "<%", "" )		' Remove ASP tags
116
	myInclude = Replace ( myInclude, "%>", "" )		' Remove ASP tags
117
	Execute( myInclude )
118
End Sub
119
'-----------------------------------------------------------------------------------------------------------------
120
Sub CRC_cksum ( SSfile_name, outCRC, outSize )
121
	Dim sysShell, crcDump, oExec, outStdErr, outStrOut, crcARR
122
	Set sysShell = WScript.CreateObject("WScript.Shell")
123
 
124
 
125
	Set oExec = sysShell.Exec( AppPath & CKSUM_EXE &" """& SSfile_name &"""" )
126
 
127
	outStdErr = oExec.StdErr.ReadLine
128
	outStrOut = oExec.StdOut.ReadLine
129
 
130
	If outStdErr = "" Then
131
		crcDump = Trim( outStrOut )
132
		crcDump = Replace ( crcDump, VBNewLine, "" )		' Remove newline characters
133
		While InStr( crcDump, "  ") > 0
134
			crcDump = Replace ( crcDump, "  ", " " )		' Ensure single space between items
135
		Wend
136
 
137
		crcARR = Split ( crcDump, " " ) 	' Split with space
138
		outCRC = crcARR(0)
139
		outSize = crcARR(1)
140
	Else
141
		outCRC = -1		' Error occuerd during cksum. Can be no read permissions
142
		outSize = -1
143
	End If
144
 
145
	Set sysShell = nothing
146
End Sub
147
'-----------------------------------------------------------------------------------------------------------------
148
Sub CRC_modcrc ( SSfile_name, SSfile_path, outCRC, outSize )
149
	Dim sysShell, crcDump, oExec, outStdErr, outStrOut, crcARR
150
	Set sysShell = WScript.CreateObject("WScript.Shell")
151
 
152
	Set oExec = sysShell.Exec( AppPath & MODCRC_EXE &" -m="& SSfile_path & SSfile_name &" -i=thx" )
153
 
154
	outStdErr = oExec.StdErr.ReadLine
155
	outStrOut = oExec.StdOut.ReadLine
156
 
157
	If outStdErr = "" Then
158
		crcDump = Trim( outStrOut )
159
		crcDump = Replace ( crcDump, VBNewLine, "" )		' Remove newline characters
160
		While InStr( crcDump, "  ") > 0
161
			crcDump = Replace ( crcDump, "  ", " " )		' Ensure single space between items
162
		Wend
163
 
164
		crcARR = Split ( crcDump, " " ) 	' Split with space
165
		outCRC = crcARR(4)
166
		outSize = crcARR(6)
167
	Else
168
		outCRC = -1		' Error occuerd during cksum. Can be no read permissions
169
		outSize = -1
170
	End If
171
 
172
	Set sysShell = nothing
173
End Sub
174
'-----------------------------------------------------------------------------------------------------------------
175
Sub Raise_Event ( eventType, SSlocation, SSvalues, SSerror_message, sDBmsg )
176
	Dim WshShell, WshNetwork, objArgs, i, agrSTR, SSmsg
177
	Set WshShell = WScript.CreateObject("WScript.Shell")
178
    Set WshNetwork = WScript.CreateObject("WScript.Network")
179
 
180
	Set objArgs = WScript.Arguments
181
	For i = 0 to objArgs.Count - 1
182
	   agrSTR = agrSTR & objArgs(i) & VBNewLine
183
	Next
184
 
185
	' Compose Message
186
	SSmsg = _
187
	"-- Script Info  --"& VBNewLine &_
188
	"Host Name: "& WshNetwork.ComputerName & VBNewLine &_
189
	"Script Name: "& WScript.ScriptName & VBNewLine & VBNewLine &_
190
	"-- Script Parameters --"& VBNewLine &_
191
	agrSTR &_
192
	VBNewLine &_
193
	"-- Error Location --"& VBNewLine &_
194
	SSlocation & VBNewLine &_
195
	VBNewLine &_
196
	"-- Values --"& VBNewLine &_
197
	SSvalues & VBNewLine &_
198
	VBNewLine &_
199
	"-- Error Message --"& VBNewLine &_
200
	SSerror_message & VBNewLine 
201
 
202
	'-- Raise this message at these places...
203
	Wscript.Echo SSmsg
204
	WshShell.LogEvent eventType, SSmsg
205
	'Call Alert_Admin ( SSmsg )
206
	'----------------------------------------
207
 
208
	Set WshShell = Nothing
209
 
210
	If Not IsNull(sDBmsg) Then Call Write_To_Release_Notes_Info ( parPv_id, sDBmsg )
211
	If eventType = enumEVENT_ERROR Then WScript.Quit    ' Only Quit if ERROR
212
 
213
End Sub
214
'-----------------------------------------------------------------------------------------------------------------
215
Sub ErrorCheck ( ERRlocation, ERRvals )
216
	If Err.Number <> 0 Then
217
		Call Raise_Event ( enumEVENT_ERROR, ERRlocation, ERRvals, Err.Source &" "& Err.Description, enum_RELEASE_NOTES_FAILED  )
218
	End If
219
	Err.Clear
220
End Sub
221
'-----------------------------------------------------------------------------------------------------------------
222
Sub Alert_Admin ( SSmsg )
223
	'Call Send_Email ( adminEmail, adminEmail, "Windows Script Alert!", SSmsg )
224
End Sub
225
'-----------------------------------------------------------------------------------------------------------------
226
Sub Send_Email ( SSfrom, SSto, SSsubject, SSbody )
227
	'Dim objCDOMail
228
	'Set objCDOMail = CreateObject("CDONTS.NewMail")
229
	''objCDOMail.From = Request.Form("firstName") & " " & Request.Form("lastName") & " <" & strReturnEmailAddress & ">"
230
	'objCDOMail.From = SSfrom
231
	'objCDOMail.To = SSto
232
	''objCDOMail.Cc = strCCEmailAddress
233
	''objCDOMail.Bcc = strBCCEmailAddress
234
	'objCDOMail.Subject = SSsubject
235
	'objCDOMail.BodyFormat = 1		 		' 0 = HTML, 1 = Plain
236
	'objCDOMail.MailFormat = 1 				' 0 = MIME, 1 = Text
237
	'objCDOMail.Importance = 0 				' 0 = High, 1 = Medium, 2 = Low
238
	''objCDOMail.attachFile ("c:\images\mypicture.gif") ' you can also attach files 
239
	'objCDOMail.Body = SSbody
240
	''objCDOMail.Send
241
	'Set objCDOMail = Nothing
242
End Sub
243
'-----------------------------------------------------------------------------------------------------------------
244
Sub Get_PV_ID ( SSpkg_name, SSpkg_version, outPV_ID)
245
	Dim Query_String, rsTemp
246
 
247
	If outPV_ID <> "" Then Exit Sub		' PV_ID already assigned
248
 
249
	Query_String = _
250
	" SELECT pv.pv_id"&_
251
	" FROM packages pkg,"&_
252
	"      package_versions pv"&_
253
	" WHERE pv.pkg_id = pkg.pkg_id"&_
254
	"   AND pkg.pkg_name = '"& SSpkg_name &"'"&_
255
	"   AND pv.pkg_version = '"& SSpkg_version &"'"
256
	Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))
257
 
258
	If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) Then
259
		outPV_ID = rsTemp("pv_id")
260
	Else
261
		Call Raise_Event ( enumEVENT_ERROR, "[sub:Get_PV_ID]", _
262
											"pkg_name: "& SSpkg_name & VBNewLine &_
263
											"pkg_version: "& SSpkg_version , _
264
						   					"pkg_name and/or pkg_version not found in Release Manager database!", enum_RELEASE_NOTES_FAILED )
265
	End If
266
	rsTemp.Close
267
	Set rsTemp = Nothing
268
End Sub
269
'-----------------------------------------------------------------------------------------------------------------
270
Function Get_Package_Type ( NNpv_id )
271
	Dim Query_String, rsTemp
272
 
273
	Query_String = ReadFile( AppPath & QUERIES_FOLDER & "\package_type.sql" )
274
	OraDatabase.Parameters.Add "PV_ID", NNpv_id, ORAPARM_INPUT, ORATYPE_NUMBER
275
	OraDatabase.Parameters.Add "enumBASE_VIEW_PRODUCTS", enumBASE_VIEW_PRODUCTS, ORAPARM_INPUT, ORATYPE_NUMBER
276
	Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))
277
 
278
	If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) Then
279
		If Not IsNull( rsTemp("message") ) Then 
280
			Get_Package_Type = Eval(rsTemp("message"))
281
		Else
282
			Get_Package_Type = enumPKG_TYPE_GENERIC_DPKG
283
		End If
284
	Else
285
		Get_Package_Type = enumPKG_TYPE_GENERIC_DPKG
286
	End If
287
 
288
	WScript.Echo "Package Type : "& Get_Package_Type
289
 
290
	OraDatabase.Parameters.Remove "PV_ID"
291
	OraDatabase.Parameters.Remove "enumBASE_VIEW_PRODUCTS"
292
	rsTemp.Close
293
	Set rsTemp = Nothing
294
End Function
295
'-----------------------------------------------------------------------------------------------------------------
296
Sub Get_Pkg_Name_Version ( NNpv_id, outPkg_name, outPkg_version )
297
	Dim Query_String, rsTemp
298
 
299
	Query_String = _
300
	" SELECT pkg.pkg_name, pv.pkg_version"&_
301
	" FROM packages pkg,"&_
302
	"      package_versions pv"&_
303
	" WHERE pv.pkg_id = pkg.pkg_id"&_
304
	"   AND pv.pv_id = "& NNpv_id 
305
	Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))
306
 
307
	If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) Then
308
		outPkg_name = rsTemp("pkg_name")
309
		outPkg_version = rsTemp("pkg_version")
310
	Else
311
		Call Raise_Event ( enumEVENT_ERROR, "[sub:Get_Pkg_Name_Version]", _
312
											"PV_ID: "& NNpv_id , _
313
		 								    "PV_ID not found in Release Manager database!", enum_RELEASE_NOTES_FAILED )
314
	End If
315
 
316
	rsTemp.Close
317
	Set rsTemp = Nothing
318
End Sub
319
'-----------------------------------------------------------------------------------------------------------------
320
Sub Check_Requirements_To_Proceed ( nPv_id )
321
	Dim Query_String, rsTemp
322
 
323
	' Exit if Release Notyes Generation is forced
324
	If objArgs.Named.Item("f") <> "" Then Exit Sub
325
 
326
 
327
	Query_String = _
328
	" SELECT pv.release_notes_info"&_
329
	" FROM package_versions pv"&_
330
	" WHERE pv.pv_id = "& nPv_id
331
 
332
	Set rsTemp = OraDatabase.CreateDynaset( Query_String, cint(0))
333
 
334
	If rsTemp("release_notes_info") <> enum_RELEASE_NOTES_GENERATING Then
335
	    WScript.Echo "Exiting this job. release_notes_info in [PACKAGE_VERSIONS] table is ("& rsTemp("release_notes_info") &")"
336
	    WScript.Echo "Expected value is ("& enum_RELEASE_NOTES_GENERATING &")"
337
	    Call Raise_Event ( enumEVENT_ERROR, "[sub:Check_Requirements_To_Proceed]", _
338
											"PV_ID: "& nPv_id , _
339
		 								    "Exiting this job. release_notes_info in [PACKAGE_VERSIONS] table is ("& rsTemp("release_notes_info") &")", NULL )
340
	End If
341
 
342
	rsTemp.Close
343
	Set rsTemp = Nothing
344
End Sub
345
'-----------------------------------------------------------------------------------------------------------------
346
Sub Write_To_Release_Notes_Info ( nPv_id, sMsg )
347
    WScript.Echo "Writing message to release_notes_info in [PACKAGE_VERSIONS] table."
348
    WScript.Echo sMsg
349
    OraSession.BeginTrans
350
	OraDatabase.ExecuteSQL " UPDATE package_versions "&_
351
						   " SET release_notes_info = '"& sMsg &"'"&_
352
						   " WHERE pv_id = "& nPv_id
353
    OraSession.CommitTrans
354
End Sub
355
'-----------------------------------------------------------------------------------------------------------------
356
Function FormatTextBox ( SSstr ) 
357
	If SSstr <> "" Or NOT IsNull(SSstr) Then
358
		FormatTextBox = Replace ( SSstr, VBNewLine, "<br>") 
359
	End If
360
End Function
361
'-----------------------------------------------------------------------------------------------------------------
362
Function HTML_Encode ( sSTR )
363
    Dim tempSTR
364
    tempSTR = sSTR
365
    If IsNull( tempSTR ) Or tempSTR = "" Then
366
        HTML_Encode = ""
367
    Else
368
        tempSTR = Replace ( tempSTR, "&", "&amp;" )
369
        tempSTR = Replace ( tempSTR, "<", "&lt;" )
370
        tempSTR = Replace ( tempSTR, ">", "&gt;" )
371
        HTML_Encode = tempSTR
372
    End If
373
End Function
374
'-----------------------------------------------------------------------------------------------------------------------------
375
Function EuroDate ( dDate )
376
	' Ensures Euro Date format DD/MM/YYYY
377
	If IsNull(dDate) Then Exit Function
378
	EuroDate = Day(dDate) &"/"& Month(dDate) &"/"& Year(dDate)
379
End Function
380
'-----------------------------------------------------------------------------------------------------------------------------
381
Function EuroDateTime ( dDate )
382
	' Ensures Euro DateTime format DD/MM/YYYY H24:MIN:SS
383
	If IsNull(dDate) Then Exit Function
384
	EuroDateTime = Day(dDate) &"/"& Month(dDate) &"/"& Year(dDate) &" "& FormatDateTime( dDate, 4 )
385
End Function
386
'-----------------------------------------------------------------------------------------------------------------