def run(self): super(YumPackageTask, self).run() if self._action == PackageAction.UPDATE: return Run(['yum', 'update']).run() elif self._action == PackageAction.UPGRADE: return Run(['yum', 'upgrade', '-y'] + self._name).run() elif self._action == PackageAction.INSTALL: return Run(['yum', 'install', '-y'] + self._name).run() elif self._action == PackageAction.REMOVE: return Run(['yum', 'remove', '-y'] + self._name).run()
def run(self): super(HomebrewPackageTask, self).run() if self._action == PackageAction.UPDATE: return Run(['brew', 'update'], user=self._user).run() elif self._action == PackageAction.UPGRADE: return Run(['brew', 'upgrade'] + self._name, user=self._user).run() elif self._action == PackageAction.INSTALL: return Run(['brew', 'install'] + self._name, user=self._user).run() elif self._action == PackageAction.REMOVE: return Run(['brew', 'uninstall'] + self._name, user=self._user).run()
def run(self): super(CaskPackageTask, self).run() if self._action == PackageAction.UPDATE: logging.info('No update function for Cask. Ignoring.') elif self._action == PackageAction.UPGRADE: return Run(['brew', 'cask', 'upgrade'] + self._name, user=self._user).run() elif self._action == PackageAction.INSTALL: return Run(['brew', 'cask', 'install'] + self._name, user=self._user).run() elif self._action == PackageAction.REMOVE: return Run(['brew', 'cask', 'uninstall'] + self._name, user=self._user).run()
def run(self): super(MasPackageTask, self).run() if self._action == PackageAction.UPDATE: logging.info('No update function for app store. Ignoring.') elif self._action == PackageAction.UPGRADE: return Run(['mas', 'upgrade'] + self._name, user=self._user).run() elif self._action == PackageAction.INSTALL: return Run(['mas', 'install'] + self._name, user=self._user).run() elif self._action == PackageAction.REMOVE: raise Exception('No remove function for app store.') elif self._action == PackageAction.SIGNIN: return Run(['mas', 'signin'] + self._name, user=self._user, ignore_errors=True).run()
def run(self): super(AptPackageTask, self).run() if self._action == PackageAction.UPDATE: return Run(['apt-get', 'update']).run() elif self._action == PackageAction.UPGRADE: return Run( ['apt-get', 'upgrade', '-y', '--no-install-recommends'] + self._name).run() elif self._action == PackageAction.INSTALL: return Run( ['apt-get', 'install', '-y', '--no-install-recommends'] + self._name).run() elif self._action == PackageAction.REMOVE: return Run(['apt-get', 'remove', '-y'] + self._name).run()
def homebrew_install(user=None, force=False): if not os.path.exists('/usr/local/bin/brew') or force: logging.header('Install homebrew') brew_cmd = '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' Run(['bash', '-e'], stdin=brew_cmd, user=user).run() else: logging.info('Homebrew already installed.')
def testProcessInvalidCommand(self): with self.assertRaises(Exception): p = Run(['fjksdhfkljsahfjshaf']).run() self.assertJoinedEqual(p.commands, 'fjksdhfkljsahfjshaf', 'incorrect command') self.assertInJoinedEqual(p.output, 'No such file or directory', 'incorrect output')
def run(self): logging.header('File ' + self._extension + ' handled by ' + self._handler) file_handler_tool = self.__class__.file_handler_tool() if file_handler_tool == FiletypeHandlerType.DUTI: return Run(['duti', '-s', self._handler, self._extension, 'all']).run() raise Exception('No tool available for handling file types.')
def command(interpreter, commands, user=None, ignore_errors=False, action=CommandAction.RUN): if action == CommandAction.RUN: logging.header('Run ' + interpreter[0]) return Run(interpreter, stdin=commands, user=user, ignore_errors=ignore_errors).run() else: raise Exception('Invalid action')
def hostname(name, secure=False): logging.header('Hostname ' + name) Run(['hostnamectl', 'set-hostname', name]).run()
def testProcessErrorReturn(self): with self.assertRaises(subprocess.CalledProcessError): p = Run(['test', '-n', '']).run() self.assertJoinedEqual(p.commands, 'test -n ', 'incorrect command') self.assertJoinedEqual(p.output, '', 'incorrect output')
def testProcessStdin(self): p = Run(['cat'], stdin='hello\nwhatsup\nbye').run() self.assertJoinedEqual(p.commands, '(cat) hello(cat) whatsup(cat) bye', 'incorrect command') self.assertJoinedEqual(p.output, 'hellowhatsupbye', 'incorrect output')
def testProcessMultilineOutput(self): p = Run(['echo', 'hello\nbye']).run() self.assertJoinedEqual(p.commands, 'echo hello\nbye', 'incorrect command') self.assertJoinedEqual(p.output, 'hellobye', 'incorrect output')
def testProcessSimpleOutput(self): p = Run(['echo', 'hello']).run() self.assertJoinedEqual(p.commands, 'echo hello', 'incorrect command') self.assertJoinedEqual(p.output, 'hello', 'incorrect output')