How to use check_directory_exists method in avocado

Best Python code snippet using avocado_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...8def get_version():9 print(get_distribution('py-gpgdir'))10def get_home_dir():11 return os.path.expanduser('~')12def check_directory_exists(dir, message):13 if not os.path.isdir(dir):14 raise Exception('[*] ' + message + ': ' + dir + ' does not exist.\n')15def get_gpg_dir():16 gpg_homedir = os.path.join(get_home_dir(), '.gnupg')17 check_directory_exists(gpg_homedir, 'GnuPG directory')18 return gpg_homedir19def get_key():20 gpgdirrc_file = os.path.join(get_home_dir(), '.py_gpgdirrc')21 if not os.path.isfile(gpgdirrc_file):22 print('[*] Please edit ' + gpgdirrc_file + ' to include your gpg key identifier')23 sys.exit(1)24 config = configparser.ConfigParser()25 config.read(gpgdirrc_file)26 return config['DEFAULT']['UseKey']27def clean_file(file):28 try:29 os.remove(file)30 except OSError:31 pass32def get_password():33 try:34 password = getpass.getpass()35 except Exception as error:36 print('Error getting password', error)37 else:38 return password39def encrypt_dir(dir_to_encrypt):40 check_directory_exists(dir_to_encrypt, 'Directory to encrypt')41 print('Encrypting dir: ' + dir_to_encrypt)42 gpg = gnupg.GPG(gnupghome=os.path.join(get_home_dir(), '.gnupg'), verbose=False)43 for file in glob.glob(os.path.join(dir_to_encrypt, '**/*'), recursive=True):44 if os.path.isfile(file):45 print('[+] encrypting: ' + file)46 with open(file, 'rb') as f:47 status = gpg.encrypt_file(48 file=f,49 recipients=[get_key()],50 output=file + '.gpg'51 )52 if status.ok:53 clean_file(file)54 else:55 print(status.stderr)56 sys.exit(1)57def decrypt_dir(dir_to_decrypt):58 check_directory_exists(dir_to_decrypt, 'Directory to decrypt')59 print('Decrypting dir: ' + dir_to_decrypt)60 os.system('gpgconf --reload gpg-agent')61 password = get_password()62 gpg = gnupg.GPG(gnupghome=os.path.join(get_home_dir(), '.gnupg'), verbose=False)63 for file in glob.glob(os.path.join(dir_to_decrypt, '**/*.gpg'), recursive=True):64 print('[+] decrypting: ' + file)65 with open(file, 'rb') as f:66 status = gpg.decrypt_file(67 file=f,68 passphrase=password,69 output=os.path.splitext(file)[0],70 )71 if status.ok:72 clean_file(file)73 else:74 print(status.stderr)75 sys.exit(1)76def sign_dir(dir_to_sign):77 check_directory_exists(dir_to_sign, 'Directory to sign')78 print('Signing dir: ' + dir_to_sign)79 os.system('gpgconf --reload gpg-agent')80 password = get_password()81 gpg = gnupg.GPG(gnupghome=os.path.join(get_home_dir(), '.gnupg'), verbose=False)82 for file in glob.glob(os.path.join(dir_to_sign, '**/*'), recursive=True):83 if os.path.isfile(file) and not (file.endswith('.gpg') or file.endswith('.sig')):84 print('[+] signing: ' + file)85 with open(file, 'rb') as f:86 gpg.sign_file(87 f,88 keyid=get_key(),89 passphrase=password,90 output=file + '.sig'91 )92def verify_dir(dir_to_verify):93 check_directory_exists(dir_to_verify, 'Directory to verify')94 print('Verifying dir: ' + dir_to_verify)95 gpg = gnupg.GPG(gnupghome=os.path.join(get_home_dir(), '.gnupg'), verbose=False)96 for file in glob.glob(os.path.join(dir_to_verify, '**/*'), recursive=True):97 if os.path.isfile(file) and file.endswith('.sig'):98 print('[+] verifying: ' + file)99 with open(file, 'rb') as f:100 verified = gpg.verify_file(f)101 if not verified:102 raise ValueError("Signature could not be verified!")103 else:...

Full Screen

Full Screen

test_default.py

Source:test_default.py Github

copy

Full Screen

...9 pass10 def check_package_installed(self, host, packages):11 for pkg in packages:12 assert host.package(pkg).is_installed13 def check_directory_exists(self, host, name):14 host.file("/home/divona/Applications/VSCode-linux-x64/").is_directory15class Archlinux(Distribution):16 def check_editors(self, host):17 self.check_package_installed(host, ["emacs"])18 self.check_package_installed(host, ["neovim"])19 self.check_directory_exists(20 host, "/home/divona/Applications/VSCode-linux-x64/")21class Debian(Distribution):22 def check_editors(self, host):23 self.check_package_installed(host, ["emacs"])24 self.check_package_installed(host, ["neovim"])25 self.check_directory_exists(26 host, "/home/divona/Applications/VSCode-linux-x64/")27class Centos(Distribution):28 def check_editors(self, host):29 self.check_package_installed(host, ["emacs"])30 self.check_package_installed(host, ["neovim"])31 self.check_directory_exists(32 host, "/home/divona/Applications/VSCode-linux-x64/")33class Fedora(Distribution):34 def check_editors(self, host):35 self.check_package_installed(host, ["emacs"])36 self.check_package_installed(host, [37 "neovim", "python2-neovim", "python3-neovim"])38 self.check_directory_exists(39 host, "/home/divona/Applications/VSCode-linux-x64/")40def _create_distribution(name):41 platform = None42 if name == "archlinux":43 platform = Archlinux()44 elif name == "debian":45 platform = Debian()46 elif name == "centos":47 platform = Centos()48 elif name == "fedora":49 platform = Fedora()50 return platform51def test_editors(host):52 distribution = _create_distribution(host.system_info.distribution)...

Full Screen

Full Screen

tl_dest.py

Source:tl_dest.py Github

copy

Full Screen

...14 '/mnt/timelapse/rafi',15 '/mnt/timelapse/zero',16 '/tmp/timelapse',17 '/mnt/pi_stick/timelapse')18def check_directory_exists(directory):19 '''Check directory exists'''20 if not os.path.exists(directory):21 msg = f'WARNING: The directory {directory} does not exist!'22 print('\n' + '=' * len(msg))23 print(msg)24 print('=' * len(msg))25def main():26 """Show and offer option to set the photos directory"""27 os.chdir(TIMELAPSE_CODE_PATH)28 if os.path.islink('timelapse_dir'):29 timelapse_dir = sp.check_output(['readlink', 'timelapse_dir'])30 timelapse_dir = timelapse_dir.strip().decode('utf-8')31 print('\nPhotos directory:', timelapse_dir)32 check_directory_exists(timelapse_dir)33 else:34 print('\nPhotos directory not set!')35 print('\nChoose photos directory or \'x\' to exit:\n')36 for index, menu_elem in enumerate(MENU):37 print(f'{index + 1}) {menu_elem}')38 print('x) Exit')39 while True:40 print('\nSelect photos directory:', end=' ', flush=True)41 option = getch()42 if option == 'x':43 sys.exit(0)44 elif option not in [str(nb + 1) for nb in range(len(MENU))]:45 print('Wrong option. Try again.')46 else:47 break48 option = int(option) - 149 sp.check_call(['rm', '-f', 'timelapse_dir'])50 timelapse_dir = MENU[option]51 sp.check_call(['ln', '-s', timelapse_dir, 'timelapse_dir'])52 print(f'\nPhotos directory set to {timelapse_dir}')53 check_directory_exists(timelapse_dir)54if __name__ == '__main__':...

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 avocado 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