Best Python code snippet using autotest_python
data_dir.py
Source:data_dir.py
...7ROOT_DIR = os.path.abspath(_ROOT_PATH)8DATA_DIR = os.path.join(ROOT_DIR, 'shared', 'data')9TMP_DIR = os.path.join(ROOT_DIR, 'tmp')10BACKING_DATA_DIR = None11def get_backing_data_dir():12 if os.path.islink(DATA_DIR):13 if os.path.isdir(DATA_DIR):14 return os.readlink(DATA_DIR)15 else:16 # Invalid symlink17 os.unlink(DATA_DIR)18 elif os.path.isdir(DATA_DIR):19 return DATA_DIR20 try:21 return os.environ['VIRT_TEST_DATA_DIR']22 except KeyError:23 pass24 data_dir = '/var/lib/virt_test'25 if os.path.isdir(data_dir):26 try:27 fd, path = tempfile.mkstemp(dir=data_dir)28 os.close(fd)29 os.unlink(path)30 return data_dir31 except OSError:32 pass33 else:34 try:35 os.makedirs(data_dir)36 return data_dir37 except OSError:38 pass39 data_dir = os.path.expanduser('~/virt_test')40 if not os.path.isdir(data_dir):41 os.makedirs(data_dir)42 return os.path.realpath(data_dir)43def set_backing_data_dir(backing_data_dir):44 if os.path.islink(DATA_DIR):45 os.unlink(DATA_DIR)46 backing_data_dir = os.path.expanduser(backing_data_dir)47 if not os.path.isdir(backing_data_dir):48 os.makedirs(backing_data_dir)49 if not backing_data_dir == DATA_DIR:50 os.symlink(backing_data_dir, DATA_DIR)51BACKING_DATA_DIR = get_backing_data_dir()52set_backing_data_dir(BACKING_DATA_DIR)53def get_root_dir():54 return ROOT_DIR55def get_data_dir():56 return DATA_DIR57def get_tmp_dir():58 return TMP_DIR59if __name__ == '__main__':60 print "root dir: " + ROOT_DIR61 print "tmp dir: " + TMP_DIR62 print "data dir: " + DATA_DIR...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!