Subversion Repositories DevTools

Rev

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