-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor out homebrew utils and make better errors
Signed-off-by: Jade Abraham <[email protected]>
- Loading branch information
1 parent
9466a6a
commit 52dbae3
Showing
8 changed files
with
77 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
from utils import error, memoize, try_run_command | ||
|
||
@memoize | ||
def get_homebrew_prefix(pkg=None): | ||
""" | ||
If running on a system with Homebrew, return the Homebrew prefix. | ||
If not, return None. | ||
If pkg is provided, return the Homebrew prefix for that package. | ||
""" | ||
cmd = ['brew', '--prefix'] | ||
if pkg is not None: | ||
cmd.append(str(pkg)) | ||
exists, retcode, my_out, _ = try_run_command(cmd) | ||
if exists and retcode == 0: | ||
# Make sure to include homebrew search path | ||
homebrew_prefix = my_out.strip() | ||
return homebrew_prefix | ||
|
||
return None | ||
|
||
@memoize | ||
def homebrew_exists(): | ||
"""Check if Homebrew is installed on the system.""" | ||
return get_homebrew_prefix() is not None | ||
|
||
@memoize | ||
def homebrew_pkg_exists(pkg): | ||
"""Check if a Homebrew package is installed on the system.""" | ||
cmd = ['brew', 'list', pkg] | ||
exists, retcode, _, _ = try_run_command(cmd) | ||
return exists and retcode == 0 | ||
|
||
def _main(): | ||
sys.stdout.write("{0}\n".format(get_homebrew_prefix())) | ||
|
||
|
||
if __name__ == '__main__': | ||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters