Skip to content

Commit

Permalink
feat: brew support
Browse files Browse the repository at this point in the history
  • Loading branch information
soof-golan authored and philpep committed Nov 13, 2023
1 parent 5af81c8 commit 70554d3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions testinfra/modules/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json

from testinfra.modules.base import Module

Expand All @@ -31,6 +32,7 @@ def is_installed(self):
- apk (Alpine)
- apt (Debian, Ubuntu, ...)
- brew (macOS)
- pacman (Arch, Manjaro )
- pkg (FreeBSD)
- pkg_info (NetBSD)
Expand Down Expand Up @@ -94,6 +96,8 @@ def get_module_class(cls, host):
return DebianPackage
if host.exists("rpm"):
return RpmPackage
if host.exists("brew"):
return HomebrewPackage
raise NotImplementedError


Expand Down Expand Up @@ -216,3 +220,20 @@ def version(self):
@property
def release(self):
raise NotImplementedError


class HomebrewPackage(Package):
@property
def is_installed(self):
info = self.check_output("brew info --formula --json %s", self.name)
return len(json.loads(info)[0]["installed"]) > 0

@property
def version(self):
info = self.check_output("brew info --formula --json %s", self.name)
version = json.loads(info)[0]["installed"][0]["version"]
return version

@property
def release(self):
raise NotImplementedError

0 comments on commit 70554d3

Please sign in to comment.