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