From 234b1afd3e44c44b1ad686e6392abdbd9382aaf5 Mon Sep 17 00:00:00 2001 From: eduard93 Date: Mon, 26 Mar 2018 13:27:16 +0300 Subject: [PATCH] XML -> UDL --- isc/git/{Diff.cls.xml => Diff.cls} | 67 ++++----- isc/git/{GitLab.cls.xml => GitLab.cls} | 183 ++++++++++--------------- isc/git/Settings.cls | 50 +++++++ isc/git/Settings.cls.xml | 68 --------- isc/util/OSUtils.cls | 91 ++++++++++++ isc/util/OSUtils.cls.xml | 112 --------------- 6 files changed, 239 insertions(+), 332 deletions(-) rename isc/git/{Diff.cls.xml => Diff.cls} (51%) rename isc/git/{GitLab.cls.xml => GitLab.cls} (58%) create mode 100644 isc/git/Settings.cls delete mode 100644 isc/git/Settings.cls.xml create mode 100644 isc/util/OSUtils.cls delete mode 100644 isc/util/OSUtils.cls.xml diff --git a/isc/git/Diff.cls.xml b/isc/git/Diff.cls similarity index 51% rename from isc/git/Diff.cls.xml rename to isc/git/Diff.cls index d136a45..d1faa7e 100644 --- a/isc/git/Diff.cls.xml +++ b/isc/git/Diff.cls @@ -1,30 +1,24 @@ - - - -isc.util.OSUtils -64700,69295.723984 +Class isc.git.Diff Extends isc.util.OSUtils +{ - - -Get diff between two points in repository -repo - repository root directory -sha1, commitEnd - poins of history in repository -modified - list of modified files -added - list of added files -deleted - list of deleted files - -Internal diff statuses: -M modified - File has been modified -C copy-edit - File has been copied and modified //3-arg form -R rename-edit - File has been renamed and modified //3-arg form -A added - File has been added -D deleted - File has been deleted -U unmerged - File has conflicts after a merge - -do ##class(isc.git.Diff).buildDiff("C:\\temp\GitLab\", "HEAD~10", "HEAD", .modified, .added, .deleted) -1 -repo:%String,commitBegin:%String,commitEnd:%String,*modified:%List,*added:%List,*deleted:%List - - +} - - -Determine if the file is neede for git diff -1 -dir:%String,file:%String -%Boolean -0 -]]> - - - +} + +} + diff --git a/isc/git/GitLab.cls.xml b/isc/git/GitLab.cls similarity index 58% rename from isc/git/GitLab.cls.xml rename to isc/git/GitLab.cls index 21544ca..a22c994 100644 --- a/isc/git/GitLab.cls.xml +++ b/isc/git/GitLab.cls @@ -1,30 +1,21 @@ - - - -64700,73518.498808 - - -1 -expression - - - - - -For CI build - get current commit -1 -expression - - - - - -Do a full load -do ##class(isc.git.GitLab).load() -1 - write !,$System.Status.GetErrorText(ex.AsStatus()),! do $system.Process.Terminate(, 1) } -]]> - +} - - -Do a diff load -do ##class(isc.git.GitLab).loadDiff() -1 - do ..logException(ex) do $system.Process.Terminate(, 1) } -]]> - +} - -1 - } else { do ..log("No init code") } -]]> - +} - - -do ##class(isc.git.GitLab).test() -1 - do ..logException(ex) do $system.Process.Terminate(, 1) } -]]> - +} - - -do ##class(GitLab.Main).package() -1 - do ..logException(ex) do $system.Process.Terminate(, 1) } -]]> - +} - -1 - do file.LinkToFile(name) do file.Write(text) quit file.%Save() -]]> - +} - -1 - - +} - - -Get extensions as wildcard for import -1 -%String - - +} - - -w ##class(GitLab.Main).isLastTestOk() -1 -%Boolean - return:suite.Status=0 $$$NO } quit $$$YES -]]> - +} - - @@ -221,14 +188,10 @@ window.location.href = "!!!" If you are not redirected automatically, follow this link to tests. -]]> - +} - -1 -var="",name:%String="" -%String -link to tests } else { write var }*/ -]]> - +} + +ClassMethod logException(ex As %Exception.AbstractException) +{ + do ..logStatus(ex.AsStatus()) +} + +ClassMethod logStatus(sc As %Status) +{ + do ..log($System.Status.GetErrorText(sc)) +} - -1 -ex:%Exception.AbstractException - - +ClassMethod log(msg As %String) +{ + write !, $$$FormatText("[%1] %2", $zdatetime($ztimestamp, 3, 1, 3), msg), ! +} - -1 -sc:%Status - - +} - -1 -msg:%String - - - - diff --git a/isc/git/Settings.cls b/isc/git/Settings.cls new file mode 100644 index 0000000..98be0f3 --- /dev/null +++ b/isc/git/Settings.cls @@ -0,0 +1,50 @@ +Include %syPrompt + +Class isc.git.Settings +{ + +/// List of extensions relevant to code load +Parameter EXT As List = {$lb("xml", "cls", "csp", "csr", "mac", "int", "bas", "inc", "gbl", "prj", "obj", "pkg", "gof", "dfi", "pivot", "dashboard")}; + +Parameter URL = "http://127.0.0.1:57772"; + +Parameter GLVN = "^isc.git.Settings"; + +/// Get setting +/// Получить настойку +/// write ##class(isc.git.Settings).getSetting("ext") +ClassMethod getSetting(name As %String) As %String [ CodeMode = expression ] +{ +$get(@..#GLVN@($zcvt(name, "l")), $parameter(,$zcvt(name, "U"))) +} + +/// Get setting +/// Установить настройку +/// write ##class(isc.git.Settings).setSetting("ext") +ClassMethod setSetting(name As %String = "", value As %String = "") As %Status +{ + #dim sc As %Status = $$$OK + + if name = "tests" { + // Path relative from the repo root to test suite + } elseif name = "ext" { + set:'$listValid(value) sc = $$$ERROR($$$GeneralError, "Extension list should be in $lb format.") + } elseif name = "commit" { + // TO-DO commit validation. + } elseif name = "init" { + set:$length(value, ":")'=2 sc = $$$ERROR($$$GeneralError, "Init should be in a format: 'class:method'") + } elseif name = "delete" { + set:$length(value, ":")'=2 sc = $$$ERROR($$$GeneralError, "Delete should be in a format: 'class:method'") + } elseif name = "url" { + // TO-DO url validation. + // "http://127.0.0.1:57772" + } else { + set sc = $$$ERROR($$$GeneralError, $$$FormatText("Setting '%1' does not exist", name)) + } + + set:$$$ISOK(sc) @..#GLVN@($zcvt(name, "l")) = value + return sc +} + +} + diff --git a/isc/git/Settings.cls.xml b/isc/git/Settings.cls.xml deleted file mode 100644 index 9534ad1..0000000 --- a/isc/git/Settings.cls.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - -%syPrompt -64700,83117.8258 - - - -List of extensions relevant to code load -List -$lb("xml", "cls", "csp", "csr", "mac", "int", "bas", "inc", "gbl", "prj", "obj", "pkg", "gof", "dfi", "pivot", "dashboard") - - - -http://127.0.0.1:57772 - - - -^isc.git.Settings - - - - -Get setting -Получить настойку -write ##class(isc.git.Settings).getSetting("ext") -1 -expression -name:%String -%String - - - - - -Get setting -Установить настройку -write ##class(isc.git.Settings).setSetting("ext") -1 -name:%String="",value:%String="" -%Status - - - - diff --git a/isc/util/OSUtils.cls b/isc/util/OSUtils.cls new file mode 100644 index 0000000..fdbd810 --- /dev/null +++ b/isc/util/OSUtils.cls @@ -0,0 +1,91 @@ +Class isc.util.OSUtils +{ + +/// Create file name +/// If name os empty then random file would be created in a Temp directrory +/// If name is an extension then new filename would be created +/// If name is a filename, then this file would be created +/// stream - %Stream.FileBinary pointing to this file +/// content - write something into a file. Can be a stream or a string +/// +/// Создать файл name +/// Если name не задан, то возвращается имя созданного файла (в папке Temp). +/// Если name - расширение, то возвращается имя созданного файла (в папке Temp) с заданным расширением. +/// stream - стрим файла +/// content - строка или stream который записывается в файл +ClassMethod createFile(ByRef name As %String = "", Output stream As %Stream.FileBinary, content As %String) As %Status +{ + #dim sc As %Status = $$$OK + + if name="" { + set name = ##class(%File).TempFilename() + } elseif $length(name, ".")=1 { + set name = ##class(%File).TempFilename(name) + } + + set stream = ##class(%Stream.FileBinary).%New() + set sc = stream.LinkToFile(name) + + if $data(content) { + if $isObject(content) { + set sc = stream.CopyFrom(content) + } else { + set sc = stream.Write(content) + } + quit:$$$ISERR(sc) sc + set sc = stream.%Save() + do stream.Rewind() + } + + quit sc +} + +/// Read file into string. Delete original file +/// Прочитать файл в строку +ClassMethod fileToString(name As %String, Output content As %String, delete As %Boolean = {$$$YES}) As %Status +{ + #dim sc As %Status = $$$OK + set stream = ##class(%Stream.FileBinary).%New() + set sc = stream.LinkToFile(name) + + set content = stream.Read($$$MaxStringLength) + + if delete { + kill stream + set sc = ..deleteFile(name) + } + + quit sc +} + +/// Delete file +/// Удалить файл +ClassMethod deleteFile(name As %String) As %Status +{ + #dim sc As %Status = $$$OK + set success = ##class(%File).Delete(name, .code) + set:success'=$$$YES sc = $$$ERROR($$$GeneralError, $$$FormatText("Error deleting file %1 with code %2", name, code)) + quit sc +} + +/// Execute OS command +/// Выполнить команду ОС +ClassMethod execute(cmd, debug As %Boolean = {$$$NO}) As %Status +{ + #dim sc As %Status = $$$OK + set code = "" + //set out = "" + write:debug !, "cmd: ", cmd + //set sc = ##class(%Net.Remote.Utility).RunCommandViaZF(cmd, , .out, timeout, $$$YES, .code) + set code = $zf(-1, cmd) + write:debug !,"code: ", code + + if code'=0 { + set sc1 = $$$ERROR($$$GeneralError, $$$FormatText("ОС command: `%1` exited with status: `%2`", cmd, code)) + set sc = $$$ADDSC(sc, sc1) + } + return sc +} + +} + diff --git a/isc/util/OSUtils.cls.xml b/isc/util/OSUtils.cls.xml deleted file mode 100644 index 1f6ed7f..0000000 --- a/isc/util/OSUtils.cls.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - -64700,72973.988557 - - - -Create file name -If name os empty then random file would be created in a Temp directrory -If name is an extension then new filename would be created -If name is a filename, then this file would be created -stream - %Stream.FileBinary pointing to this file -content - write something into a file. Can be a stream or a string - -Создать файл name -Если name не задан, то возвращается имя созданного файла (в папке Temp). -Если name - расширение, то возвращается имя созданного файла (в папке Temp) с заданным расширением. -stream - стрим файла -content - строка или stream который записывается в файл -1 - -%Status - - - - - -Read file into string. Delete original file -Прочитать файл в строку -1 -name:%String,*content:%String,delete:%Boolean=$$$YES -%Status - - - - - -Delete file -Удалить файл -1 -name:%String -%Status - - - - - -Execute OS command -Выполнить команду ОС -1 -cmd,debug:%Boolean=$$$NO -%Status - - - -