How to use command_exists method in lisa

Best Python code snippet using lisa_python

setup.py

Source:setup.py Github

copy

Full Screen

...13IS_WORK_LAPTOP = host_name in ['C02RT09FG8WL-mackduan', 'C02FL7URMD6M-mackduan']14DIR_PATH = os.path.dirname(os.path.realpath(__file__))15def call_shell(command):16 return subprocess.call(command, shell=True)17def command_exists(command):18 return not call_shell('which {} > /dev/null'.format(command))19def path_exists(p):20 return os.path.exists(os.path.expanduser(p))21# region installations22def install_ag():23 if command_exists('ag'):24 return25 if IS_LINUX:26 call_shell('sudo apt-get install silversearcher-ag')27 elif IS_MAC:28 call_shell('brew install the_silver_searcher')29def install_fasd():30 if command_exists('fasd'):31 return32 if IS_LINUX:33 call_shell('sudo apt-get install fasd')34 elif IS_MAC:35 call_shell('brew install fasd')36def install_fzf():37 if command_exists('fzf'):38 return39 if IS_LINUX:40 call_shell(41 'rm ~/.fzf'42 ' && git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf'43 ' && ~/.fzf/install'44 )45 elif IS_MAC:46 call_shell('brew install fzf')47 call_shell('$(brew --prefix)/opt/fzf/install')48def install_google_cloud_sdk():49 if command_exists('gcloud'):50 return51 if not path_exists('~/google-cloud-sdk'):52 call_shell(53 'curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz'54 ' && tar -xzf /tmp/google-cloud-sdk.tar.gz --directory ~/'55 )56 call_shell('~/google-cloud-sdk/install.sh')57 print("Remember to run 'gcloud auth login'")58def install_tmux():59 if command_exists('tmux'):60 return61 if IS_LINUX:62 call_shell('sudo apt-get install tmux')63 elif IS_MAC:64 call_shell('brew install tmux')65def install_zsh():66 if command_exists('zsh'):67 return68 if IS_LINUX:69 call_shell('sudo apt-get install zsh')70 elif IS_MAC:71 call_shell('brew install zsh')72# endregion73# region mac installations74def install_homebrew():75 if command_exists('brew'):76 return77 call_shell('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')78def install_sleep_watcher():79 if not call_shell('brew ls | grep sleepwatcher'):80 return81 call_shell('brew install sleepwatcher')82 call_shell('brew services start sleepwatcher')83 print('Installed SleepWatcher. Remember to enable permissions in Security & Privacy')84def install_blueutil():85 if command_exists('blueutil'):86 return87 call_shell('brew install blueutil')88def install_jq():89 if command_exists('jq'):90 return91 call_shell('brew install jq')92def install_docker():93 if path_exists('/Applications/Docker.app'):94 return95 call_shell('brew install --cask docker')96# endregion97def script():98 additional_instructions = []99 if os.environ['USER'] == 'root':100 print('Do not run this script as root')101 sys.exit(1)102 response = input(103 'This script overwrite dotfiles in your home directory.'...

Full Screen

Full Screen

apt.py

Source:apt.py Github

copy

Full Screen

...5from provisioning import utils6@task(core.dotfiles)7def ag(c):8 "Install ag, an improved grep."9 if utils.command_exists(c, 'ag'):10 return11 utils.apt_install(c, "silversearcher-ag")12@task13def cmake(c):14 """Install cmake, a tool for building from source."""15 if utils.command_exists(c, 'cmake'):16 return17 utils.apt_install(c, ["build-essential", "cmake"])18@task19def git(c):20 "Install git, a version control system."21 if utils.command_exists(c, 'git'):22 return23 utils.apt_install(c, "git")24@task(git)25def git_init_submodules(c):26 "Initialize all submodules in this repository."27 utils.print_run(c, "git submodule update --init --recursive", hide="out")28@task29def htop(c):30 "Install htop, a nicer version of top."31 if utils.command_exists(c, 'htop'):32 return33 utils.apt_install(c, "htop")34@task35def keepass2(c):36 """Install Keepass2, a password storage app."""37 if utils.command_exists(c, 'keepass2'):38 return39 utils.apt_install(c, "keepass2")40@task41def maestral(c):42 """Install maestral, an open source Dropbox client."""43 if os.path.exists(os.path.expanduser('~/.local/bin/maestral')):44 return45 utils.pip_install(c, "maestral") # TODO(duckworthd): Re-enable maestral[gui] when "pip3 install PyQT5" works again.46 utils.print_run(c, "~/.local/bin/maestral autostart --yes", hide="out")47@task48def python3_dev(c):49 """Install Python 3 headers."""50 if utils.is_apt_installed(c, 'python3-dev'):51 return52 utils.apt_install(c, "python3-dev")53@task54def requests(c):55 """Install requests, a Python library for downloading URLs."""56 try:57 import requests58 return59 except ImportError:60 utils.pip_install(c, "requests")61@task62def xclip(c):63 "Install xclip, a tool for copying text from terminal to your clipboard."64 if utils.is_apt_installed(c, 'xclip'):65 return66 utils.apt_install(c, "xclip")67@task(git)68def fzf(c):69 """Install fzf, a fuzzy file finder."""70 if utils.command_exists(c, "fzf"):71 return72 if not os.path.exists(os.path.expanduser("~/.fzf")):73 utils.print_run(c, "git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf")74 utils.print_run(c, "~/.fzf/install --all")75@task(git_init_submodules, core.dotfiles, cmake, python3_dev)76def neovim(c):77 "Install neovim, a text editor."78 if utils.command_exists(c, 'nvim'):79 return80 utils.apt_install(c, ["neovim", "python3-neovim"])81 # Install plugins with vim-plug.82 print(colors.OKRED + "Run :PlugInstall the next time you open vim to install plugins." + colors.ENDC)83@task(requests)84def tmux(c):85 """Install tmux, a terminal multiplexer, from source."""86 if os.path.exists(os.path.expanduser("~/bin/tmux")):87 return88 import requests89 # install dependencies.90 utils.apt_install(c, [91 "libevent-dev",92 "ncurses-dev",93 "build-essential",94 "bison",95 "pkg-config",96 ])97 # Downlaod tarball.98 response = requests.get(99 "https://github.com/tmux/tmux/releases/download/3.1b/tmux-3.1b.tar.gz")100 tar_path = "/tmp/tmux.tar.gz"101 with open(tar_path, "wb") as tarfile:102 tarfile.write(response.content)103 # Extract its contents.104 utils.print_run(c, f"tar -zxf {tar_path} --directory /tmp", hide="out")105 with utils.chdir("/tmp/tmux-3.1b"):106 # Build it.107 utils.print_run(c, "./configure --enable-static", hide="out")108 utils.print_run(c, "make", hide="out")109 # Move it $HOME/bin.110 destination_dir = os.path.join(os.path.expanduser("~"), "bin")111 if not os.path.exists(destination_dir):112 os.makedirs(destination_dir)113 utils.print_run(c, f"cp ./tmux {destination_dir}/tmux", hide="out")114 print(colors.OKRED + "Run CTRL+b I the next time you open tmux to install plugins." + colors.ENDC)115@task(git_init_submodules, core.dotfiles)116def zsh(c):117 "Install zsh, an alternative to bash."118 if utils.command_exists(c, 'zsh'):119 return120 utils.apt_install(c, "zsh")121 utils.print_run(c, "chsh -s $(which zsh)")122@task(zsh)123def oh_my_zsh(c):124 """Installs oh-my-zsh, an extension suite for ZSH."""125 destination = os.path.expanduser("~/.oh-my-zsh")126 if os.path.exists(destination):127 return128 utils.print_run(c, 'sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"')129@task(oh_my_zsh, git)130def powerlevel10k(c):131 """Installs powerlevel10k, a theme for oh-my-zsh."""132 source = "https://github.com/romkatv/powerlevel10k.git"133 destination = os.path.expanduser("~/.oh-my-zsh/custom/themes/powerlevel10k")134 if os.path.exists(destination):135 return136 utils.print_run(c, f"git clone --depth=1 {source} {destination}", hide="out")137@task(oh_my_zsh, git)138def zsh_syntax_highlighting(c):139 """Installs zsh-syntax-highlighting, an extension for oh-my-zsh."""140 source = "https://github.com/zsh-users/zsh-syntax-highlighting.git"141 destination = os.path.expanduser("~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting")142 if os.path.exists(destination):143 return144 utils.print_run(c, f"git clone --depth=1 {source} {destination}", hide="out")145@task146def meld(c):147 """Installs meld, a 3-way merge tool."""148 if utils.command_exists(c, 'meld'):149 return...

Full Screen

Full Screen

util_test.py

Source:util_test.py Github

copy

Full Screen

1import argparse2import unittest3from sacrerouge.common.testing.util import command_exists4class TestUtil(unittest.TestCase):5 def test_command_exists(self):6 parser = argparse.ArgumentParser()7 assert command_exists(parser, ['test']) is False8 subparsers = parser.add_subparsers()9 assert command_exists(parser, ['test']) is False10 parser_A = subparsers.add_parser('A')11 parser_B = subparsers.add_parser('B')12 assert command_exists(parser, ['A'])13 assert command_exists(parser, ['B'])14 assert not command_exists(parser, ['C'])15 assert not command_exists(parser, ['B', 'C'])16 subparsers_B = parser_B.add_subparsers()17 parser_C = subparsers_B.add_parser('C')18 assert command_exists(parser, ['B', 'C'])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful