|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2016.2 (Build 728U)"> |
| 3 | +<Project name="sc-all"> |
| 4 | + <Items> |
| 5 | + <ProjectItem name="sc.all" type="CLS"></ProjectItem> |
| 6 | + <ProjectItem name="sc.all.sub" type="CLS"></ProjectItem> |
| 7 | + </Items> |
| 8 | +</Project> |
| 9 | + |
| 10 | + |
| 11 | +<Class name="sc.all"> |
| 12 | +<Description> |
| 13 | + |
| 14 | +UDL export/import all for ISC Caché 2016.2 |
| 15 | +Usage: |
| 16 | +w ##class(sc.all).workdir( "c:\your\work\dir\") |
| 17 | +d ##class(sc.all).export() |
| 18 | +d ##class(sc.all).import() |
| 19 | +</Description> |
| 20 | +<Abstract>1</Abstract> |
| 21 | + |
| 22 | +<Method name="export"> |
| 23 | +<Description> |
| 24 | +export all available code</Description> |
| 25 | +<ClassMethod>1</ClassMethod> |
| 26 | +<FormalSpec>generated=0,system=0,percent=0,mapped=1</FormalSpec> |
| 27 | +<Implementation><![CDATA[ |
| 28 | + |
| 29 | + #define export(%code, %file) $system.OBJ.ExportUDL(%code, %file,"/diffexport") |
| 30 | + #define isGenerated(%code) ##class(%RoutineMgr).IsGenerated( %code ) |
| 31 | + #define isPercented(%code) ("%" = $e(%code)) |
| 32 | + #define isMapped(%code) ##class(%RoutineMgr).IsMapped( %code ) |
| 33 | + #define log w !, code, " -> ", filename, " " |
| 34 | + |
| 35 | + #; classes |
| 36 | + s rs = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary") |
| 37 | + if rs.Execute() { |
| 38 | + |
| 39 | + while rs.%Next(){ |
| 40 | + |
| 41 | + s code = rs.Name _ ".cls", isSystem = rs.System |
| 42 | + if ( 'system && isSystem ) continue |
| 43 | + if ( 'generated && $$$isGenerated( code ) ) continue |
| 44 | + if ( 'percent && $$$isPercented( code ) ) continue |
| 45 | + if ( 'mapped && $$$isMapped( code ) ) continue |
| 46 | + s filename = ..filename( code ) |
| 47 | + $$$log |
| 48 | + w $$$export( code, filename ) |
| 49 | + |
| 50 | + } s rs="" |
| 51 | + } |
| 52 | + |
| 53 | + #; routines |
| 54 | + s rs = ##class(%ResultSet).%New("%Routine:RoutineList") |
| 55 | + if rs.Execute() { |
| 56 | + |
| 57 | + while rs.%Next() { |
| 58 | + |
| 59 | + s code = rs.Name |
| 60 | + if ( 'generated && $$$isGenerated( code ) ) continue |
| 61 | + if ( 'percent && $$$isPercented( code ) ) continue |
| 62 | + if ( 'mapped && $$$isMapped( code ) ) continue |
| 63 | + |
| 64 | + s filename = ..filename( code ) |
| 65 | + $$$log |
| 66 | + w $$$export( code, filename ) |
| 67 | + |
| 68 | + } s rs="" |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + #; dfi |
| 73 | + #define export(%code, %file) ##class(%DeepSee.UserLibrary.Utils).%Export( %code, %file, 0 ) |
| 74 | + s sql = "Select fullName as Name From %DeepSee_UserLibrary.FolderItem" |
| 75 | + s rs = ##class(%SQL.Statement).%ExecDirect( .stm, sql ) |
| 76 | + while rs.%Next() { |
| 77 | + s code = rs.Name, filename = ..filename( code_".dfi" ) |
| 78 | + $$$log |
| 79 | + w $$$export( code, filename ) |
| 80 | + |
| 81 | + } s rs="" |
| 82 | + |
| 83 | + Q |
| 84 | +]]></Implementation> |
| 85 | +</Method> |
| 86 | + |
| 87 | +<Method name="import"> |
| 88 | +<Description> |
| 89 | +import all from workdir</Description> |
| 90 | +<ClassMethod>1</ClassMethod> |
| 91 | +<FormalSpec><![CDATA[qspec="cku-d",&err="",recurse=1,&loaded="",verbose=1]]></FormalSpec> |
| 92 | +<ReturnType>%Status</ReturnType> |
| 93 | +<Implementation><![CDATA[ |
| 94 | + #define push(%dir) s dirs( $i( dirs ) ) = %dir |
| 95 | + #define next(%i,%dir) s %i=$o( dirs( "" ), 1, %dir ) k:%i'="" dirs(%i) |
| 96 | + #define isDirectory(%type) ( %type = "D" ) |
| 97 | + #define log w !, filename, " ", +sc |
| 98 | + |
| 99 | + s sc = 1, dirs = "", dir = ..workdir() $$$push(dir) |
| 100 | + |
| 101 | + s rs = ##class(%ResultSet).%New( "%Library.File:FileSet" ) |
| 102 | + for { $$$next(i,dir) Q:i="" Q:dir="" |
| 103 | + |
| 104 | + s sc = rs.Execute( dir, "*.*" ) Q:'sc |
| 105 | + |
| 106 | + while rs.Next() { |
| 107 | + |
| 108 | + s filename = rs.Name |
| 109 | + |
| 110 | + if $$$isDirectory(rs.Type) { |
| 111 | + |
| 112 | + if recurse $$$push(filename) |
| 113 | + continue |
| 114 | + |
| 115 | + } |
| 116 | + |
| 117 | + s ext = $p(filename, ".", *) |
| 118 | + if $zcvt(ext,"l") = "dfi" { |
| 119 | + |
| 120 | + s sc = ##class(%DeepSee.UserLibrary.Utils).%Import( filename, 1, 0, 0, "", .loaded ) |
| 121 | + |
| 122 | + } else { |
| 123 | + |
| 124 | + s sc = $system.OBJ.Load( filename, qspec, .err, .loaded) |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + if verbose $$$log |
| 129 | + |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + Q sc |
| 134 | +]]></Implementation> |
| 135 | +</Method> |
| 136 | + |
| 137 | +<Method name="filename"> |
| 138 | +<Description> |
| 139 | +Translate ( codename ) into ( filename )</Description> |
| 140 | +<ClassMethod>1</ClassMethod> |
| 141 | +<FormalSpec>code</FormalSpec> |
| 142 | +<Implementation><![CDATA[ |
| 143 | + s wd = ..workdir() |
| 144 | + d:'##class(%File).DirectoryExists( wd ) ##class(%File).CreateDirectoryChain( wd ) |
| 145 | + s filename = ##class(%File).NormalizeFilename( code, wd ) |
| 146 | + #; for *.dfi filename can contain folders |
| 147 | + s path = ##class(%File).GetDirectory(filename) |
| 148 | + d:'##class(%File).DirectoryExists( path ) ##class(%File).CreateDirectoryChain( path ) |
| 149 | + Q filename |
| 150 | +]]></Implementation> |
| 151 | +</Method> |
| 152 | + |
| 153 | +<Method name="workdir"> |
| 154 | +<Description> |
| 155 | +get or set working directory for export/import source</Description> |
| 156 | +<ClassMethod>1</ClassMethod> |
| 157 | +<FormalSpec>workdir</FormalSpec> |
| 158 | +<Implementation><![CDATA[ |
| 159 | + s gln = ..gln() s:$d(workdir) @gln = workdir |
| 160 | + ///zu(12) namespace directory by default |
| 161 | + #define nsdir $zu(12,"") |
| 162 | + Q $g(@gln, $$$nsdir) |
| 163 | +]]></Implementation> |
| 164 | +</Method> |
| 165 | + |
| 166 | +<Method name="gln"> |
| 167 | +<Description> |
| 168 | +gl[obal] n[ame] - storage for settings</Description> |
| 169 | +<ClassMethod>1</ClassMethod> |
| 170 | +<CodeMode>expression</CodeMode> |
| 171 | +<Private>1</Private> |
| 172 | +<Implementation><![CDATA["^"_$classname() |
| 173 | +]]></Implementation> |
| 174 | +</Method> |
| 175 | +</Class> |
| 176 | + |
| 177 | + |
| 178 | +<Class name="sc.all.sub"> |
| 179 | +<Description> |
| 180 | +Export different types of modules in different subfolders</Description> |
| 181 | +<Super>sc.all</Super> |
| 182 | + |
| 183 | +<Method name="filename"> |
| 184 | +<Description><![CDATA[ |
| 185 | +test.dfi -> /dfi/test.dfi |
| 186 | +test.cls -> /cls/test.cls |
| 187 | +etc]]></Description> |
| 188 | +<ClassMethod>1</ClassMethod> |
| 189 | +<FormalSpec>code</FormalSpec> |
| 190 | +<Implementation><![CDATA[ |
| 191 | + s ext = $p( code, ".", * ), ext = $zcvt( ext, "l" ) |
| 192 | + #; for each type - different directory |
| 193 | + s wd = ..workdir() s:ext'="" wd = ##class(%File).NormalizeDirectory( ext, wd ) |
| 194 | + d:'##class(%File).DirectoryExists( wd ) ##class(%File).CreateDirectoryChain( wd ) |
| 195 | + |
| 196 | + s filename = ##class(%File).NormalizeFilename( code, wd ) |
| 197 | + #; for *.dfi filename can contain folders |
| 198 | + if ext = "dfi" { |
| 199 | + s path = ##class(%File).GetDirectory( filename ) |
| 200 | + d:'##class(%File).DirectoryExists( path ) ##class(%File).CreateDirectoryChain( path ) |
| 201 | + } |
| 202 | + Q filename |
| 203 | +]]></Implementation> |
| 204 | +</Method> |
| 205 | + |
| 206 | +<Method name="importUpdated"> |
| 207 | +<Description> |
| 208 | +import from workdir all files with ts newer than code ts in db</Description> |
| 209 | +<ClassMethod>1</ClassMethod> |
| 210 | +<FormalSpec><![CDATA[qspec="cku-d",&err="",recurse=1,&loaded="",verbose=1]]></FormalSpec> |
| 211 | +<ReturnType>%Status</ReturnType> |
| 212 | +<Implementation><![CDATA[ |
| 213 | + #define push(%dir) s dirs( $i( dirs ) ) = %dir |
| 214 | + #define next(%i,%dir) s %i=$o( dirs( "" ), 1, %dir ) k:%i'="" dirs(%i) |
| 215 | + #define isDirectory(%type) ( %type = "D" ) |
| 216 | + #define log w !, filename, " -> ", codename, " ", +sc |
| 217 | + |
| 218 | + s sc = 1, dirs = "", dir = ..workdir() $$$push(dir) |
| 219 | + |
| 220 | + s rs = ##class(%ResultSet).%New( "%Library.File:FileSet" ) |
| 221 | + for { $$$next(i,dir) Q:i="" Q:dir="" |
| 222 | + |
| 223 | + s sc = rs.Execute( dir, "*.*" ) Q:'sc |
| 224 | + |
| 225 | + while rs.Next() { |
| 226 | + |
| 227 | + s filename = rs.Name |
| 228 | + |
| 229 | + if $$$isDirectory( rs.Type ) { |
| 230 | + if ( recurse ) $$$push(filename) ;push directory |
| 231 | + continue |
| 232 | + } |
| 233 | + |
| 234 | + s filets = rs.DateModified |
| 235 | + s codename = ..codename( filename, .ext ) |
| 236 | + s codets = ..codets( codename, ext ) |
| 237 | + |
| 238 | + if ( filets '] codets ) continue |
| 239 | + |
| 240 | + /* |
| 241 | + w !, " ************* import ************** " |
| 242 | + w !, "file: ", filets |
| 243 | + w !, "code: ", codets |
| 244 | + */ |
| 245 | + |
| 246 | + if ext = "dfi" { |
| 247 | + |
| 248 | + s sc = ##class(%DeepSee.UserLibrary.Utils).%Import( filename, 1, 0, 0, "", .loaded ) |
| 249 | + |
| 250 | + } else { |
| 251 | + |
| 252 | + s sc = $system.OBJ.Load( filename, qspec, .err, .loaded) |
| 253 | + |
| 254 | + } |
| 255 | + |
| 256 | + if verbose $$$log |
| 257 | + } |
| 258 | + } |
| 259 | + Q sc |
| 260 | +]]></Implementation> |
| 261 | +</Method> |
| 262 | + |
| 263 | +<Method name="codename"> |
| 264 | +<Description> |
| 265 | +presumable codename </Description> |
| 266 | +<ClassMethod>1</ClassMethod> |
| 267 | +<FormalSpec><![CDATA[filename,&ext=""]]></FormalSpec> |
| 268 | +<Implementation><![CDATA[ |
| 269 | + s ext = $p( filename, ".", * ), ext = $zcvt( ext, "l" ) |
| 270 | + s path = ##class(%File).NormalizeDirectory( ext, ..workdir() ) |
| 271 | + s codename = $p( filename, path, 2 ) |
| 272 | + if ext = "dfi" { |
| 273 | + s fullname = $tr( codename, "\", "/" ) ; return fullname for dfi in $$$IsWINDOWS |
| 274 | + Q $p( fullname, ".", 1, *-1 ) ;remove extension |
| 275 | + } |
| 276 | + Q codename |
| 277 | +]]></Implementation> |
| 278 | +</Method> |
| 279 | + |
| 280 | +<Method name="codets"> |
| 281 | +<ClassMethod>1</ClassMethod> |
| 282 | +<FormalSpec>codename,ext</FormalSpec> |
| 283 | +<Implementation><![CDATA[ |
| 284 | + s ts = "" |
| 285 | + if ext'="dfi" { |
| 286 | + s ts = ##class(%RoutineMgr).TS( codename ) |
| 287 | + } else { |
| 288 | + s sql="Select timeModified From %DeepSee_UserLibrary.FolderItem Where fullname = ?" |
| 289 | + s rs = ##class(%SQL.Statement).%ExecDirect( , sql, codename ) |
| 290 | + if rs.%Next() { |
| 291 | + s utcts = rs.timeModified |
| 292 | + s utch = $zdth( utcts, 3, , 3 ) ;utc internal format |
| 293 | + s loch = $zdth( utch, -3 ) ; utc to local timezone |
| 294 | + s ts = $zdt( loch, 3, ,0 ) ; local timestamp*/ |
| 295 | + } |
| 296 | + } |
| 297 | + Q $p( ts, "." ) ;remove ms |
| 298 | +]]></Implementation> |
| 299 | +</Method> |
| 300 | +</Class> |
| 301 | +</Export> |
0 commit comments