Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
27 rsolanki 1
'=====================================================
2
'        Name: 	pkg_archive
3
' Description:	This library contains methods required
4
'               for dpkg_archive and deploy_archive 
5
'               manipulation. 
6
'=====================================================
7
 
8
Option Explicit
9
 
10
Class PkgArchive
11
	'================ Properties Declaration =============
12
	Private pRemote_Host
13
	Private pArchive_Path
14
 
15
 
16
	'==================== Properties =====================
17
	Public Property Let Remote_Host( SSrhost )
18
		pRemote_Host = SSrhost
19
	End Property
20
 
21
	Public Property Let Archive_Path( SSarch_path )
22
		pArchive_Path = UnixPath(SSarch_path)
23
	End Property
24
 
25
 
26
	'====================== Methods ======================
27
	'-----------------------------------------------------------------------------------------------------------------
28
	Private Sub Get_Archive_Telnet_Login_Details ( outUser, outPassword )
29
		outUser 		= "releasem"
30
		outPassword 	= "releasem"
31
	End Sub
32
	'-----------------------------------------------------------------------------------------------------------------
33
	Private Sub Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
41 brianf 34
		outUser 		= "vix\releasem"
27 rsolanki 35
		outPassword 	= "releasem"
36
	End Sub
37
	'-----------------------------------------------------------------------------------------------------------------
38
	Function UnixPath( SSpath )
39
		If SSpath <> "" Then UnixPath = Replace( SSpath, "\", "/" )
40
	End Function
41
    '-----------------------------------------------------------------------------------------------------------------
42
	Sub Ensure_Read_Write ( SSpkg_name, SSpkg_version )
43
		Dim outMachine, outUser, outPassword
44
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
45
		WScript.Echo "Allowing Read and Write on folder "& SSpkg_version 
46
 
47
		WScript.Echo "Error Before Command "& Err.Number		
48
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
49
 
50
		' Set all folders to +RWX and all files to +RW
51
		' --- Commands to run ---
52
		'command = _
53
		'"cd "& pArchive_Path &" && "&_
54
		'"chmod a+rwx "& SSpkg_name &"; "&_
55
		'"cd "& SSpkg_name &" && "&_
56
		'"find '"& SSpkg_version &"' -type d -exec chmod a+rwx {} \; ; "&_
57
		'"chmod -R a+rw "& SSpkg_version &"; "
58
 
59
		command = _
60
		"sudo ~/sbin/make_writable "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
61
 
62
		WScript.Echo command
63
 
64
		' --- SSH client with login details ---
65
		'login_details = APP_ROOT & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
66
		login_details = APP_ROOT & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
67
 
68
		WScript.Echo login_details 
69
 
70
		Set sysShell = WScript.CreateObject("WScript.Shell")
71
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
72
 
73
 
74
 
75
		'Set oExec = sysShell.Exec( login_details &" "& command )
76
		'Set oExec = sysShell.Exec(  login_details &" """& command &"""" )
77
 
78
		'outStrOut = oExec.StdOut.ReadAll
79
		'outStrErr = oExec.StdErr.ReadAll
80
 
81
		'If outStrErr <> "" Then
82
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Ensure_Read_Write]", _
83
		'					   "user: "& outUser & VBNewLine &_
84
		'					   "command: "& command , _
85
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
86
		'End If
87
		'Set oExec = Nothing
88
		Set sysShell = Nothing
89
 
90
	End Sub
91
	'-----------------------------------------------------------------------------------------------------------------	
92
	Sub All_Read_Only ( SSpkg_name, SSpkg_version )
93
		Dim outMachine, outUser, outPassword
94
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
95
 
96
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
97
 
98
		' Set all folders from version folder, to -W and all files to -W
99
		' --- Commands to run ---
100
		'command = _
101
		'"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
102
		'"find '"& SSpkg_version &"' -type d -exec chmod a-w {} \; ; "&_
103
		'"chmod -R a-w "& SSpkg_version &"; "&_
104
		'"chown -R root:other "& SSpkg_version &"; "
105
 
106
		command = _
107
		"sudo ~/sbin/make_readonly "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
108
 
109
		WScript.Echo command
110
 
111
		' --- SSH client with login details ---
112
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
113
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
114
 
115
 
116
 
117
		Set sysShell = WScript.CreateObject("WScript.Shell")
118
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
119
 
120
		'Set oExec = sysShell.Exec( login_details &" "& command )
121
 
122
		'outStrOut = oExec.StdOut.ReadAll
123
		'outStrErr = oExec.StdErr.ReadAll
124
 
125
		'If outStrErr <> "" Then
126
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:All_Read_Only]", _
127
		'					   "user: "& outUser & VBNewLine &_
128
		'					   "command: "& command , _
129
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
130
		'End If
131
 
132
		'Set oExec = Nothing
133
		Set sysShell = Nothing
134
 
135
	End Sub	
136
	'-----------------------------------------------------------------------------------------------------------------	
137
	Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )
138
		Dim outMachine, outDpkg_root, outUser, outPassword
139
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
140
 
141
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
142
 
143
		' --- Commands to run ---
144
		' Creates doc folder if required with rwx permissions for all
145
		command = _
146
		"cd "& pArchive_Path &"/"& SSpkg_name &"/"& SSpkg_version &" && "&_
147
		"mkdir -p -m a+rwx "& docFolder &"; "
148
 
149
		WScript.Echo command
150
 
151
		' --- SSH client with login details ---
152
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
153
		login_details = APP_ROOT & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
154
 
155
 
156
		Set sysShell = WScript.CreateObject("WScript.Shell")
157
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
158
 
159
		'Set oExec = sysShell.Exec( login_details &" """& command &"""" )
160
		'WScript.Echo "HERE:"& oExec
161
		'outStrOut = oExec.StdOut.ReadAll
162
		'outStrErr = oExec.StdErr.ReadAll
163
 
164
		'If outStrErr <> "" Then
165
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Doc_Folder]", _
166
		'					   "user: "& outUser & VBNewLine &_
167
		'					   "command: "& command , _
168
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
169
		'End If
170
 
171
		'Set oExec = Nothing
172
		Set sysShell = Nothing
173
	End Sub
174
    '-----------------------------------------------------------------------------------------------------------------	
175
	Sub Create_Pkg_Folder ( SSpkg_name, SSpkg_version )
176
		Dim outMachine, outDpkg_root, outUser, outPassword
177
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
178
 
179
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
180
 
181
		' --- Commands to run ---
182
		' Creates pkg_name and pkg_version folder if required with rwx permissions for all
183
		'command = _
184
		'"cd "& pArchive_Path &" && "&_
185
		'"mkdir -p -m a+rwx "& SSpkg_name &"; "&_
186
		'"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
187
		'"mkdir -p -m a+rwx "& SSpkg_version &"; "
188
 
189
		command = _
190
		"sudo ~/sbin/make_pkgfolder "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
191
 
192
		WScript.Echo command
193
 
194
		' --- SSH client with login details ---
195
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
196
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
197
 
198
		Set sysShell = WScript.CreateObject("WScript.Shell")
199
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
200
 
201
		'Set oExec = sysShell.Exec( login_details &" "& command )
202
 
203
		'outStrOut = oExec.StdOut.ReadAll
204
		'outStrErr = oExec.StdErr.ReadAll
205
 
206
		'If outStrErr <> "" Then
207
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Pkg_Folder]", _
208
		'					   "user: "& outUser & VBNewLine &_
209
		'					   "command: "& command , _
210
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
211
		'End If
212
 
213
		'Set oExec = Nothing
214
		Set sysShell = Nothing
215
	End Sub
216
	'-----------------------------------------------------------------------------------------------------------------
217
	Sub Map_Network_Drive ( SSunc, outMappedDrive )
218
		Dim outUser, outPassword
219
		Dim ValidDrivesARR, validDrive, UsedDrives
220
		Dim i, WshNetwork, oDrives, oFilesys, drv
221
		WScript.Echo "Mapping drive..."
222
 
223
		Call Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
224
 
225
		ValidDrivesARR = Array("E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")
226
		Set WshNetwork = WScript.CreateObject("WScript.Network")
227
		Set oDrives = WshNetwork.EnumNetworkDrives
228
 
229
		' Check for existing map
230
		outMappedDrive = ""			
231
		For i = 0 to oDrives.Count - 1 Step 2
232
			' Reuse network map if exists
233
        	If UCase(oDrives.Item(i+1)) = UCase(SSunc) Then
234
				outMappedDrive = oDrives.Item(i)
235
				Exit For
236
			End If
237
        Next
238
 
239
 
240
		If outMappedDrive = "" Then
241
			' Drive need to be mapped, hence map one.
242
 
243
			' Get all drive used drive letters.
244
			' NOTE: It will not display a drive if mapped but not connected.
245
			Set oFilesys = CreateObject("Scripting.FileSystemObject")
246
			Set oDrives = oFilesys.Drives
247
			For Each drv in oDrives
248
				UsedDrives = UsedDrives &"|"& drv.DriveLetter &":|"
249
			Next
250
 
251
			For Each validDrive In ValidDrivesARR
252
				If NOT InStr( UCase(UsedDrives), "|"& UCase(validDrive) &"|") > 0 Then
253
					' used this unused drive
254
					On Error Resume Next
255
 
256
					WshNetwork.MapNetworkDrive validDrive, SSunc, FALSE, outUser, outPassword
257
 
258
					Call ErrorCheck ( "[sub:Map_Network_Drive]", _
259
							   		  "used drives: "& UsedDrives & VBNewLine &_
260
							   		  "valid letters to pick from: "& Join( ValidDrivesARR, ",") & VBNewLine &_
261
							   		  "attempting to map: "& validDrive & VBNewLine &_
262
							   		  "UNC: "& SSunc & VBNewLine &_
263
							   		  "username: "& outUser )
264
 
265
					outMappedDrive = validDrive
266
					Exit For
267
				End If
268
			Next
269
 
270
		End If
271
 
272
		If outMappedDrive = "" Then
273
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Map_Network_Drive]", _
274
							   "used drives: "& UsedDrives & VBNewLine &_
275
							   "valid drives to pick from: "& Join( ValidDrivesARR, ",") , _
276
							   "Network drive is not mapped!", enum_RELEASE_NOTES_FAILED )
277
		End If
278
 
279
		WScript.Echo "Using network drive: "& outMappedDrive
280
 
281
		Set oDrives = Nothing
282
		Set WshNetwork = Nothing
283
	End Sub
284
    '-----------------------------------------------------------------------------------------------------------------
285
	Sub Make_Zip ( zip_name, path )
286
 
287
		Dim outMachine, outDpkg_root, outUser, outPassword
288
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
289
 
290
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
291
 
292
		command = _
293
		"sudo ~/sbin/make_zip "& zip_name &" """& path &""" ;"
294
 
295
		'WScript.Echo command
296
 
297
 
298
 
299
		' --- SSH client with login details ---
300
		'login_details = APP_ROOT & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
301
		login_details = APP_ROOT & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
302
 
303
 
304
 
305
		Set sysShell = WScript.CreateObject("WScript.Shell")
306
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, False
307
 
308
		Wscript.Echo "cmd.exe /c "& login_details &" """& command &""""
309
 
310
 
311
		'Set oExec = sysShell.Exec( login_details &" "& command )
312
 
313
 
314
		'outStrOut = oExec.StdOut.ReadAll
315
		'outStrErr = oExec.StdErr.ReadAll
316
 
317
		'If outStrErr <> "" Then
318
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Pkg_Folder]", _
319
		'					   "user: "& outUser & VBNewLine &_
320
		'					   "command: "& command , _
321
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
322
		'End If
323
 
324
		'Set oExec = Nothing
325
		Set sysShell = Nothing
326
	End Sub
327
	'-----------------------------------------------------------------------------------------------------------------
328
 
329
 
330
End Class
331