How to use get_assets_unused_for_days method in avocado

Best Python code snippet using avocado_python

asset.py

Source:asset.py Github

copy

Full Screen

...439 continue440 return asset_file441 raise OSError("File %s not found in the cache." % name)442 @classmethod443 def get_assets_unused_for_days(cls, days, cache_dirs):444 """Return a list of all assets in cache based on the access time.445 This will check if the file's data wasn't modified N days ago.446 :param days: how many days ago will be the threshold. Ex: "10" will447 return the assets files that *was not* accessed during448 the last 10 days.449 :param cache_dirs: list of directories to use during the search.450 """451 result = []452 for file_path in cls.get_all_assets(cache_dirs):453 stats = os.stat(file_path)454 diff = datetime.now() - datetime.fromtimestamp(stats.st_atime)455 if diff.days >= days:456 result.append(file_path)457 return result458 @classmethod459 def get_assets_by_size(cls, size_filter, cache_dirs):460 """Return a list of all assets in cache based on its size in MB.461 :param size_filter: a string with a filter (comparison operator +462 value). Ex ">20", "<=200". Supported operators:463 ==, <, >, <=, >=.464 :param cache_dirs: list of directories to use during the search.465 """466 try:467 op = re.match('^(\\D+)(\\d+)$', size_filter).group(1)468 value = int(re.match('^(\\D+)(\\d+)$', size_filter).group(2))469 except (AttributeError, ValueError):470 msg = ("Invalid syntax. You need to pass an comparison operatator",471 " and a value. Ex: '>=200'")472 raise OSError(msg)473 try:474 method = SUPPORTED_OPERATORS[op]475 except KeyError:476 msg = ("Operator not supported. Currented valid values are: ",477 ", ".join(SUPPORTED_OPERATORS))478 raise OSError(msg)479 result = []480 for file_path in cls.get_all_assets(cache_dirs):481 file_size = os.path.getsize(file_path)482 if method(file_size, value):483 result.append(file_path)484 return result485 @classmethod486 def remove_assets_by_overall_limit(cls, limit, cache_dirs):487 """This will remove assets based on overall limit.488 We are going to sort the assets based on the access time first.489 For instance it may be the case that a GitLab cache limit is 4490 GiB, in that case we can sort by last access, and remove all491 that exceeds 4 GiB (that is, keep the last accessed 4 GiB worth492 of cached files).493 Note: during the usage of this method, you should use bytes as limit.494 :param limit: a integer limit in bytes.495 :param cache_dirs: list of directories to use during the search.496 """497 size_sum = 0498 for asset in cls.get_all_assets(cache_dirs):499 size_sum += os.stat(asset).st_size500 if size_sum >= limit:501 cls.remove_asset_by_path(asset)502 @classmethod503 def remove_assets_by_size(cls, size_filter, cache_dirs):504 for file_path in cls.get_assets_by_size(size_filter, cache_dirs):505 cls.remove_asset_by_path(file_path)506 @classmethod507 def remove_assets_by_unused_for_days(cls, days, cache_dirs):508 for file_path in cls.get_assets_unused_for_days(days, cache_dirs):509 cls.remove_asset_by_path(file_path)510 @property511 def name_scheme(self):512 """This property will return the scheme part of the name if is an URL.513 Otherwise, will return None.514 """515 parsed = self.parsed_name516 if parsed:517 return parsed.scheme518 @property519 def name_url(self):520 """This property will return the full url of the name if is an URL.521 Otherwise, will return None.522 """...

Full Screen

Full Screen

assets.py

Source:assets.py Github

copy

Full Screen

...427 cache_dirs = config.get("datadir.paths.cache_dirs")428 try:429 assets = None430 if days is not None:431 assets = Asset.get_assets_unused_for_days(days, cache_dirs)432 elif size_filter is not None:433 assets = Asset.get_assets_by_size(size_filter, cache_dirs)434 elif assets is None:435 assets = Asset.get_all_assets(cache_dirs)436 except (FileNotFoundError, OSError) as e:437 LOG_UI.error("Could get assets: %s", e)438 return exit_codes.AVOCADO_FAIL439 matrix = []440 for asset in assets:441 stat = os.stat(asset)442 basename = os.path.basename(asset)443 hash_path = f"{asset}-CHECKSUM"444 atime = datetime.fromtimestamp(stat.st_atime)445 _, checksum = Asset.read_hash_from_file(hash_path)...

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