File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 9
9
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
# See the License for the specific language governing permissions and
11
11
# limitations under the License.
12
+ import json
12
13
13
14
from testinfra .modules .base import Module
14
15
@@ -31,6 +32,7 @@ def is_installed(self):
31
32
32
33
- apk (Alpine)
33
34
- apt (Debian, Ubuntu, ...)
35
+ - brew (macOS)
34
36
- pacman (Arch, Manjaro )
35
37
- pkg (FreeBSD)
36
38
- pkg_info (NetBSD)
@@ -94,6 +96,8 @@ def get_module_class(cls, host):
94
96
return DebianPackage
95
97
if host .exists ("rpm" ):
96
98
return RpmPackage
99
+ if host .exists ("brew" ):
100
+ return HomebrewPackage
97
101
raise NotImplementedError
98
102
99
103
@@ -216,3 +220,20 @@ def version(self):
216
220
@property
217
221
def release (self ):
218
222
raise NotImplementedError
223
+
224
+
225
+ class HomebrewPackage (Package ):
226
+ @property
227
+ def is_installed (self ):
228
+ info = self .check_output ("brew info --formula --json %s" , self .name )
229
+ return len (json .loads (info )[0 ]["installed" ]) > 0
230
+
231
+ @property
232
+ def version (self ):
233
+ info = self .check_output ("brew info --formula --json %s" , self .name )
234
+ version = json .loads (info )[0 ]["installed" ][0 ]["version" ]
235
+ return version
236
+
237
+ @property
238
+ def release (self ):
239
+ raise NotImplementedError
You can’t perform that action at this time.
0 commit comments