How to use _package_exists method in lisa

Best Python code snippet using lisa_python

healthcheck.py

Source:healthcheck.py Github

copy

Full Screen

...123def check_website_availability(host):124 # Only ping the website if it is reachable.125 if _check_website_reachable(host):126 _check_ping_time(host)127def _package_exists(package):128 try:129 import_module(package)130 return True131 except ImportError:132 return False133def check_package(package):134 logger.info("Checking {}...".format(package))135 # Check if the package is installed at all136 if not _package_exists(package):137 logger.error("CAN NOT FIND {}".format(package))138 return139 logger.info("{} is available on this machine".format(package))140 # Check the version (only if the version number was specified, otherwise141 # we are not interested in a specific version.142 if PACKAGES_TO_BE_CHECKED[package] is not None:143 check_package_version(package)144 # Special case for our analytics library145 if package == "IxionAnalytics":146 _check_ixion_analytics_version()147def check_package_version(package):148 logger.info("Checking {} version...".format(package))149 if not _package_exists('pkg_resources'):150 logger.error("pkg_resources package not installed.")151 return152 import pkg_resources153 try:154 # Get the version of the package installed by setuptools. Note: This155 # might not match the version that is actually used.156 installed = pkg_resources.get_distribution(package).version157 if installed == PACKAGES_TO_BE_CHECKED[package]:158 logger.info("Version {} installed and used.".format(installed))159 else:160 logger.error('OLD VERSION USED?!')161 except pkg_resources.DistributionNotFound:162 logger.warning("CAN NOT VERIFY THE VERSION OF {}.".format(package))163def _check_ixion_analytics_version():164 logger.info("Checking IxionAnalyitcs version specific...")165 if not _package_exists("IxionAnalytics"):166 logger.error("IxionAnalytics does not exist.")167 return168 import IxionAnalytics169 # double check if the newest version is also the default version (in170 # case it got messed up with different Python versions). If it is an171 # old version the method 'track_interaction' won't exist. In future I172 # will add a __version__ flag to the analytics library to make that173 # more clear and clean.174 newest_version_used = 'track_interaction' in dir(IxionAnalytics)175 if newest_version_used:176 logger.info("Newest version of IxionAnalyitcs used.")177 else:178 logger.error('Old version of IxionAnalyitcs used.')179def _check_if_yarely_config_exists():180 return os.path.exists(YARELY_CONFIG)181def _get_config_item(section, option, fallback):182 cfg = configparser.ConfigParser()183 cfg.read(YARELY_CONFIG)184 return cfg.get(section, option, fallback=fallback)185def _get_display_type():186 return _get_config_item('DisplayDevice', 'devicetype', fallback='sony')187def _get_serial_name():188 return _get_config_item(189 'DisplayDevicess', 'displaydeviceserialusbname', fallback=None190 )191def check_display_power_status():192 logger.info("Checking display power status...")193 if not _package_exists("serial"):194 logger.warning(195 "CAN NOT CHECK DISPLAY STATUS BECAUSE serial PACKAGE IS MISSING."196 )197 return198 logger.info("Checking if Yarely config exists...")199 if not _check_if_yarely_config_exists():200 logger.error("CAN NOT FIND YARELY CONFIG!")201 return202 display = _get_display_type() # sony, lg, projector, etc.203 logger.info("Using display type: {}".format(display))204 script_name = display + DISPLAY_DEVICE_DRIVER_SUFFIX205 path_to_script = os.path.join(206 YARELY_DIR, 'core', 'scheduler', script_name207 )...

Full Screen

Full Screen

driver.py

Source:driver.py Github

copy

Full Screen

...12 self._client = self._s3.meta.client13 def download_package(self, group: str, artifact: str, version: str,14 tmp_artifact_dir: str, output: AbstractOutputWriter):15 # check that package exists in the repository16 package_exists = self._package_exists(group, artifact, version)17 if not package_exists:18 raise PackageNotFoundError()19 # download an archive20 s3_path = self._get_s3_artifact_path(group, artifact, version)21 archive_path = os.path.join(tmp_artifact_dir, 'package.zip')22 try:23 self._s3.Bucket(self._root).download_file(s3_path, archive_path)24 except ClientError as e:25 raise DriverError('Download Error: %s' % e.response['Error']['Message'])26 # unarchive a package27 unpack_archive(archive_path, tmp_artifact_dir)28 # remove an archive29 os.remove(archive_path)30 def upload_package(self, group: str, artifact: str, version: str,31 tmp_artifact_dir: str, output: AbstractOutputWriter):32 # check that this version of the package doesn't exist in the repository33 package_exists = self._package_exists(group, artifact, version)34 if package_exists:35 raise VersionExistsError()36 # archive a package37 archive_path = os.path.join(tmp_artifact_dir, 'package.zip')38 pack_archive(tmp_artifact_dir, archive_path)39 # upload an archive to S340 s3_path = self._get_s3_artifact_path(group, artifact, version)41 try:42 self._client.upload_file(archive_path, self._root, s3_path)43 except ClientError as e:44 raise DriverError('Upload Error: %s' % e.response['Error']['Message'])45 # remove an archive46 os.remove(archive_path)47 def _package_exists(self, group: str, artifact: str, version: str) -> bool:48 path = self._get_s3_artifact_path(group, artifact, version)49 exists = True50 try:51 self._client.head_object(Bucket=self._root, Key=path)52 except ClientError as e:53 if e.response['Error']['Code'] == '404':54 exists = False55 elif e.response['Error']['Code'] == '403':56 raise ReadAccessError()57 else:58 raise DriverError(e.response['Error']['Message'])59 return exists60 @staticmethod61 def _get_s3_artifact_path(group: str, artifact: str, version: str):...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

1from pkg_resources import DistributionNotFound, get_distribution2from setuptools import setup3with open("README.md", encoding="utf-8") as f:4 long_description = "\n" + f.read()5def _package_exists(name: str) -> bool:6 """Check whether package is installed."""7 try:8 get_distribution(name)9 except DistributionNotFound:10 return False11 else:12 return True13def _get_tensorflow_requirement():14 """Avoid re-download and mis-detection of a package."""15 lower = 2.216 upper = 2.617 if _package_exists("tensorflow-cpu"):18 return [f"tensorflow-cpu>={lower},<{upper}"]19 elif _package_exists("tensorflow-gpu"):20 return [f"tensorflow-gpu>={lower},<{upper}"]21 else:22 return [f"tensorflow>={lower},<{upper}"]23setup(24 name="mlp-mixer-keras",25 version="0.1",26 description="A Keras re-implementation of MLP-Mixer models.",27 long_description=long_description,28 long_description_content_type="text/markdown",29 url="https://github.com/sebastian-sz/mlp-mixer-keras",30 author="Sebastian Szymanski",31 author_email="mocart15@gmail.com",32 license="Apache",33 python_requires=">=3.6.0,<3.10",...

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