# Path: biggraphite/metadata_cache.py
# METRICS_LABELS = ["type", "name"]
# CACHE_SIZE = prometheus_client.Gauge("bg_cache_size", "Current size", METRICS_LABELS)
# CACHE_MAX_SIZE = prometheus_client.Gauge("bg_cache_maxsize", "Max size", METRICS_LABELS)
# CACHE_HITS = prometheus_client.Counter(
#     "bg_cache_hits_total", "Cache hits", METRICS_LABELS
# )
# CACHE_MISSES = prometheus_client.Counter(
#     "bg_cache_misses_total", "Cache misses", METRICS_LABELS
# )
#     TYPE = "abstract"
#     TYPE = "memory"
#     TYPE = "disk"
#     __SINGLETONS = {}
#     __SINGLETONS_LOCK = threading.Lock()
#     _MAX_READERS = 2048
#     _METRIC_SEPARATOR = "|"
#     _EMPTY = b"nil"
#     MAP_SIZE = 1024 * 1024 * 1024 * 16 if sys.maxsize > 2 ** 32 else 1024 * 1024 * 1024
# class Error(Exception):
# class InvalidArgumentError(Error):
# class MetadataCache(object):
# class MemoryCache(MetadataCache):
# class DiskCache(MetadataCache):
# class NoneCache(MetadataCache):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def __enter__(self):
#     def __exit__(self, typ, value, traceback):
#     def close(self):
#     def hit_count(self):
#     def miss_count(self):
#     def cache_has(self, metric_name):
#     def cache_drop(self, metric_name):
#     def cache_set(self, metric_name, metric):
#     def create_metric(self, metric, metric_name=None):
#     def has_metric(self, metric_name):
#     def get_metric(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def metadata_from_str(self, metadata_str):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#         def _timer():
#     def close(self):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def _cache_drop(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def _repair(self, start_key, end_key, shard, nshards, callback_on_progress):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def _cache_has(self, metric_name):
#     def __expired_timestamp(self, timestamp):
#     def _encode(self, value):
#     def _decode(self, value):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __value_from_strings(self, metric_id, metric_metadata):
#     def __value_from_metric(self, metric):
#     def __split_payload(self, payload):
#     def clean(self):
#     def _clean_some(self, txn, cursor, cutoff):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def clean(self):
#     def repair(self, start_key=None, end_key=None, shard=0, nshards=1, callback_on_progress=None):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


import logging
import os
import sys
import time
import progressbar
from biggraphite import metadata_cache
from biggraphite.cli import command
from prometheus_client import write_to_textfile, REGISTRY
                ' ',
                progressbar.AdaptiveETA(),
            ]

            # max_value = end_key - start_key
            self.pbar = progressbar.ProgressBar(
                widgets=widgets,
                fd=out_fd,
                redirect_stderr=False,
                min_value=0,
                max_value=end_key - start_key)

        self.pbar.start()

        if on_progress is None:
            def _on_progress(total, done, token):
                self.pbar.update(total, token=token)

                if self.metrics_file_path != "":
                    write_to_textfile(self.metrics_file_path, REGISTRY)

            on_progress = _on_progress

        accessor.connect()

        if opts.clean_cache:
            if opts.storage_dir:
                settings = {"path": opts.storage_dir, "ttl": opts.max_age}

                logging.info("Cleaning cache from %s", settings)

# Path: biggraphite/metadata_cache.py
# METRICS_LABELS = ["type", "name"]
# CACHE_SIZE = prometheus_client.Gauge("bg_cache_size", "Current size", METRICS_LABELS)
# CACHE_MAX_SIZE = prometheus_client.Gauge("bg_cache_maxsize", "Max size", METRICS_LABELS)
# CACHE_HITS = prometheus_client.Counter(
#     "bg_cache_hits_total", "Cache hits", METRICS_LABELS
# )
# CACHE_MISSES = prometheus_client.Counter(
#     "bg_cache_misses_total", "Cache misses", METRICS_LABELS
# )
#     TYPE = "abstract"
#     TYPE = "memory"
#     TYPE = "disk"
#     __SINGLETONS = {}
#     __SINGLETONS_LOCK = threading.Lock()
#     _MAX_READERS = 2048
#     _METRIC_SEPARATOR = "|"
#     _EMPTY = b"nil"
#     MAP_SIZE = 1024 * 1024 * 1024 * 16 if sys.maxsize > 2 ** 32 else 1024 * 1024 * 1024
# class Error(Exception):
# class InvalidArgumentError(Error):
# class MetadataCache(object):
# class MemoryCache(MetadataCache):
# class DiskCache(MetadataCache):
# class NoneCache(MetadataCache):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def __enter__(self):
#     def __exit__(self, typ, value, traceback):
#     def close(self):
#     def hit_count(self):
#     def miss_count(self):
#     def cache_has(self, metric_name):
#     def cache_drop(self, metric_name):
#     def cache_set(self, metric_name, metric):
#     def create_metric(self, metric, metric_name=None):
#     def has_metric(self, metric_name):
#     def get_metric(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def metadata_from_str(self, metadata_str):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#         def _timer():
#     def close(self):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def _cache_drop(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def _repair(self, start_key, end_key, shard, nshards, callback_on_progress):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def _cache_has(self, metric_name):
#     def __expired_timestamp(self, timestamp):
#     def _encode(self, value):
#     def _decode(self, value):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __value_from_strings(self, metric_id, metric_metadata):
#     def __value_from_metric(self, metric):
#     def __split_payload(self, payload):
#     def clean(self):
#     def _clean_some(self, txn, cursor, cutoff):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def clean(self):
#     def repair(self, start_key=None, end_key=None, shard=0, nshards=1, callback_on_progress=None):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


# Path: biggraphite/cli/command_clean.py
import logging
import os
import sys
import time
import progressbar
from biggraphite import metadata_cache
from biggraphite.cli import command
from prometheus_client import write_to_textfile, REGISTRY

                ' ',
                progressbar.AdaptiveETA(),
            ]

            # max_value = end_key - start_key
            self.pbar = progressbar.ProgressBar(
                widgets=widgets,
                fd=out_fd,
                redirect_stderr=False,
                min_value=0,
                max_value=end_key - start_key)

        self.pbar.start()

        if on_progress is None:
            def _on_progress(total, done, token):
                self.pbar.update(total, token=token)

                if self.metrics_file_path != "":
                    write_to_textfile(self.metrics_file_path, REGISTRY)

            on_progress = _on_progress

        accessor.connect()

        if opts.clean_cache:
            if opts.storage_dir:
                settings = {"path": opts.storage_dir, "ttl": opts.max_age}

                logging.info("Cleaning cache from %s", settings)

                with metadata_cache.DiskCache(accessor, settings) as cache: