Question
Arpitha Ramakri... · May 11, 2017

Compare and update two directories\namespaces for class files

Hi,

I would like to know if there is any code to compare and update two directories/namespaces for class files.
If file is present in directory1 and not present in diectory2, it should import the classfile.
If file is not present in directory1 and it is present in directory2, the corresponding file should be deleted from  directory2.

Please suggest code for the task.

Thanks,
Arpitha R

0
0 587
Discussion (2)3
Log in or sign up to continue

Have you considered implementing a Caché source code management tool such as Deltanji from George James Software, for whom I work? A Deltanji workflow can propagate code from one namespace to another, and can also propagate deletions. In other words, if you decommission a class in DEV, then propagate the now-decommissioned code object to TEST, the class will be deleted from TEST.

- If the two directories should have the same classes, you could use class mapping to point the two namespaces to the same code base ...

Beside getting a source code tool, there are several ways to compare  :

- If you want to write your own compare logic, you can use the %Dictionary.* classes (a lot of work,  since there are a lot of classes /properties to compare). Use this to get a list of classes in the two directories and to see which is missing.

- If you want to compare  two classes quick-and-dirty : you can have a look at the global ^oddDEF. It contains the class definition of all classes : methods, properties, indexes, storage etc. are all in this global. You could $ZOrder your way through the global and compare the two namespaces. But since this is internal stuff, it could change in new versions of Caché!

Here is an example, but test before you use it !!!

Class Utils.Classes
{

/// Compare two classes :
/// If ##class(Utils.Classes).Diff("USER","TEST","Data.MyClass", .reason) {
///   Write $List(reason, 1)," = ",$List(reason, 2) ;global from USER
///   Write $List(reason, 3)," = ",$List(reason, 4) ;global from TEST
/// } 
ClassMethod Diff(ns1 As %String, ns2 As %String, class As %String, ByRef reason As %String)
{
   Set diff = ..Diff1way(ns1, ns2, class, .reason)
   If 'diff Set diff = ..Diff1way(ns2, ns1, class, .reason)
   Quit diff
}

ClassMethod Diff1way(ns1 As %String, ns2 As %String, class As %String, ByRef reason As %String)
{
   Set diff = 0
   Set startref1="^["""_ns1_"""]oddDEF("""_class
   Set startref2="^["""_ns2_"""]oddDEF("""_class
   Set global1="^["""_ns1_"""]oddDEF("""_class_""")"
   For {
       Set global1=$ZOrder(@global1) Quit:global1=""  Quit:global1'[startref1
       Set data1=$Get(@global1)
       Set subs=$Piece(global1,class,2,*)
       Set global2=startref2_subs
       Set data2=$Get(@global2)
       If (subs=""",63)")!(subs=""",64)") Continue  ;properties time changed (63) & time created (64) can be different
       If data1'=data2 Set diff=1,reason=$lb(global1,data1,global2,data2) Quit
   }
   Quit diff
}

}