Subversion Repositories DevTools

Rev

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