1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
- <Export generator =" Cache" version =" 25" zv =" Cache for Windows (x86-64) 2016.2 (Build 721U)" ts =" 2016-09-04 22:50:49 " >
2
+ <Export generator =" Cache" version =" 25" zv =" Cache for Windows (x86-64) 2016.2 (Build 721U)" ts =" 2016-09-12 18:18:41 " >
3
3
<Class name =" CacheUpdater.Task" >
4
- <Super >%SYS.Task.Definition</Super >
5
- <TimeChanged >64161,48985.224853 </TimeChanged >
4
+ <Super >%SYS.Task.Definition,CacheUpdater.UDL </Super >
5
+ <TimeChanged >64173,65712.36031 </TimeChanged >
6
6
<TimeCreated >63603,52252.541311</TimeCreated >
7
7
8
8
<Parameter name =" TaskName" >
@@ -75,20 +75,21 @@ Unauthenticated requests are associated with an IP address.<br>
75
75
For example in the repository: https://github.com/intersystems-ru/Cache-MDX2JSON<br>
76
76
Owner - intersystems-ru, Repository - Cache-MDX2JSON.<br> ]]> </Description >
77
77
<ClassMethod >1</ClassMethod >
78
- <FormalSpec >Owner:%String,Repository:%String,Branch:%String="",Username:%String,Password:%String,Namespace=$Namespace</FormalSpec >
78
+ <FormalSpec >Owner:%String,Repository:%String,Branch:%String="",Username:%String="" ,Password:%String="" ,Namespace=$Namespace</FormalSpec >
79
79
<ReturnType >%Status</ReturnType >
80
80
<Implementation ><![CDATA[
81
+ #dim req As %Net.HttpRequest
81
82
Set req = ..CreateRequest(Username, Password)
82
83
Set req.Location = "repos/" _ Owner _ "/" _ Repository _ "/contents" // as described in https://developer.github.com/v3/repos/
83
- Do:(Branch'="") req.SetParam("ref",Branch) // if omitted the repository’s default branch (usually master) would be used
84
84
85
85
Set links = ##class(%ListOfDataTypes).%New()
86
- Set st = ..ProcessDirectory("",req,.links)
86
+ Set st = ..ProcessDirectory("",. req,Branch ,.links)
87
87
Return:$$$ISERR(st) st
88
88
89
89
Set namespace = $Namespace
90
90
Zn Namespace
91
91
Set st = ..DownloadFiles(links,req,.list)
92
+ zw list
92
93
Set st2 = $system.OBJ.CompileList(.list,"cuk /checkuptodate=expandedonly")
93
94
Zn namespace
94
95
@@ -103,13 +104,15 @@ Process one directory of GitHub repository. Recursive.<br>
103
104
<b>Request</b> - Authenticated/Set %Net.HttpRequest object.<br>
104
105
<b>Links</b> - List of links to raw files (which satisfy <b>IsCacheFile</b> conditions) from repository.<br>]]> </Description >
105
106
<ClassMethod >1</ClassMethod >
106
- <FormalSpec ><![CDATA[ Path:%String="",Request:%Net.HttpRequest,&Links:%ListOfDataTypes]]> </FormalSpec >
107
+ <FormalSpec ><![CDATA[ Path:%String="",Request:%Net.HttpRequest,Branch:%String="", &Links:%ListOfDataTypes]]> </FormalSpec >
107
108
<ReturnType >%Status</ReturnType >
108
109
<Implementation ><![CDATA[
109
110
Set location = Request.Location
110
111
Set Request.Location = Request.Location _ Path
112
+ Do:(Branch'="") Request.SetParam("ref",Branch)
111
113
112
114
Set st = Request.Get()
115
+
113
116
Return:$$$ISERR(st) st
114
117
Return:(Request.HttpResponse.StatusCode = 404) $$$ERROR($$$GeneralError,"Repository doesn't exist OR you don't have access")
115
118
Return:((Request.HttpResponse.StatusCode = 403) && (Request.HttpResponse.GetHeader("X-RATELIMIT-REMAINING")=0)) $$$ERROR($$$GeneralError,"API rate limit exceeded. Try logging in.")
@@ -123,10 +126,11 @@ Process one directory of GitHub repository. Recursive.<br>
123
126
For i = 1:1:objects.Count() {
124
127
Set obj = objects.GetAt(i)
125
128
If (obj.type = "dir") {
126
- Set st = ..ProcessDirectory("/"_obj.name,Request,.Links)
129
+ Set st = ..ProcessDirectory("/"_obj.name,Request,Branch, .Links)
127
130
Return:$$$ISERR(st) st
128
131
} ElseIf (obj.type = "file") {
129
- Do:..IsCacheFile(obj) Links.Insert(obj."download_url")
132
+ //Do:..IsCacheFile(obj) Links.Insert(obj."download_url")
133
+ Do Links.Insert($LB(obj."download_url",..IsCacheFile(obj)))
130
134
} Else {
131
135
// obj.type = "symlink" or obj.type = "submodule"
132
136
}
@@ -143,7 +147,7 @@ Check that incoming file is the one you need.</Description>
143
147
<FormalSpec >File:%ZEN.proxyObject</FormalSpec >
144
148
<ReturnType >%Boolean</ReturnType >
145
149
<Implementation ><![CDATA[
146
- Set extensions = ",xml,cls,csp,csr,mac,int,bas,inc,gbl,prj,obj,pkg,gof,dfi,pivot,dashboard,html,css,js,ts,scss"
150
+ Set extensions = ",xml,cls,csp,csr,mac,int,bas,inc,gbl,prj,obj,pkg,gof,dfi,pivot,dashboard,html,css,js,ts,scss, "
147
151
Return:($L(File.name,".")=1) 0 //no extension
148
152
Set File.Extension = $P(File.name,".",$L(File.name,"."))
149
153
Return $F(extensions,","_$ZCVT(File.Extension,"l")_",")
@@ -163,36 +167,100 @@ Download list of files on https://raw.githubusercontent.com/ server.<br>
163
167
Kill Items
164
168
Set Request.Server = "raw.githubusercontent.com"
165
169
Set st = $$$OK
166
-
167
- For i = 1:1:Links.Count() {
168
- Set link = Links.GetAt(i)
169
- Set streq = Request.Get($e(link,35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
170
- Set:$$$ISERR(streq) st=$$$ADDSC(st, streq)
171
-
172
- Set binarystream = Request.HttpResponse.Data
173
- Do binarystream.Rewind() // just in case
174
-
175
- Set stream=##class(%GlobalCharacterStream).%New() //translating binary stream into character stream
176
- While 'binarystream.AtEnd {
177
- Do stream.WriteLine(binarystream.ReadLine())
178
- }
179
- Do stream.Rewind()
180
-
181
-
182
- Set strload = ""
183
- If ##class(CacheUpdater.UDL).IsUDLFile(stream) {
184
- Set stload = ##class(CacheUpdater.UDL).LoadUDLFile(stream, link, .items)
185
- }
186
- Else {
187
- Set stload = $system.OBJ.LoadStream(stream,"",.error,.items,,,,"UTF8")
170
+ Try
171
+ {
172
+ For i = 1:1:Links.Count()
173
+ {
174
+ Set link = $ListGet(Links.GetAt(i),1)
175
+ Set bIsCacheFile = $ListGet(Links.GetAt(i),2)
176
+ Set ^gitfiles(i,"link")=link
177
+ Set ^gitfiles(i,"bIsCacheFile")=bIsCacheFile
178
+
179
+ Set streq = Request.Get($e(link,35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
180
+ If $$$ISERR(streq)
181
+ {
182
+ Set st=$$$ADDSC(st, streq)
183
+ Set ^gitfiles(i,"streq")=streq
184
+ Continue
185
+ }
186
+
187
+ Set ^gitfiles(i,"stream")="starting..."
188
+ Set binarystream = Request.HttpResponse.Data
189
+
190
+ Do binarystream.Rewind() // just in case
191
+
192
+ Set characterStream=##class(%GlobalCharacterStream).%New() //translating binary stream into character stream
193
+ Set stTranslate=$$$OK
194
+ Try
195
+ {
196
+ While 'binarystream.AtEnd
197
+ {
198
+ //Use eol to prevent breaking lines larger than 32Kb
199
+ Set line=binarystream.ReadLine(, .stTranslate, .eol)
200
+ Quit:$System.Status.IsError(stTranslate)
201
+
202
+ If eol
203
+ {
204
+ Set stTranslate=characterStream.WriteLine(line)
205
+ }
206
+ Else
207
+ {
208
+ Set stTranslate=characterStream.Write(line)
209
+ }
210
+ Quit:$System.Status.IsError(stTranslate)
211
+ }
212
+ Quit:$System.Status.IsError(stTranslate)
213
+
214
+ Do characterStream.Rewind()
215
+ }
216
+ Catch (oTranslateStreamException)
217
+ {
218
+ Set stTranslate=oTranslateStreamException.AsStatus()
219
+ }
220
+
221
+ If $System.Status.IsError(stTranslate)
222
+ {
223
+ //Could not convert binary stream to character stream
224
+ //It is probably a binary file anyway
225
+ Set characterStream=""
226
+ Set st=$$$ADDSC(st, stTranslate)
227
+ Set ^gitfiles(i,"stTranslate")=stTranslate
228
+ }
229
+ Set ^gitfiles(i,"stream")="Done"
230
+
231
+ Do binarystream.Rewind()
232
+
233
+ Set stload = $$$OK
234
+
235
+ set items = ""
236
+ If ('$IsObject(characterStream)) || (..IsUDLFile(characterStream))
237
+ {
238
+ Set ^gitfiles(i,"IsUDLFile")="1"
239
+ Set stload = ..LoadUDLFile(characterStream, binarystream, link, .items)
240
+ }
241
+ ElseIf bIsCacheFile
242
+ {
243
+ Set ^gitfiles(i,"IsUDLFile")="0"
244
+ Set stload = $system.OBJ.LoadStream(characterStream,"",.error,.items,,,,"UTF8")
245
+ }
246
+ Set ^gitfiles(i,"stload")=stload
247
+ If $$$ISERR(stload)
248
+ {
249
+ Set st=$$$ADDSC(st, stload)
250
+ Continue
251
+ }
252
+ Merge Items = items // Does not overwrite existing array keys: Items(itemname)=""
188
253
}
189
254
190
- Set:$$$ISERR(stload) st=$$$ADDSC(st, stload)
191
- Merge Items = items // Does not overwrite existing array keys: Items(itemname)=""
255
+ Set Request.Server="api.github.com"
256
+ }
257
+ Catch (oException)
258
+ {
259
+ Set st = oException.AsStatus()
260
+ If $D(i) Set ^gitfiles(i,"st final")=st
192
261
}
193
262
194
- Set Request.Server="api.github.com"
195
- Return st
263
+ Quit st
196
264
]]> </Implementation >
197
265
</Method >
198
266
@@ -227,7 +295,7 @@ Download list of files on https://raw.githubusercontent.com/ server.<br>
227
295
228
296
<Class name =" CacheUpdater.UDL" >
229
297
<Super >%RegisteredObject</Super >
230
- <TimeChanged >64165,82238.47126 </TimeChanged >
298
+ <TimeChanged >64173,65465.415142 </TimeChanged >
231
299
<TimeCreated >64161,48850.325593</TimeCreated >
232
300
233
301
<Method name =" IsUDLFile" >
@@ -265,23 +333,8 @@ Finds the first string in a line
265
333
<FormalSpec >line:%String</FormalSpec >
266
334
<ReturnType >%String</ReturnType >
267
335
<Implementation ><![CDATA[
268
- set counter = 1
269
- set letter = $extract(line, counter)
270
- while letter '= "" {
271
- if letter = " " {
272
- set counter = counter + 1
273
- set letter = $extract(line, counter)
274
- continue
275
- } else {
276
- set ext = $extract(line, counter, *)
277
- set index = $find(ext, " ")
278
- if index = 0 {
279
- set index = 9999999999
280
- }
281
- return $extract(ext, 0, index - 2)
282
- }
283
- }
284
- return ""
336
+ set trimmed = $zstrip(line, "<>W")
337
+ return $piece(trimmed, " ")
285
338
]]> </Implementation >
286
339
</Method >
287
340
@@ -396,8 +449,9 @@ Get extension of the file by url
396
449
<FormalSpec >url:%String</FormalSpec >
397
450
<ReturnType >%String</ReturnType >
398
451
<Implementation ><![CDATA[
399
-
400
- return $zconvert($piece(url, ".", *), "l")
452
+ //return $zconvert($piece(url, ".", *), "l")
453
+ //AMIR: There are parameters after the extension that are not part of the extension
454
+ return $zconvert($piece($piece(url, ".", *),"?"), "l")
401
455
]]> </Implementation >
402
456
</Method >
403
457
@@ -409,7 +463,6 @@ Check whether a file is a web file
409
463
<FormalSpec >ext:%String</FormalSpec >
410
464
<ReturnType >%String</ReturnType >
411
465
<Implementation ><![CDATA[
412
-
413
466
set webExts = "csp,html,css,js,ts,scss"
414
467
return $find(webExts, ext)
415
468
]]> </Implementation >
@@ -422,12 +475,13 @@ Imports the file in UDL file in the project
422
475
<b>url</b> - the url where the file is located in the web.<br>
423
476
<b>list</b> - array of files to compile<br>]]> </Description >
424
477
<ClassMethod >1</ClassMethod >
425
- <FormalSpec >contentStream:%GlobalCharacterStream,url:%String,list:%String</FormalSpec >
478
+ <FormalSpec >contentStream:%GlobalCharacterStream,binaryStream:%Stream.FileCharacterGzip, url:%String,list:%String</FormalSpec >
426
479
<ReturnType >%Status</ReturnType >
427
480
<Implementation ><![CDATA[
428
481
set st = $$$OK
429
482
430
483
set ext = ..GetExt(url)
484
+
431
485
if ext = "cls" {
432
486
set st = ..CreateClass(contentStream, url, .list)
433
487
}
@@ -436,10 +490,11 @@ Imports the file in UDL file in the project
436
490
}
437
491
elseif (ext = "inc") || (ext = "mac") {
438
492
set st = ..CreateRoutine(contentStream, url, .list)
439
- } elseif ..IsWebFile(ext) {
440
- set st = ..CreateWebFile(contentStream, url, ext, .list)
493
+ }
494
+ else
495
+ {
496
+ set st = ..CreateWebFile(contentStream, binaryStream, url, ext, .list)
441
497
}
442
-
443
498
return st
444
499
]]> </Implementation >
445
500
</Method >
@@ -585,34 +640,57 @@ Creates and imports mac, int, inc files into the project from stream
585
640
<b>ext</b> - extension of the file<br>
586
641
<b>list</b> - array of files to compile<br>]]> </Description >
587
642
<ClassMethod >1</ClassMethod >
588
- <FormalSpec ><![CDATA[ contentStream:%GlobalCharacterStream,url:%String,ext:%String,&list:%String]]> </FormalSpec >
643
+ <FormalSpec ><![CDATA[ contentStream:%GlobalCharacterStream,binaryStream:%Stream.FileCharacterGzip, url:%String,ext:%String,&list:%String]]> </FormalSpec >
589
644
<ReturnType >%Status</ReturnType >
590
645
<Implementation ><![CDATA[
591
646
Set st = $$$OK
592
-
593
- Set filestream = ##class(%Stream.FileCharacter).%New()
594
- Do contentStream.Rewind()
595
-
596
- set CSPPath = $system.CSP.GetFileName($system.CSP.GetDefaultApp($namespace)_"/")
597
- set fileDirectory = $translate($Piece(url, "csp/", 2), "\", "/")
598
- set dirChain = $p(CSPPath_fileDirectory,$p($translate(CSPPath_fileDirectory,"\","/"),"/",*),1)
599
- set dirChain = $translate(dirChain, "\", "/")
600
- do ##class(%File).CreateDirectoryChain(dirChain)
601
- set st = filestream.LinkToFile(CSPPath_fileDirectory)
602
-
603
- While 'contentStream.AtEnd
647
+ Try
604
648
{
605
- Do filestream.WriteLine(contentStream.ReadLine())
649
+ Set tDefaultApp=$system.CSP.GetDefaultApp($namespace)_"/"
650
+ set tCSPRootPath = $system.CSP.GetFileName(tDefaultApp)
651
+
652
+ Set tFileName = $Piece($Piece(url,"?",1),"/",*)
653
+
654
+ Set tCSPSubPath = $Piece(url,tDefaultApp,2,*) //still has filename and ? parameters in it
655
+ Set tCSPSubPath = $Piece(tCSPSubPath, tFileName,1) //now it does't
656
+
657
+ set tFileDirectory = tCSPRootPath_tCSPSubPath
658
+ Set tFullFileName = tFileDirectory_tFileName
659
+
660
+ //On Windows, tFullFileName will contain \ and / but CreateDirectoryChain() and
661
+ //LinkToFile() already normalize the paths accordingly to the OS for us so
662
+ //we don't have to worry about it.
663
+ If '##class(%File).CreateDirectoryChain(tFileDirectory)
664
+ {
665
+ Set st = $System.Status.Error(5001,"Could nor create path chain '"_tFileDirectory_"'")
666
+ Quit
667
+ }
668
+
669
+ Set filestream = ##class(%Stream.FileCharacter).%New()
670
+ set st = filestream.LinkToFile(tFullFileName)
671
+ Quit:$System.Status.IsError(st)
672
+
673
+ If $IsObject(contentStream) && ..IsWebFile(ext)
674
+ {
675
+ Set st=filestream.CopyFrom(contentStream)
676
+ }
677
+ Else
678
+ {
679
+ Set st=filestream.CopyFrom(binaryStream)
680
+ }
681
+ Quit:$System.Status.IsError(st)
682
+
683
+ set st = filestream.%Save()
684
+ Quit:$System.Status.IsError(st)
685
+
686
+ Write !, "Imported " _ tFullFileName, !
606
687
}
607
- if $$$ISERR(st) Quit st
608
-
609
- set st = filestream.%Save()
610
-
611
- if st {
612
- w !, "Imported " _ fileDirectory, !
688
+ Catch (oException)
689
+ {
690
+ Set st = oException.AsStatus()
613
691
}
614
692
615
- Return st
693
+ Quit st
616
694
]]> </Implementation >
617
695
</Method >
618
696
</Class >
0 commit comments