Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrite homebrew updater in Python.
  • Loading branch information
Kevin Deldycke committed Jul 5, 2016
1 parent 09bf4c3 commit bfcc51e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 24 deletions.
23 changes: 0 additions & 23 deletions dotfiles-osx/.bitbar/brew.1d.sh

This file was deleted.

85 changes: 85 additions & 0 deletions dotfiles-osx/.bitbar/brew.7h.py
@@ -0,0 +1,85 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>PackageManager</bitbar.title>
# <bitbar.version>v1.0.0</bitbar.version>
# <bitbar.author>Kevin Deldycke</bitbar.author>
# <bitbar.author.github>kdeldycke</bitbar.author.github>
# <bitbar.desc>List available updates and allows individual or full upgrades.
# </bitbar.desc>
# <bitbar.dependencies>python,homebrew</bitbar.dependencies>
# <bitbar.image></bitbar.image>

from __future__ import print_function, unicode_literals

from subprocess import Popen, PIPE
import sys
import json


BREW_CLI = '/usr/local/bin/brew'


def repo_sync():
""" Sync reporitories, exits right away on error. """
_, error = Popen(
[BREW_CLI, 'update'],
stdout=PIPE).communicate()

if error:
print("Error | color=red")
sys.exit(error)


def list_updates():
""" List available updates. """
output, error = Popen(
[BREW_CLI, 'outdated', '--json=v1'],
stdout=PIPE).communicate()

if error:
return

updates = json.loads(output)

# Only keeps the highest installed version.
for package in updates:
yield {
'name': package['name'],
'installed_version': max(package['installed_versions']),
'latest_version': package['current_version']}


def print_menu():
""" Print menu structure using BitBar's plugin API.
See: https://github.com/matryer/bitbar#plugin-api
"""
# Update repositories.
repo_sync()

# List available updates.
updates = list(list_updates())

# Print menu bar icon with number of available updates.
print(("↑{} | dropdown=false".format(len(updates))).encode('utf-8'))

# Print the dropdown menu's content.
print("---")

print("{} Homebrew packages".format(len(updates)))

if updates:
print(
"Upgrade all | "
"bash={} param1=upgrade param2=--cleanup "
"terminal=false refresh=true".format(
BREW_CLI))

for package in updates:
print((
"{name} {installed_version} → {latest_version} | "
"bash={cli} param1=upgrade param2=--cleanup param3={name} "
"terminal=false refresh=true".format(
cli=BREW_CLI, **package)).encode('utf-8'))

print_menu()
1 change: 0 additions & 1 deletion scripts/osx-install.sh
Expand Up @@ -175,7 +175,6 @@ wget -O - "https://get.popcorntime.sh/build/Popcorn-Time-0.3.9-Mac.tar.xz" | tar
brew cask install bitbar
defaults write com.matryer.BitBar pluginsDirectory "~/.bitbar"
wget -O "${HOME}/.bitbar/btc.17m.sh" https://github.com/matryer/bitbar-plugins/raw/master/Bitcoin/bitfinex.com/bitfinex_btcusd.sh
wget -O "${HOME}/.bitbar/brew.1d.sh" https://github.com/matryer/bitbar-plugins/raw/master/Dev/Homebrew/brew-updates.1h.sh
wget -O "${HOME}/.bitbar/cask.1d.sh" https://github.com/matryer/bitbar-plugins/raw/master/Dev/Homebrew/homebrewcask.1d.sh
wget -O "${HOME}/.bitbar/netinfo.3m.sh" https://github.com/matryer/bitbar-plugins/raw/master/Network/netinfo.60s.sh
wget -O "${HOME}/.bitbar/disk.13m.sh" https://github.com/matryer/bitbar-plugins/raw/master/System/mdf.1m.sh
Expand Down

0 comments on commit bfcc51e

Please sign in to comment.