Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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