functions/process-map.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
function import-map {
    [cmdletbinding()]
    param([Parameter(Mandatory=$true)] $maps)
    
    if ($maps -is [System.Collections.IDictionary] ) {
        return import-mapobject $maps
    }    
    else {
        return import-mapfile $maps
    }
}

function import-mapfile {
    [cmdletbinding()]
    param([Parameter(Mandatory=$true)] $maps)

    write-verbose "processing publishmap..."

    if ($null -ne $maps) {
        $maps = @($maps)
    }
        
    $publishmap = @{}

    foreach($m in $maps) {
        $publishmap += import-singlemapfile $m
    }

    write-verbose "processing publishmap... DONE"

    return $publishmap
}


function import-mapobject { 
[cmdletbinding()]
param([Parameter(Mandatory=$true)] $map) 
   $pmap = @{}
    
   $pmap = import-genericgroup $map ""   
   $pmap = add-metaproperties $pmap ""
   return $pmap
}

function import-singlemapfile($file) {
    $fullname = $file
    if ($null -ne $fullname.FullName) { $Fullname =$Fullname.FullName }
    $map = & "$FullName"
    
    #$publishmap_obj = ConvertTo-Object $publishmap
    $pmap = import-mapobject $map

   return $pmap
}


function import-genericgroup($group,
    $fullpath, 
    $settings = $null,
    $settingskey = "settings",
    $specialkeys = @("settings", "global_profiles")
) {
    Write-Verbose "processing map path $fullpath"
   
    $result = {}        

    # only direct children inherit settings
    $onelevelsettingsinheritance = $true

    $childsettings = $null 
    #get settings for children
    if ($null -ne $group.$settingskey) {
        $childsettings = $group.$settingskey
    } else {
        if (!$onelevelsettingsinheritance) {
            $childsettings = $settings
        }
    }
    
    <#
    if ($null -ne $settings) {
        inherit-globalsettings $group $settings
    }
    #>


    $keys = get-propertynames $group
    foreach($projk in $keys) {
        #do not process special global settings
        if ($projk -in $specialkeys) {
            continue
        }
        $subgroup = $group.$projk
        if (!($subgroup -is [System.Collections.IDictionary])) {
            continue
        }
        $path = "$fullpath.$projk"            


        inherit-properties -from $group -to $subgroup -valuesonly
        # this should be run only once per group, right?
        # why is this needed here?
        if ($null -ne $settings) {
                inherit-globalsettings $group $settings
        }
        $r = import-genericgroup $subgroup $path -settings $childsettings -settingskey $settingskey -specialkeys $specialkeys
    }
        


    if ($null -ne $settings) {
        inherit-globalsettings $group $settings
        
      <# $keys = get-propertynames $group
        foreach($projk in $keys) {
            $subgroup = $group.$projk
            if ($projk -in $specialkeys) {
                continue
            }
            if (!($subgroup -is [System.Collections.IDictionary])) {
                continue
            }
            inherit-properties -from $group -to $subgroup -valuesonly
        }
        #>

    }
    
    

    return $map
}

function add-metaproperties($group, $fullpath, $specialkeys = @("settings", "global_profiles")
) {
    if ($group -isnot [System.Collections.IDictionary]) {
        return
    }
    $splits = $fullpath.split('.')
    $level = $splits.length - 1
    
    $null = $group | add-property -name _level -value $level
    $null = $group | add-property -name _fullpath -value $fullpath.trim('.')
    if ($splits.length -gt 0) {
        $null = $group | add-property -name _name -value $splits[$splits.length - 1]
    }

      $keys = get-propertynames $group

        
    foreach($projk in $keys) {
     #do not process special global settings
        if ($projk -in $specialkeys) {
                continue
        }
        $path = "$fullpath.$projk"
        $null = add-metaproperties $group.$projk $path -specialkeys $specialkeys
    }
  
    return $group
}

<#
function import-mapgroup(
    $publishmapgroup, $groupk,
    $settings = $null,
    $stripsettingswrapper = $false
) {
    Write-Verbose "processing map $groupk"
   
    $keys = get-propertynames $publishmapgroup
    
    $null = add-property $publishmapgroup "level" 1
    $null = add-property $publishmapgroup -name fullpath -value "$groupk"
    
    $group = $publishmapgroup
    $result = {}
    foreach($projk in $keys) {
            #do not process special global settings
            if ($projk -in "settings","global_profiles") {
                continue
            }
            $proj = $group.$projk
            $r = import-mapproject $proj $projk $level
            
            $null = add-property $proj "level" 2
            $null = add-property $proj -name fullpath -value "$groupk.$projk"
                       
        }

    return $publishmapgroup
}

#>

<#

#>