|
| 1 | +/// UDL export/import all for ISC Caché 2016.2 |
| 2 | +/// Usage: |
| 3 | +/// w ##class(sc.all).workdir( "c:\your\work\dir\") |
| 4 | +/// d ##class(sc.all).export() |
| 5 | +/// d ##class(sc.all).import() |
| 6 | +Class sc.all [ Abstract ] |
| 7 | +{ |
| 8 | + |
| 9 | +/// export all available code |
| 10 | +ClassMethod export(generated = 0, system = 0, percent = 0) |
| 11 | +{ |
| 12 | + |
| 13 | + #define export(%code, %file) $system.OBJ.ExportUDL(%code, %file,"/diffexport") |
| 14 | + #define isGenerated(%code) ##class(%RoutineMgr).IsGenerated( %code ) |
| 15 | + #define isPercented(%code) ("%" = $e(%code)) |
| 16 | + #define log w !, code, " -> ", filename |
| 17 | + |
| 18 | + #; classes |
| 19 | + s rs = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary") |
| 20 | + if rs.Execute() { |
| 21 | + |
| 22 | + while rs.%Next(){ |
| 23 | + |
| 24 | + s code = rs.Name _ ".cls", isSystem = rs.System |
| 25 | + if ( 'system && isSystem ) continue |
| 26 | + if ( 'generated && $$$isGenerated( code ) ) continue |
| 27 | + if ( 'percent && $$$isPercented( code ) ) continue |
| 28 | + s filename = ..filename( code ) |
| 29 | + $$$log |
| 30 | + d $$$export( code, filename ) |
| 31 | + |
| 32 | + } s rs="" |
| 33 | + } |
| 34 | + |
| 35 | + #; routines |
| 36 | + s rs = ##class(%ResultSet).%New("%Routine:RoutineList") |
| 37 | + if rs.Execute() { |
| 38 | + |
| 39 | + while rs.%Next() { |
| 40 | + |
| 41 | + s code = rs.Name |
| 42 | + if ( 'generated && $$$isGenerated( code ) ) continue |
| 43 | + s filename = ..filename( code ) |
| 44 | + $$$log |
| 45 | + d $$$export( code, filename ) |
| 46 | + |
| 47 | + } s rs="" |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + #; dfi |
| 52 | + #define export(%code, %file) ##class(%DeepSee.UserLibrary.Utils).%Export( %code, %file, 0 ) |
| 53 | + s sql = "Select fullName as Name From %DeepSee_UserLibrary.FolderItem" |
| 54 | + s rs = ##class(%SQL.Statement).%ExecDirect( .stm, sql ) |
| 55 | + while rs.%Next() { |
| 56 | + s code = rs.Name, filename = ..filename( code )_".dfi" |
| 57 | + $$$log |
| 58 | + d $$$export( code, filename ) |
| 59 | + |
| 60 | + } s rs="" |
| 61 | + |
| 62 | + Q |
| 63 | +} |
| 64 | + |
| 65 | +/// import all from workdir |
| 66 | +ClassMethod import(qspec = "-d", ByRef err = "", recurse = 1, ByRef loaded = "", verbose = 1) As %Status |
| 67 | +{ |
| 68 | + #define push(%dir) s dirs( $i( dirs ) ) = %dir |
| 69 | + #define next(%i,%dir) s %i=$o( dirs( "" ), 1, %dir ) k:%i'="" dirs(%i) |
| 70 | + #define isDirectory(%type) ( %type = "D" ) |
| 71 | + #define log w !, filename, " ", +sc |
| 72 | + |
| 73 | + s sc = 1, dirs = "", dir = ..workdir() $$$push(dir) |
| 74 | + |
| 75 | + s rs = ##class(%ResultSet).%New( "%Library.File:FileSet" ) |
| 76 | + for { $$$next(i,dir) Q:i="" Q:dir="" |
| 77 | + |
| 78 | + s sc = rs.Execute( dir, "*.*" ) Q:'sc |
| 79 | + |
| 80 | + while rs.Next() { |
| 81 | + |
| 82 | + s filename = rs.Name |
| 83 | + |
| 84 | + if $$$isDirectory(rs.Type) { |
| 85 | + |
| 86 | + if recurse $$$push(filename) |
| 87 | + continue |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + s ext = $p(filename, ".", *) |
| 92 | + if $zcvt(ext,"l") = "dfi" { |
| 93 | + |
| 94 | + s sc = ##class(%DeepSee.UserLibrary.Utils).%Import( filename, 1, 0, 0, "", .loaded ) |
| 95 | + |
| 96 | + } else { |
| 97 | + |
| 98 | + s sc = $system.OBJ.Load( filename, qspec, .err, .loaded) |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + if verbose $$$log |
| 103 | + |
| 104 | + } |
| 105 | + } |
| 106 | + Q sc |
| 107 | +} |
| 108 | + |
| 109 | +/// Translate ( codename ) into ( filename ) |
| 110 | +ClassMethod filename(code) |
| 111 | +{ |
| 112 | + s path = ##class(%File).NormalizeFilename(code, ..workdir()) |
| 113 | + s dir = ##class(%File).GetDirectory( path ) |
| 114 | + d:'##class(%File).DirectoryExists( dir ) ##class(%File).CreateDirectoryChain( dir ) |
| 115 | + Q path |
| 116 | +} |
| 117 | + |
| 118 | +/// get or set working directory for export/import source |
| 119 | +ClassMethod workdir(workdir) |
| 120 | +{ |
| 121 | + s gln = ..gln() s:$d(workdir) @gln = workdir |
| 122 | + ///zu(12) namespace directory by default |
| 123 | + #define nsdir $zu(12,"") |
| 124 | + Q $g(@gln, $$$nsdir) |
| 125 | +} |
| 126 | + |
| 127 | +/// gl[obal] n[ame] - storage for settings |
| 128 | +ClassMethod gln() [ CodeMode = expression, Private ] |
| 129 | +{ |
| 130 | +"^"_$classname() |
| 131 | +} |
| 132 | + |
| 133 | +} |
| 134 | + |
0 commit comments