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