Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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