source: cprs/branches/tmg-cprs/m_files/TMGPAT2.m@ 1705

Last change on this file since 1705 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 31.3 KB
Line 
1TMGPAT2 ;TMG/kst/Patching tools Suport;09/17/08
2 ;;1.0;TMG-LIB;**1**;09/17/08
3 ;
4 ;"Kevin Toppenberg MD
5 ;"GNU General Public License (GPL) applies
6 ;"9/17/08
7
8 ;"=======================================================================
9 ;" API -- Public Functions.
10 ;"=======================================================================
11 ;"MAKFRESH(PckInit,Msg,PckDirFName) --ensure that the Package list of files avilable on server is fresh
12 ;"RefreshPackge(PckInit,.Msg,NeedsRefresh,PckDirFName) -- query server for one package, and refresh info stored in TMG REMOTE PATCH SOURCE file
13 ;"GetNextIENS(LastPatch,NextPatchName) -- return IENS in file TMG REMOTE PATCH SOURCE (22709)
14 ;"GetIENS(PatchName) -- Given patch name, return IENS in file TMG REMOTE PATCH SOURCE (22709)
15 ;"GetIENS2(PatchName) -- Given partial patch name, return IENS in file 22709.01
16 ;"FORCEPAT -- All user to enter a patch entry
17 ;"IsInstalled(PatchName) -- return if a given patch has already been installed.
18 ;"ParsePatchName(PatchName,PckInit,Ver,PatchNum,SeqNum) -- parse a patch name into it's composit parts.
19 ;"EnsureLocal(IENS,Info,Msg,Option) -- Ensure files downloaded from server and stored locally
20 ;"DownloadPatch(PatchName,protocol,Option,Msg,Info) -- Ensure that the Patch has been downloaded from server and stored locally
21 ;"MakePatchEntry(PatchName,Msg) -- make pseudo-entries to show that something was processed.
22 ;"AddMsg(s,IsError,Msg) -- add a message to Msg Array
23 ;"ShowMsg(Msg) -- display the message array
24
25 ;"=======================================================================
26 ;"Private Functions
27 ;"=======================================================================
28 ;"EmptyPackage(IEN9d4,Msg) - delete info for Package in file TMG REMOTE PATCH SOURCE
29 ;"LoadPackage(IEN9d4,Array,protocol,Msg,SomeAdded) -- load info for Package info file TMG REMOTE PATCH SOURCE
30 ;"LoadOne(PckIEN,Ver,PatchNum,SeqNum,RemoteURL,Msg) -- file one entry info TMG REMOTE PATCH SOURCE
31
32 ;"=======================================================================
33 ;"=======================================================================
34
35MAKFRESH(PckInit,Msg,PckDirFName)
36 ;"Purpose: to ensure that the Package list of files avilable on server is fresh
37 ;"Input: PckInit -- this is the namespace of the package to get patches for, e.g. 'DI' for fileman
38 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
39 ;" Errors are stored in Msg("ERROR",x)=Message
40 ;" Msg("ERROR")=count of last error
41 ;" Message are store in Msg(x)=Message
42 ;" Msg=count of last message+1
43 ;" PckDirFName -- Optional. PASS BY REFERNCE, an OUT PARAMETER. Filled with HFS filename of file
44 ;"Results: none
45
46 new IEN9d4 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,""))
47 if IEN9d4'>0 do goto ENSFDone
48 . do AddMsg("Can't find PACKAGE named '"_PckInit_"'",1,.Msg)
49 new PckIEN,lastFMDate
50 set PckIEN=+$order(^TMG(22709,"B",IEN9d4,""))
51 if PckIEN>0 set lastFMDate=$piece($get(^TMG(22709,PckIEN,2)),"^",1)
52 else set lastFMDate=""
53 new %,X,X1,X2,NeedsRefresh
54 set NeedsRefresh=0
55 if lastFMDate'="" do
56 . do NOW^%DTC ;"returns date in X
57 . set X1=lastFMDate,X2=X
58 . do ^%DTC
59 . if X>7 set NeedsRefresh=1 ;"hard code in fresh if > 7 days since last scan.
60 else set NeedsRefresh=1
61 if $$RefreshPackge(PckInit,.Msg,NeedsRefresh,.PckDirFName)
62ENSFDone
63 quit
64
65RefreshPackge(PckInit,Msg,NeedsRefresh,PckDirFName,Option)
66 ;"Purpose: To query server for one package, and refresh info stored in TMG REMOTE PATCH SOURCE file
67 ;"Input: PckInit -- this is the namespace of the package to get patches for, e.g. 'DI' for fileman
68 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
69 ;" Errors are stored in Msg("ERROR",x)=Message
70 ;" Msg("ERROR")=count of last error
71 ;" Message are store in Msg(x)=Message
72 ;" Msg=count of last message+1
73 ;" NeedsRefresh -- 0 if refreshing not needed (just return PckDirFName, but ensure file exists)
74 ;" PckDirFName -- Optional. PASS BY REFERANCE, an OUT PARAMETER. Filled with HFS filename of file
75 ;" Option -- Optional. PASS BY REFERANCE.
76 ;" Option("VERBOSE")=1 puts out text to console. (1 is default value)
77 ;"Result : 1=success, 0=failure
78
79 new Array,result
80 new verbose set verbose=+$get(Option("VERBOSE"),1)
81 set NeedsRefresh=+$get(NeedsRefresh)
82 if NeedsRefresh,verbose write "Fetching list of available "_PckInit_" patches from VA ftp server..."
83 set result=$$GetPckList^TMGKERNL(PckInit,.Array,.NeedsRefresh,.PckDirFName)
84 if NeedsRefresh,verbose write " Done.",!
85 if $get(NeedsRefresh)'>0 goto RPDone
86 if result=0 goto RPDone
87 new IEN9d4 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,""))
88 if IEN9d4'>0 do goto RPDone
89 . do AddMsg("Can't find PACKAGE named '"_PckInit_"'",1,.Msg)
90 new SomeAdded
91 set result=$$LoadPackage(IEN9d4,.Array,"ftp://",.Msg,.SomeAdded)
92RPDone
93 quit result
94
95
96EmptyPackage(IEN9d4,Msg)
97 ;"Purpose: to delete info for Package in file TMG REMOTE PATCH SOURCE
98 ;"Input: IEN9d4 -- IEN in 9.4 to get patches for
99 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
100 ;" Errors are stored in Msg("ERROR",x)=Message
101 ;" Msg("ERROR")=count of last error
102 ;" Message are store in Msg(x)=Message
103 ;" Msg=count of last message+1
104
105 new PckIEN set PckIEN=+$order(^TMG(22709,"B",IEN9d4,""))
106 if PckIEN=0 goto EPDone
107 new TMGFDA,TMGMSG
108 set TMGFDA(22709,PckIEN_",",.01)="@"
109 do FILE^DIE("EK","TMGFDA","TMGMSG")
110 if $data(TMGMSG("DIERR")) do
111 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
112
113EPDone quit
114
115
116LoadPackage(IEN9d4,Array,protocol,Msg,SomeAdded)
117 ;"Purpose: to load info for Package info file TMG REMOTE PATCH SOURCE
118 ;"Input: IEN9d4 -- IEN in 9.4 to get patches for
119 ;" Array -- This is file with available filepaths, as returned from GetPckList
120 ;" protocol -- OPTIONAL. Default is 'ftp://'
121 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
122 ;" Errors are stored in Msg("ERROR",x)=Message
123 ;" Msg("ERROR")=count of last error
124 ;" Message are store in Msg(x)=Message
125 ;" Msg=count of last message+1
126 ;" SomeAdded -- PASS BY REFERENCE, an OUT PARAMETER
127 ;" set to 1 if some added, otherwise 0
128 ;"Result : 2=patch added, 1=no problems, 0=failure or error occured
129
130 new result set result=1
131 set SomeAdded=0
132 set protocol=$get(protocol,"ftp://")
133 set IEN9d4=+$get(IEN9d4)
134 if IEN9d4'>0 do goto LPDone
135 . do AddMsg("Can't find record #"_IEN9d4_" in INSTALL file.",1,.Msg)
136 new PckIEN set PckIEN=+$order(^TMG(22709,"B",IEN9d4,""))
137 new TMGFDA,TMGMSG,TMGIEN,X,%
138 do NOW^%DTC ;"output in %
139 if PckIEN>0 do
140 . set TMGFDA(22709,PckIEN_",",2)=%
141 . do FILE^DIE("K","TMGFDA","TMGMSG")
142 else do
143 . set TMGFDA(22709,"+1,",.01)=IEN9d4
144 . set TMGFDA(22709,"+1,",2)=% ;"the time downloaded
145 . do UPDATE^DIE("K","TMGFDA","TMGIEN","TMGMSG")
146 . set PckIEN=$get(TMGIEN(1))
147 if $data(TMGMSG("DIERR")) do
148 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
149 if PckIEN'>0 goto LPDone
150
151 new i set i=0 ;"skip first line, a header line
152 for set i=$order(Array(i)) quit:(i="") do
153 . new Name,Path,FullNamePath,Ver,PatchNum,SeqNum
154 . set FullNamePath=$get(Array(i)) quit:FullNamePath=""
155 . do SplitFNamePath^TMGIOUTL(FullNamePath,.Path,.Name,"/")
156 . if (Path="")!(Name="") quit
157 . new UName set UName=$$UP^XLFSTR(Name)
158 . if UName?2.4A1"_"1.4N1"_"0.1"P"1.N1".KID" do ;"e.g. DG_53_P481.KID or EAS_1_47.KID
159 . . set Ver=$piece($piece(Name,"_",2),"_",1)
160 . . new verIEN set verIEN=+$order(^TMG(22709,PckIEN,1,"C",Ver,""))
161 . . if verIEN=0 set Ver="" quit
162 . . set Ver=$piece($get(^TMG(22709,PckIEN,1,verIEN,0)),"^",1)
163 . . if Ver="" quit
164 . . set PatchNum=$piece($piece(Name,"_",3),".",1)
165 . . if PatchNum?1A.N set PatchNum=$extract(PatchNum,2,99)
166 . . set SeqNum="" ;"signal for no seq number provided
167 . else do
168 . . set Ver=$piece($piece(Name,"_",1),"-",2) quit:(Ver="")
169 . . if Ver?.N1(1"p",1"P").N set Ver=$translate(Ver,"Pp","..")
170 . . set SeqNum=$piece($piece(Name,"_",2),"-",2) quit:(SeqNum="")
171 . . set PatchNum=$piece($piece(Name,"_",3),"-",2) quit:(PatchNum="")
172 . . set PatchNum=$piece(PatchNum,".",1) quit:(PatchNum="")
173 . if Ver="" do quit
174 . . do AddMsg("Unable to process file name: "_Name_". Couldn't determine version number.",1,.Msg)
175 . ;"if SeqNum="" do quit ;Removed because sometimes the sequence # comes from the TXT file, not the patch file.
176 . ;". do AddMsg("Unable to process file name: "_Name_". Couldn't determine sequence number.",1,.Msg)
177 . if PatchNum="" do quit
178 . . do AddMsg("Unable to process file name: "_Name_". Couldn't determine patch number.",1,.Msg)
179 . new tempResult
180 . set tempResult=$$LoadOne(PckIEN,Ver,PatchNum,SeqNum,protocol_FullNamePath)
181 . if tempResult=2 set SomeAdded=1
182
183LPDone
184 quit result
185
186
187LoadOne(PckIEN,Ver,PatchNum,SeqNum,RemoteURL,Msg)
188 ;"Purpose: to file one entry info TMG REMOTE PATCH SOURCE
189 ;" This doesn't actually get the file from the server, just store
190 ;" the directory info, for later retrieval
191 ;"Input: PckIEN -- the IEN in TMG REMOTE PATCH SOURCE for Package
192 ;" Ver -- the version of the patch
193 ;" PatchNum -- the patch number
194 ;" SeqNum -- the patch sequence number (the release sequence number) (if provided)
195 ;" RemoteURL -- The protocol_remoteURL of the patch on the server
196 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
197 ;" Errors are stored in Msg("ERROR",x)=Message
198 ;" Msg("ERROR")=count of last error
199 ;" Message are store in Msg(x)=Message
200 ;" Msg=count of last message+1
201 ;"Result : 1=success, 0=failure
202
203 new result set result=0 ;"default to failure
204 set PckIEN=+$get(PckIEN) if PckIEN'>0 goto LODone
205 set Ver=$get(Ver) if Ver="" goto LODone
206 if Ver'["." set Ver=Ver_".0"
207 set PatchNum=$get(PatchNum) if PatchNum="" goto LODone
208 set SeqNum=$get(SeqNum) ;"OK if no sequence number
209 new VerIEN set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",Ver,""))
210 if VerIEN'>0 do
211 . new TMGFDA,TMGIEN,TMGMSG
212 . set TMGFDA(22709.01,"+1,"_PckIEN_",",".01")=Ver
213 . set TMGFDA(22709.01,"+1,"_PckIEN_",",".02")=$translate(Ver,".","") ;"synonym
214 . do UPDATE^DIE("","TMGFDA","TMGIEN","TMGMSG")
215 . if $data(TMGMSG("DIERR")) do
216 . . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
217 . set VerIEN=+$get(TMGIEN(1))
218 if VerIEN'>0 goto LODone
219 new patchIEN set patchIEN=+$order(^TMG(22709,PckIEN,1,VerIEN,1,"B",PatchNum,""))
220 if patchIEN'>0 do
221 . new TMGFDA,TMGIEN,TMGMSG
222 . set TMGFDA(22709.11,"+1,"_VerIEN_","_PckIEN_",",".01")=PatchNum
223 . do UPDATE^DIE("","TMGFDA","TMGIEN","TMGMSG")
224 . if $data(TMGMSG("DIERR")) do
225 . . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
226 . set patchIEN=+$get(TMGIEN(1))
227 . set result=2 ;"something added
228 if patchIEN'>0 goto LODone
229 new TMGFDA,TMGMSG
230 new Ext set Ext=$piece(RemoteURL,".",$length(RemoteURL,"."))
231
232 new spec
233 set spec("'")="'\''",spec("*")="'\*'",spec("&")="'\&'",spec("?")="'\?'"
234 set spec("\ ")=" "
235 set RemoteURL=$$REPLACE^XLFSTR(RemoteURL,.spec)
236
237 new field
238 if $$UP^XLFSTR(Ext)="TXT" set field=1.5
239 else set field=1
240 set TMGFDA(22709.11,patchIEN_","_VerIEN_","_PckIEN_",",field)=RemoteURL
241 if SeqNum'="" set TMGFDA(22709.11,patchIEN_","_VerIEN_","_PckIEN_",",".02")=SeqNum
242 do FILE^DIE("K","TMGFDA","TMGMSG")
243 if $data(TMGMSG("DIERR")) do
244 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
245 if $data(TMGMSG("DIERR"))=0 do
246 . if result>0 quit
247 . set result=1 ;"success
248LODone
249 quit result
250
251
252GetNextIENS(LastPatch,NextPatchName)
253 ;"Purpose: Given last patch name, return IENS in file TMG REMOTE PATCH SOURCE (22709)
254 ;" that points to record with information about next appropriate patch.
255 ;"Input: LastPatch -- expected Format: e.g. DI*22.0*100 SEQ #123
256 ;" NextPatchName -- PASS BY REFERENCE, an OUT PARAMETER
257 ;" Will be filled with name of next patch.
258 ;"Output: returns IENS to record in 22709.11, or "" if problem.
259
260 new result set result=""
261 set NextPatchName=""
262 if $get(LastPatch)="" goto GNPDone
263
264 new seqNum,PckInit,Ver,PatchNum,seqNum
265 do ParsePatchName(LastPatch,.PckInit,.Ver,.PatchNum,.seqNum)
266 if seqNum="" goto GNPDone
267
268 new IEN9d4 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,""))
269 if IEN9d4'>0 goto GNPDone
270 new PckIEN set PckIEN=+$order(^TMG(22709,"B",IEN9d4,""))
271 if PckIEN'>0 goto GNPDone
272 new VerIEN set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",Ver,""))
273 if VerIEN'>0 set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",$piece(Ver,".0",1),""))
274 if VerIEN'>0 goto GNPDone
275
276 new patchIEN,nextSeq
277 set nextSeq=+$order(^TMG(22709,PckIEN,VerIEN,"SEQ",seqNum))
278 if nextSeq'>0 goto GNPDone
279 set patchIEN=+$order(^TMG(22709,PckIEN,VerIEN,"SEQ",nextSeq,""))
280 if patchIEN'>0 goto GNPDone
281 set result=patchIEN_","_VerIEN_","_PckIEN_","
282 set NextPatchName=$piece(LastPatch," ",1)
283 new node0 set node0=$get(^TMG(22709,PckIEN,1,VerIEN,1,patchIEN,0))
284 new nextPatchNum set nextPatchNum=$piece(node0,"^",1)
285 set $piece(NextPatchName,"*",3)=nextPatchNum
286 set NextPatchName=NextPatchName_" SEQ #"_nextSeq
287
288GNPDone
289 quit result
290
291
292GetIENS(PatchName)
293 ;"Purpose: Given patch name, return IENS in file TMG REMOTE PATCH SOURCE (22709)
294 ;"Input: PatchName -- expected Format: e.g. DI*22.0*100 SEQ #123
295 ;"Output: returns IENS to record in 22709.11, or "" if problem.
296
297 new result set result=""
298 if $get(PatchName)="" goto GIDone
299 new seqNum,PckInit,Ver,PatchNum,seqNum
300 new IEN9d4,PckIEN,VerIEN,patchIEN
301 do ParsePatchName(PatchName,.PckInit,.Ver,.PatchNum,.seqNum) goto:(seqNum="") GIDone
302 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,"")) goto:(IEN9d4'>0) GIDone
303 set PckIEN=+$order(^TMG(22709,"B",IEN9d4,"")) goto:(PckIEN'>0) GIDone
304 set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",Ver,""))
305 if VerIEN'>0 set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",$piece(Ver,".0",1),""))
306 if VerIEN'>0 goto GIDone
307 set patchIEN=+$order(^TMG(22709,PckIEN,VerIEN,"SEQ",seqNum,"")) goto:(patchIEN'>0) GIDone
308 set result=patchIEN_","_VerIEN_","_PckIEN_","
309GIDone
310 quit result
311
312
313GetIENS2(PatchName)
314 ;"Purpose: Given partial patch name, return IENS in file 22709.01
315 ;" (i.e. just patch*ver)
316 ;"Input: PatchName -- expected Format: e.g. DI*22.0*.... or DI*22.0
317 ;"Output: returns IENS to record in 22709.01, or "" if problem.
318
319 new result set result=""
320 if $get(PatchName)="" goto GI2Done
321 new seqNum,PckInit,Ver,PatchNum,seqNum
322 new IEN9d4,PckIEN,VerIEN,patchIEN
323 do ParsePatchName(PatchName,.PckInit,.Ver,.PatchNum,.seqNum)
324 if (PckInit="")!(Ver="") goto GI2Done
325 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,"")) goto:(IEN9d4'>0) GI2Done
326 set PckIEN=+$order(^TMG(22709,"B",IEN9d4,"")) goto:(PckIEN'>0) GI2Done
327 set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",Ver,""))
328 if VerIEN'>0 set VerIEN=+$order(^TMG(22709,PckIEN,1,"B",$piece(Ver,".0",1),""))
329 if VerIEN'>0 goto GI2Done
330 set result=VerIEN_","_PckIEN_","
331GI2Done
332 quit result
333
334
335EnsureLocal(IENS,Info,Msg,Option)
336 ;"Purpose: Ensure that the files have been downloaded from server and stored locally
337 ;"Input: IENS -- IENS in 22709.11
338 ;" Info -- PASS BY REFERENCE, an OUT PARAMETER.
339 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
340 ;" Errors are stored in Msg("ERROR",x)=Message
341 ;" Msg("ERROR")=count of last error
342 ;" Message are store in Msg(x)=Message
343 ;" Msg=count of last message+1
344 ;" Option -- optional. Pass by reference.
345 ;" Option("VERBOSE")=1, means messaages also written directly to output
346 ;"Output: Info will be filled as follows:
347 ;" Info("PATH")=Path in HFS
348 ;" Info("KID FILE")=HFS filename of .KID patch
349 ;" Info("TEXT FILE")=HFS filename of .TXT accompanying patch
350 ;" Info("TEXT ONLY")=1 if there is a text file, but no .KIDS file
351 ;" Info("KID URL")=URL on server for KID file
352 ;" Info("TEXT URL")=URL on server for TXT file
353 ;"results: 1 if OK, 0 if problem.
354
355 new TMGMSG,TMGDATA,TMGFDA
356 new verbose set verbose=$get(Option("VERBOSE"))
357 new result set result=1 ;"default to success
358 kill Info
359 if $get(IENS)="" goto ELDone
360 do GETS^DIQ(22709.11,IENS,"1;1.5;2;3;4","","TMGDATA","TMGMSG")
361 if $data(TMGMSG("DIERR")) do goto ELDone
362 . new tempS set tempS=$$GetErrStr^TMGDEBUG(.TMGMSG)
363 . do AddMsg(tempS,1,.Msg)
364 . if verbose write tempS,!
365 new URL set URL=$get(TMGDATA(22709.11,IENS,1))
366 set Info("KID URL")=URL
367 new textURL set textURL=$get(TMGDATA(22709.11,IENS,1.5))
368 set Info("TEXT URL")=textURL
369 if URL="" do
370 . if textURL'="" set Info("TEXT ONLY")=1 quit
371 . new tempS set tempS="No URL found for KIDS patch or accompanying Info text file in FM File #22709.22, IENS="_IENS
372 . do AddMsg(tempS,1,.Msg)
373 . if verbose write tempS,!
374
375 new Path set Path=$get(TMGDATA(22709.11,IENS,2))
376 if Path="" do
377 . set Path=$get(^TMG("KIDS","PATCH DIR"),"/tmp/")
378 . set TMGFDA(22709.11,IENS,2)=Path
379 set Info("PATH")=Path
380 new Filename set Filename=$get(TMGDATA(22709.11,IENS,3))
381 new textFilename set textFilename=$get(TMGDATA(22709.11,IENS,4))
382
383 if (Filename'=""),$$FileExists^TMGIOUTL(Path_Filename) do
384 . set Info("KID FILE")=Filename
385 else if (URL'="") do
386 . if verbose write "Downloading KID file from FTP.VA.GOV..."
387 . if $$DownloadFile^TMGKERNL(URL,Path)
388 . set Filename=$$FNameExtract^TMGIOUTL(URL)
389 . if $$FileExists^TMGIOUTL(Path_Filename) do
390 . . if $$Dos2Unix^TMGKERNL(Path_Filename)
391 . . set TMGFDA(22709.11,IENS,3)=Filename
392 . . set Info("KID FILE")=Filename
393 . else set result=0
394 . if verbose write !
395
396 if (textFilename'=""),$$FileExists^TMGIOUTL(Path_textFilename) do
397 . set Info("TEXT FILE")=textFilename
398 else if (textURL'="") do
399 . if verbose write "Downloading TEXT file from FTP.VA.GOV..."
400 . if $$DownloadFile^TMGKERNL(textURL,Path)
401 . set textFilename=$$FNameExtract^TMGIOUTL(textURL)
402 . if $$FileExists^TMGIOUTL(Path_textFilename) do
403 . . set TMGFDA(22709.11,IENS,4)=textFilename
404 . . set Info("TEXT FILE")=textFilename
405 . set result=0
406 . if verbose write !
407
408 set result=1 ;"success
409ELDone
410 kill TMGMSG
411 if $data(TMGFDA) do
412 . do FILE^DIE("","TMGFDA","TMGMSG")
413 . if $data(TMGMSG("DIERR")) do
414 . . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
415 . . set result=0
416 . . if verbose write Msg("ERROR",MsgI),!
417
418 quit result
419
420
421DownloadPatch(PatchName,protocol,Option,Msg,Info)
422 ;"Purpose: Ensure that the Patch has been downloaded from server and stored locally
423 ;"Input: PatchName -- the name of the patch to get, e.g. ABC*12.34*1234 [SEQ #123]
424 ;" protocol -- OPTIONAL. Default is 'ftp://'
425 ;" Option -- optional. Pass by reference.
426 ;" Option("VERBOSE")=1, means messaages also written directly to output
427 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
428 ;" Errors are stored in Msg("ERROR",x)=Message
429 ;" Msg("ERROR")=count of last error
430 ;" Message are store in Msg(x)=Message
431 ;" Msg=count of last message+1
432 ;" Info -- PASS BY REFERENCE, an IN and OUT PARAMETER.
433 ;" Info("PATH")=Path in HFS
434 ;" Info("KID FILE")=HFS filename of .KID patch
435 ;" Info("TEXT FILE")=HFS filename of .TXT accompanying patch
436 ;" Info("TEXT ONLY")=1 if there is a text file, but no .KIDS file
437 ;" Info("KID URL")=URL on server for KID file
438 ;" Info("TEXT URL")=URL on server for TXT file
439 ;"Output: Info will be filled as follows:
440 ;" Info("PATH")=Path in HFS
441 ;" Info("KID FILE")=HFS filename of .KID patch
442 ;"results: 1 if OK, 0 if problem.
443
444 new result set result=1
445 new seqNum,PckInit,Ver,PatchNum,seqNum,PckDirFName,URL
446 new verbose set verbose=($get(Option("VERBOSE"))=1)
447 set protocol=$get(protocol,"ftp://")
448 if PatchName?2.4N1"*"1.3N.(1"."1.4N)1"*"1.4N do
449 . do ParsePatchName(PatchName,.PckInit,.Ver,.PatchNum,.seqNum)
450 else if PatchName?1.4A1"_".E do
451 . set PckInit=$piece(PatchName,"_",1)
452 else do goto:(result=0) DLPDone
453 . new tempName set tempName=$get(Info("TEXT FILE"))
454 . if tempName="" set result=0 quit
455 . if tempName?1.4A1"_".E do
456 . . set PckInit=$piece(tempName,"_",1)
457 . else if tempName?1.4A1"-".E do
458 . . set PckInit=$piece(tempName,"-",1)
459 . if $get(PckInit)="" set result=0
460
461 set result=$$RefreshPackge(PckInit,.Msg,0,.PckDirFName) goto:(result=0) DLPDone
462 set result=$$FindMultPatch^TMGPAT4(PatchName,PckInit,.Option,.URL,.Info) goto:(result=0) DLPDone
463
464 new Filename,Path
465 set Path=$get(^TMG("KIDS","PATCH DIR"),"/tmp/")
466 set Info("PATH")=Path
467 set Filename=$$FNameExtract^TMGIOUTL(URL)
468 if $$FileExists^TMGIOUTL(Path_Filename) goto DLPDone
469 if verbose write "Downloading "_Filename_" from FTP.VA.GOV...",!
470 new spec set spec("\ ")="%20"
471 set URL=$$REPLACE^XLFSTR(URL,.spec)
472 if $$DownloadFile^TMGKERNL(protocol_URL,Path,0)
473 if $$FileExists^TMGIOUTL(Path_Filename)=0 set result=0 goto DLPDone
474 if $$Dos2Unix^TMGKERNL(Path_Filename)
475 set Info("KID FILE")=Filename
476DLPDone
477 quit result
478
479FORCEPAT
480 ;"Purpose: All user to enter a patch entry
481
482 new PckInit,Ver,DIR,PatchNum,SeqNum,NewPatch
483 do GetPckVer^TMGPAT1(.PckInit,.Ver)
484 set DIR(0)="N",DIR("A")="Enter PATCH NUMBER"
485 do ^DIR write !
486 set PatchNum=Y
487 if $get(DIRUT) goto FPDone
488 set DIR(0)="N",DIR("A")="Enter SEQUENCE NUMBER"
489 do ^DIR write !
490 set SeqNum=Y
491 if $get(DIRUT) goto FPDone
492 do ForceP2(.PckInit,.Ver,.PatchNum,.SeqNum)
493 quit
494
495ForceP2(PckInit,Ver,PatchNum,SeqNum)
496 ;"Purpose: Hack write a patch into Package file, based in componant parts.
497 ;"Results: None
498
499 new NewPatch set NewPatch=PckInit_"*"_Ver_"*"_PatchNum_" SEQ #"_SeqNum
500 new DIR set DIR(0)="Y"
501 set DIR("A")="HACK/FORCE an entry in the Package file for: "_NewPatch_" (Y/N)"
502 do ^DIR write !
503 if $get(DIRUT)!(Y'=1) goto FPDone
504 new Msg
505 if $$MakePatchEntry^TMGPAT2(NewPatch,.Msg)
506 if $$ShowMsg^TMGPAT2(.Msg)
507FPDone
508 quit
509
510
511MakePatchEntry(PatchName,Msg)
512 ;"Purpose: For times when a patch was informational only, and there was
513 ;" no KIDS file to actually install, then this can make pseudo-entries
514 ;" to show that something was processed.
515 ;"Input: PatchName -- The name of the patch. Eg: DI*22*123 SEQ #456"
516 ;" Msg -- PASS BY REFERANCE, an OUT PARAMETER
517 ;" Errors are stored in Msg("ERROR",x)=Message
518 ;" Msg("ERROR")=count of last error
519 ;" Message are store in Msg(x)=Message
520 ;" Msg=count of last message+1
521
522 ;"Results: 1 if OK, 0 if error
523
524 new %,X,result
525 new TMGMSG,TMGFDA,TMGIEN
526 set result=1
527 new justPatch set justPatch=$piece(PatchName," SEQ",1)
528 new tempIEN set tempIEN=+$order(^XPD(9.7,"B",justPatch,""))
529 if tempIEN>0 goto MPE2 ;"INSTALL entry already made
530
531 do NOW^%DTC
532 set TMGFDA(9.7,"+1,",.01)=justPatch
533 set TMGFDA(9.7,"+1,",.02)=3 ;"2 = status
534 set TMGFDA(9.7,"+1,",6)="Text_Only "_PatchName ;"6 = file comment
535 set TMGFDA(9.7,"+1,",9)=DUZ ;"9 = Installed by
536 set TMGFDA(9.7,"+1,",11)=% ;"11 = Install start time
537 set TMGFDA(9.7,"+1,",17)=% ;"17 = Install completion time
538 do UPDATE^DIE("","TMGFDA","TMGIEN","TMGMSG")
539 if $data(TMGMSG("DIERR")) do
540 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
541 . set result=0
542
543MPE2 set PckInit=$piece(PatchName,"*",1)
544 set Ver=$piece(PatchName,"*",2)
545 if (PckInit="")!(Ver="") set result=0 goto MPEDone
546 new IEN9d4,IEN9d49
547 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,""))
548 if IEN9d4'>0 set result=0 goto MPEDone
549 set IEN9d49=+$order(^DIC(9.4,IEN9d4,22,"B",Ver,""))
550 if IEN9d49'>0 set result=0 goto MPEDone
551
552 new PatchSeq set PatchSeq=$piece(PatchName,"*",3)
553 set tempIEN=$order(^DIC(9.4,IEN9d4,22,IEN9d49,"PAH","B",PatchSeq,""))
554 if tempIEN>0 do goto MPE3
555 . set TMGIEN(1)=tempIEN
556 new IENS set IENS="+1,"_IEN9d49_","_IEN9d4_","
557 kill TMGFDA,TMGMSG,TMGIEN
558 set TMGFDA(9.4901,IENS,.01)=PatchSeq ;".01=Patch Hx, e.g. 10 SEQ #10
559 set TMGFDA(9.4901,IENS,.02)="NOW" ;".02=date applied
560 set TMGFDA(9.4901,IENS,.03)="`"_DUZ ;".03=Applied by
561 do UPDATE^DIE("E","TMGFDA","TMGIEN","TMGMSG")
562 if $data(TMGMSG("DIERR")) do
563 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
564 . set result=0
565
566MPE3 if result=0 goto MPEDone
567 new TMGWP
568 kill TMGFDA,TMGMSG
569 set TMGWP(1)="Patch was informational only. No installed code etc."
570 set TMGWP(2)="This entry was created as a marker that information was processed."
571 set IENS=TMGIEN(1)_","_IEN9d49_","_IEN9d4_","
572 do WP^DIE(9.4901,IENS,1,"","TMGWP","TMGMSG")
573 if $data(TMGMSG("DIERR")) do
574 . do AddMsg($$GetErrStr^TMGDEBUG(.TMGMSG),1,.Msg)
575 . set result=0
576
577MPEDone
578 quit result
579
580IsInstalled(PatchName)
581 ;"Purpose: To return if a given patch has already been installed.
582 ;"Input: PatchName -- format aaaa*nn.nn*mmm [SEQ #xxx]
583 ;"Result: 1 if installed, 0 if not, or problem.
584
585 new result set result=0
586 new PckInit,Ver,PatchNum
587
588 set PatchName=$piece(PatchName," ",1)
589 set PatchName=$$TrimRType^TMGSTUTL(PatchName,"C") ;"trim any characters off end of patch name, e.g. 'ABC*5.5*123<=='
590 set PckInit=$piece(PatchName,"*",1)
591 set Ver=$piece(PatchName,"*",2)
592 set PatchNum=$piece(PatchName,"*",3)
593 if (PckInit="")!(Ver="")!(PatchNum="") goto IIDone
594
595 new IEN9d4,IEN9d49
596 set IEN9d4=+$order(^DIC(9.4,"C",PckInit,""))
597 if IEN9d4'>0 goto IIDone
598 set IEN9d49=+$order(^DIC(9.4,IEN9d4,22,"B",Ver,""))
599 if IEN9d49'>0 do
600 . new oneVer set oneVer=""
601 . new found set found=0
602 . for set oneVer=$order(^DIC(9.4,IEN9d4,22,"B",oneVer)) quit:(oneVer="")!found do
603 . . new Int,oneInt,Dec,oneDec
604 . . set Int=$piece(Ver,".",1),Dec=+$piece(Ver,".",2)
605 . . set oneInt=$piece(oneVer,".",1),oneDec=+$piece(oneVer,".",2)
606 . . if (Int=oneInt)&(Dec=oneDec) do
607 . . . set IEN9d49=+$order(^DIC(9.4,IEN9d4,22,"B",oneVer,""))
608 . . . set found=1
609 if IEN9d49'>0 goto IIDone
610
611 goto:(IEN9d49'>0) IIDone
612
613 new i,array,done
614 set i="",done=0
615 for set i=$order(^DIC(9.4,IEN9d4,22,IEN9d49,"PAH","B",i)) quit:(i="") do
616 . new onePatchNum set onePatchNum=$piece(i," ",1)
617 . if onePatchNum=PatchNum do
618 . . set result=1,done=1
619
620IIDone
621 quit result
622
623
624ParsePatchName(PatchName,PckInit,Ver,PatchNum,SeqNum)
625 ;"Purpose: to parse a patch name into it's composit parts.
626 ;"Input: PatchName -- the patch name to parse, e.g. ABC*12.34*1234 SEQ #123
627 ;" PckInit,Ver,PatchNum,SeqNum -- PASS BY REFERENCE, OUT PARAMETERS
628 ;"Results: none
629 set SeqNum=+$piece(PatchName,"SEQ #",2)
630 set PatchName=$piece(PatchName," SEQ #",1)
631 set PckInit=$piece(PatchName,"*",1)
632 set Ver=$piece(PatchName,"*",2)
633 set PatchNum=$piece(PatchName,"*",3)
634 quit
635
636
637
638AddMsg(s,IsError,Msg)
639 ;"Purpose: to add a message to Msg Array
640 ;"Input: s -- message. May be a string, or an array (or both) in format of:
641 ;" s=A line
642 ;" s(1)=line 1
643 ;" s(2)=line 2
644 ;" IsError -- 1 if is an error message
645 ;" Msg -- PASS BY REFERENCE, an OUT PARAMETER.
646 ;" Errors are stored in Msg("ERROR",x)=Message
647 ;" Msg("ERROR")=count of last error
648 ;" Message are store in Msg(x)=Message
649 ;" Msg=count of last message+1
650 ;"Results: none
651
652 set IsError=+$get(IsError)
653 new oneLine,subI set subI=""
654 set oneLine=$get(s)
655 for do set subI=$order(s(subI)) quit:(subI="") set oneLine=$get(s(subI))
656 . if IsError do
657 . . new MsgI set MsgI=$get(Msg("ERROR"),0)+1
658 . . set Msg("ERROR",MsgI)=oneLine
659 . . set Msg("ERROR")=MsgI
660 . else do
661 . . set Msg=+$get(Msg,1)
662 . . set Msg(Msg)=oneLine,Msg=Msg+1
663 quit
664
665
666ShowMsg(Msg,NoPause)
667 ;"Purpose: to display the message array
668 ;"Input: Msg - PASS BY REFERENCE. The message array to display.
669 ;" NoPause -- OPTIONAL. If 1, then user not prompted to hit enter to cont.
670 ;"Results: 0 if OK, 1 if ERROR found in message array.
671 new errorFound set errorFound=0
672 if $data(Msg) do
673 . new i set i=""
674 . for set i=$order(Msg(i)) quit:(+i'>0) write " ",$get(Msg(i)),!
675 . if $data(Msg("ERROR")) do
676 . . write !!,"NOTE: ERRORS ENCOUNTERED:",!
677 . . set i=""
678 . . for set i=$order(Msg("ERROR",i)) quit:(+i'>0) write " ",$get(Msg("ERROR",i)),!
679 . . set errorFound=1
680 . if $get(NoPause)'=1 do PressToCont^TMGUSRIF
681
682 quit errorFound
Note: See TracBrowser for help on using the repository browser.