def upgrade_package(self, package): """ upgrade package, return True if upgraded """ if self.package_is_outdated(package): io.Print("brew upgrade {package}".format(**vars())) host.ShellCommand( "{self.BREW_BINARY} upgrade {package}".format(**vars())) return True
def install_package(self, package): """ install a package using homebrew, return True if installed """ if not self.package_is_installed(package): io.Print("brew install " + package) host.ShellCommand( "{self.BREW_BINARY} install {package}".format(**vars())) return True
def upgrade_cask(self, cask): """ upgrade a homebrew cask. does nothing if cask not installed """ if self.cask_is_outdated(cask): io.Print("brew cask upgrade {cask}".format(**vars())) host.ShellCommand( "{self.BREW_BINARY} cask upgrade {cask}".format(**vars())) return True
def install_cask(self, cask): """ install a homebrew cask, return True if installed """ if not self.cask_is_installed(cask): io.Print("brew cask install " + cask) host.ShellCommand( "{self.BREW_BINARY} cask install {cask}".format(**vars())) return True
def install_osx(): if not host.Which('brew'): io.Print("Installing Homebrew") url = 'https://raw.githubusercontent.com/Homebrew/install/master/install' host.ShellCommand( 'yes | /usr/bin/ruby -e "$(curl -fsSL {url})"'.format( **vars())) host.ShellCommand('brew doctor')
def MakeSymlink(src, dst, sudo=False): src = os.path.expanduser(src) dst = os.path.expanduser(dst) if src.startswith("/"): src_abs = src else: src_abs = os.path.dirname(dst) + "/" + src # Symlink already exists use_sudo = "sudo -H " if sudo else "" if (CheckShellCommand("{use_sudo}test -f '{dst}'".format(**vars())) or CheckShellCommand("{use_sudo}test -d '{dst}'".format(**vars()))): linkdest = ShellCommand( "{use_sudo}readlink {dst}".format(**vars())).rstrip() if linkdest.startswith("/"): linkdest_abs = linkdest else: linkdest_abs = os.path.dirname(dst) + "/" + linkdest if linkdest_abs == src_abs: return if not (CheckShellCommand("{use_sudo}test -f '{src_abs}'".format(**vars())) or CheckShellCommand( "{use_sudo}test -d '{src_abs}'".format(**vars()))): raise OSError("symlink source '{src}' does not exist".format(**vars())) # if CheckShellCommand("{use_sudo}test -d '{dst}'".format(**vars())): # raise OSError("symlink destination '{dst}' is a directory".format(**vars())) # Make a backup of existing file: if (CheckShellCommand("{use_sudo}test -f '{dst}'".format(**vars())) or CheckShellCommand("{use_sudo}test -d '{dst}'".format(**vars()))): ShellCommand("{use_sudo}mv '{dst}' '{dst}'.backup".format(**vars())) # in case of broken symlink ShellCommand("{use_sudo}rm -f '{dst}'".format(**vars())) # Create the symlink: io.Print("Creating symlink {dst}".format(**vars())) ShellCommand("{use_sudo}ln -s '{src}' '{dst}'".format(**vars()))
def uninstall_cask(self, cask): """ remove a homebrew cask, return True if uninstalled """ if self.cask_is_installed(cask): io.Print("brew cask remove " + cask) host.ShellCommand("{self.BREW_BINARY} cask remove " + cask) return True