specinfra 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7217cd76bb32ea14d335ad1f82a572c5e5a67f82
4
- data.tar.gz: d1fde8f39d7c4af54603e79275f595d0aaed0fd8
3
+ metadata.gz: 3fbfc9272049c0efc0e7b3430719d72547ec5bd1
4
+ data.tar.gz: 16b88cf1fd04e29eff60421b60f688fe80496948
5
5
  SHA512:
6
- metadata.gz: 066e834d27e47eefe0e332808d529dd1bf1a48f845859edf31e9fd97b392add75c7058307f3b204b824af3448c191098c389330dbfa7a9dae4417ceff8a85567
7
- data.tar.gz: d23345ce8d33603f067a107f559506058926a0a0ec0423c8837e5853c87cefd0ae31b9522971a18ea1d3f133d2f837142f8b70bf2018cc3fe2d854b95d50a164
6
+ metadata.gz: 065a3f9ece6c188b117a378e826a5b1b7aaabb2f7b17f67c07a9e4fa5bb999fb8d8f3e91e72763e6ae5119a3b0c0485b0b17867109159b18adc7fdf9e854acf8
7
+ data.tar.gz: 565a0f1febe195e6cdbe6cab501e1cdf88cfa2c92dcd7c0469e215f4c9b29f91e8075b67a1e987999ac1042fd8e54022453ff5c6e29616026736895e1af76343
@@ -1,26 +1,45 @@
1
1
  function ListWindowsFeatures
2
2
  {
3
- $cachepath = "${env:temp}/ListWindowsFeatures.xml"
3
+
4
+ param(
5
+ [string]$feature,
6
+ [string]$provider="dism"
7
+ )
8
+
9
+ $cachepath = "${env:temp}/ListWindowsFeatures-${provider}.xml"
4
10
  $maxAge = 2
5
11
 
6
12
  $cache = Get-Item $cachepath -erroraction SilentlyContinue
7
13
 
8
14
  if($cache -ne $null -and ((get-date) - $cache.LastWriteTime).minutes -lt $maxage){
9
- return Import-Clixml $cachepath
15
+ $features = Import-Clixml $cachepath | Select *| Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and (($_.installed -eq $true) -or ($_.state -eq "Enabled"))}
16
+ return $features
10
17
  }
11
18
  else{
12
- try
19
+
20
+ switch($provider)
13
21
  {
14
- $dism = DISM /Online /Get-Features /Format:List | Where-Object {$_}
22
+ "dism" { return features_dism | Select * | Where-Object {($_.name -eq $feature) -and ($_.state -eq "Enabled")} }
23
+ "powershell" { return features_powershell | Select * | Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and ($_.installed -eq $true)} }
24
+ default {throw "Unsupported provider"}
25
+ }
26
+
27
+ }
28
+ }
29
+
30
+ function features_dism{
31
+ try
32
+ {
33
+ $out = DISM /Online /Get-Features /Format:List | Where-Object {$_}
15
34
 
16
35
  if($LASTEXITCODE -ne 0)
17
36
  {
18
- Write-Error $dism
37
+ Write-Error $out
19
38
  Break
20
39
  }
21
40
 
22
- $f = $dism[4..($dism.length-2)]
23
- $feature = for($i=0; $i -lt $f.length;$i+=2)
41
+ $f = $out[4..($out.length-2)]
42
+ $features = for($i=0; $i -lt $f.length;$i+=2)
24
43
  {
25
44
  $tmp = $f[$i],$f[$i+1] -replace '^([^:]+:\s)'
26
45
 
@@ -30,14 +49,20 @@ function ListWindowsFeatures
30
49
  }
31
50
  }
32
51
 
33
- $feature | Export-Clixml $cachepath
52
+ $features | Export-Clixml $cachepath
34
53
 
35
- return $feature
54
+ return $features
36
55
  }
37
56
  catch
38
57
  {
39
58
  Throw
40
59
  }
60
+ }
41
61
 
42
- }
62
+ function features_powershell{
63
+ $ProgressPreference = "SilentlyContinue"
64
+ import-module servermanager
65
+ $features = Get-WindowsFeature
66
+ $features | Export-Clixml $cachepath
67
+ return Get-WindowsFeature
43
68
  }
@@ -203,13 +203,23 @@ module SpecInfra
203
203
  end
204
204
  end
205
205
 
206
- def check_windows_feature_enabled(name)
207
-
208
- Backend::PowerShell::Command.new do
209
- using 'list_windows_features.ps1'
210
- exec "@(ListWindowsFeatures | Where-Object {($_.name -eq '#{name}') -and ($_.State -eq 'enabled')}).count -gt 0"
211
- end
206
+ def check_windows_feature_enabled(name,provider)
212
207
 
208
+ if provider.nil?
209
+ cmd = "@(ListWindowsFeatures -feature #{name}).count -gt 0"
210
+ else
211
+ cmd = "@(ListWindowsFeatures -feature #{name} -provider #{provider}).count -gt 0"
212
+ end
213
+
214
+ Backend::PowerShell::Command.new do
215
+ using 'list_windows_features.ps1'
216
+ exec cmd
217
+ end
218
+ end
219
+
220
+ def check_file_version(name,version)
221
+ cmd = "((Get-Command '#{name}').FileVersionInfo.ProductVersion -eq '#{version}') -or ((Get-Command '#{name}').FileVersionInfo.FileVersion -eq '#{version}')"
222
+ Backend::PowerShell::Command.new { exec cmd }
213
223
  end
214
224
 
215
225
  private
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita