Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 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 )
34
		outUser 		= "erg\releasem"
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
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
48
 
49
		' Set all folders to +RWX and all files to +RW
50
		' --- Commands to run ---
51
		'command = _
52
		'"cd "& pArchive_Path &" && "&_
53
		'"chmod a+rwx "& SSpkg_name &"; "&_
54
		'"cd "& SSpkg_name &" && "&_
55
		'"find '"& SSpkg_version &"' -type d -exec chmod a+rwx {} \; ; "&_
56
		'"chmod -R a+rw "& SSpkg_version &"; "
57
 
58
		command = _
59
		"sudo ~/sbin/make_writable "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
60
 
61
		WScript.Echo command
62
 
63
		' --- SSH client with login details ---
64
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
65
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
66
 
67
		'WScript.Echo login_details &" """& command &""""
68
 
69
		Set sysShell = WScript.CreateObject("WScript.Shell")
70
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
71
 
72
 
73
 
74
		'Set oExec = sysShell.Exec( login_details &" "& command )
75
		'Set oExec = sysShell.Exec(  login_details &" """& command &"""" )
76
 
77
		'outStrOut = oExec.StdOut.ReadAll
78
		'outStrErr = oExec.StdErr.ReadAll
79
 
80
		'If outStrErr <> "" Then
81
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Ensure_Read_Write]", _
82
		'					   "user: "& outUser & VBNewLine &_
83
		'					   "command: "& command , _
84
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
85
		'End If
86
		'Set oExec = Nothing
87
		Set sysShell = Nothing
88
 
89
	End Sub
90
	'-----------------------------------------------------------------------------------------------------------------	
91
	Sub All_Read_Only ( SSpkg_name, SSpkg_version )
92
		Dim outMachine, outUser, outPassword
93
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
94
 
95
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
96
 
97
		' Set all folders from version folder, to -W and all files to -W
98
		' --- Commands to run ---
99
		'command = _
100
		'"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
101
		'"find '"& SSpkg_version &"' -type d -exec chmod a-w {} \; ; "&_
102
		'"chmod -R a-w "& SSpkg_version &"; "&_
103
		'"chown -R root:other "& SSpkg_version &"; "
104
 
105
		command = _
106
		"sudo ~/sbin/make_readonly "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
107
 
108
		WScript.Echo command
109
 
110
		' --- SSH client with login details ---
111
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
112
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
113
 
114
 
115
 
116
		Set sysShell = WScript.CreateObject("WScript.Shell")
117
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
118
 
119
		'Set oExec = sysShell.Exec( login_details &" "& command )
120
 
121
		'outStrOut = oExec.StdOut.ReadAll
122
		'outStrErr = oExec.StdErr.ReadAll
123
 
124
		'If outStrErr <> "" Then
125
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:All_Read_Only]", _
126
		'					   "user: "& outUser & VBNewLine &_
127
		'					   "command: "& command , _
128
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
129
		'End If
130
 
131
		'Set oExec = Nothing
132
		Set sysShell = Nothing
133
 
134
	End Sub	
135
	'-----------------------------------------------------------------------------------------------------------------	
136
	Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )
137
		Dim outMachine, outDpkg_root, outUser, outPassword
138
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
139
 
140
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
141
 
142
		' --- Commands to run ---
143
		' Creates doc folder if required with rwx permissions for all
144
		command = _
145
		"cd "& pArchive_Path &"/"& SSpkg_name &"/"& SSpkg_version &" && "&_
146
		"mkdir -p -m a+rwx "& docFolder &"; "
147
 
148
		WScript.Echo command
149
 
150
		' --- SSH client with login details ---
151
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
152
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
153
 
154
 
155
		Set sysShell = WScript.CreateObject("WScript.Shell")
156
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
157
 
158
		'Set oExec = sysShell.Exec( login_details &" """& command &"""" )
159
		'WScript.Echo "HERE:"& oExec
160
		'outStrOut = oExec.StdOut.ReadAll
161
		'outStrErr = oExec.StdErr.ReadAll
162
 
163
		'If outStrErr <> "" Then
164
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Doc_Folder]", _
165
		'					   "user: "& outUser & VBNewLine &_
166
		'					   "command: "& command , _
167
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
168
		'End If
169
 
170
		'Set oExec = Nothing
171
		Set sysShell = Nothing
172
	End Sub
173
    '-----------------------------------------------------------------------------------------------------------------	
174
	Sub Create_Pkg_Folder ( SSpkg_name, SSpkg_version )
175
		Dim outMachine, outDpkg_root, outUser, outPassword
176
		Dim login_details, command, sysShell, oExec, outStrOut, outStrErr
177
 
178
		Call Get_Archive_Telnet_Login_Details ( outUser, outPassword )
179
 
180
		' --- Commands to run ---
181
		' Creates pkg_name and pkg_version folder if required with rwx permissions for all
182
		'command = _
183
		'"cd "& pArchive_Path &" && "&_
184
		'"mkdir -p -m a+rwx "& SSpkg_name &"; "&_
185
		'"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_
186
		'"mkdir -p -m a+rwx "& SSpkg_version &"; "
187
 
188
		command = _
189
		"sudo ~/sbin/make_pkgfolder "& pArchive_Path &" '"& SSpkg_name &"' '"& SSpkg_version &"';"
190
 
191
		WScript.Echo command
192
 
193
		' --- SSH client with login details ---
194
		'login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPassword 
195
		login_details = AppPath & WINRSH_EXE &" -q -h "& pRemote_Host &" -l "& outUser &" -p "& outPassword 
196
 
197
		Set sysShell = WScript.CreateObject("WScript.Shell")
198
		sysShell.Run "cmd.exe /c "& login_details &" """& command &"""", 0, True
199
 
200
		'Set oExec = sysShell.Exec( login_details &" "& command )
201
 
202
		'outStrOut = oExec.StdOut.ReadAll
203
		'outStrErr = oExec.StdErr.ReadAll
204
 
205
		'If outStrErr <> "" Then
206
		'	Call Raise_Event ( enumEVENT_ERROR, "[sub:Create_Pkg_Folder]", _
207
		'					   "user: "& outUser & VBNewLine &_
208
		'					   "command: "& command , _
209
		'					   outStrErr, enum_RELEASE_NOTES_FAILED )
210
		'End If
211
 
212
		'Set oExec = Nothing
213
		Set sysShell = Nothing
214
	End Sub
215
	'-----------------------------------------------------------------------------------------------------------------
216
	Sub Map_Network_Drive ( SSunc, outMappedDrive )
217
		Dim outUser, outPassword
218
		Dim ValidDrivesARR, validDrive, UsedDrives
219
		Dim i, WshNetwork, oDrives, oFilesys, drv
220
		WScript.Echo "Mapping drive..."
221
 
222
		Call Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )
223
 
224
		ValidDrivesARR = Array("E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")
225
		Set WshNetwork = WScript.CreateObject("WScript.Network")
226
		Set oDrives = WshNetwork.EnumNetworkDrives
227
 
228
		' Check for existing map
229
		outMappedDrive = ""			
230
		For i = 0 to oDrives.Count - 1 Step 2
231
			' Reuse network map if exists
232
        	If UCase(oDrives.Item(i+1)) = UCase(SSunc) Then
233
				outMappedDrive = oDrives.Item(i)
234
				Exit For
235
			End If
236
        Next
237
 
238
 
239
		If outMappedDrive = "" Then
240
			' Drive need to be mapped, hence map one.
241
 
242
			' Get all drive used drive letters.
243
			' NOTE: It will not display a drive if mapped but not connected.
244
			Set oFilesys = CreateObject("Scripting.FileSystemObject")
245
			Set oDrives = oFilesys.Drives
246
			For Each drv in oDrives
247
				UsedDrives = UsedDrives &"|"& drv.DriveLetter &":|"
248
			Next
249
 
250
			For Each validDrive In ValidDrivesARR
251
				If NOT InStr( UCase(UsedDrives), "|"& UCase(validDrive) &"|") > 0 Then
252
					' used this unused drive
253
					On Error Resume Next
254
 
255
					WshNetwork.MapNetworkDrive validDrive, SSunc, FALSE, outUser, outPassword
256
 
257
					Call ErrorCheck ( "[sub:Map_Network_Drive]", _
258
							   		  "used drives: "& UsedDrives & VBNewLine &_
259
							   		  "valid letters to pick from: "& Join( ValidDrivesARR, ",") & VBNewLine &_
260
							   		  "attempting to map: "& validDrive & VBNewLine &_
261
							   		  "UNC: "& SSunc & VBNewLine &_
262
							   		  "username: "& outUser )
263
 
264
					outMappedDrive = validDrive
265
					Exit For
266
				End If
267
			Next
268
 
269
		End If
270
 
271
		If outMappedDrive = "" Then
272
			Call Raise_Event ( enumEVENT_ERROR, "[sub:Map_Network_Drive]", _
273
							   "used drives: "& UsedDrives & VBNewLine &_
274
							   "valid drives to pick from: "& Join( ValidDrivesARR, ",") , _
275
							   "Network drive is not mapped!", enum_RELEASE_NOTES_FAILED )
276
		End If
277
 
278
		WScript.Echo "Using network drive: "& outMappedDrive
279
 
280
		Set oDrives = Nothing
281
		Set WshNetwork = Nothing
282
	End Sub
283
    '-----------------------------------------------------------------------------------------------------------------
284
 
285
End Class
286