# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# Path: studio/storage/storage_type.py
# class StorageType(Enum):
#     storageHTTP = 1
#     storageS3 = 2
#     storageLocal = 3
#     storageFirebase = 4
#     storageDockerHub = 5
#     storageSHub = 6
# 
#     storageInvalid = 99
# 
# Path: studio/storage/storage_handler.py
# class StorageHandler:
#     def __init__(self, storage_type: StorageType,
#                  logger,
#                  measure_timestamp_diff=False,
#                  compression=None):
#         self.type = storage_type
#         self.logger = logger
#         self.compression = compression
#         self._timestamp_shift = 0
#         if measure_timestamp_diff:
#             try:
#                 self._timestamp_shift = self._measure_timestamp_diff()
#             except BaseException:
#                 check_for_kb_interrupt()
#                 self._timestamp_shift = 0
# 
#     @classmethod
#     def get_id(cls, config: Dict) -> str:
#         raise NotImplementedError("Not implemented: upload_file")
# 
#     def upload_file(self, key, local_path):
#         raise NotImplementedError("Not implemented: upload_file")
# 
#     def download_file(self, key, local_path):
#         raise NotImplementedError("Not implemented: download_file")
# 
#     def download_remote_path(self, remote_path, local_path):
#         raise NotImplementedError("Not implemented: download_remote_path")
# 
#     def delete_file(self, key, shallow=True):
#         raise NotImplementedError("Not implemented: delete_file")
# 
#     def get_file_url(self, key, method='GET'):
#         raise NotImplementedError("Not implemented: get_file_url")
# 
#     def get_file_timestamp(self, key):
#         raise NotImplementedError("Not implemented: get_file_timestamp")
# 
#     def get_qualified_location(self, key):
#         raise NotImplementedError("Not implemented: get_qualified_location")
# 
#     def get_local_destination(self, remote_path: str):
#         raise NotImplementedError("Not implemented: get_local_destination")
# 
#     def get_timestamp_shift(self):
#         return self._timestamp_shift
# 
#     def get_compression(self):
#         return self.compression
# 
#     def cleanup(self):
#         pass
# 
#     def _measure_timestamp_diff(self):
#         max_diff = 60
#         tmpfile = get_temp_filename() + '.txt'
#         with open(tmpfile, 'w') as f:
#             f.write('timestamp_diff_test')
#         key = 'tests/' + str(uuid.uuid4())
#         self.upload_file(key, tmpfile)
#         remote_timestamp = self.get_file_timestamp(key)
# 
#         if remote_timestamp is not None:
#             now_remote_diff = time.time() - remote_timestamp
#             self.storage_handler.delete_file(key)
#             os.remove(tmpfile)
# 
#             assert -max_diff < now_remote_diff and \
#                 now_remote_diff < max_diff, \
#                 "Timestamp difference is more than 60 seconds. " + \
#                 "You'll need to adjust local clock for caching " + \
#                 "to work correctly"
# 
#             return -now_remote_diff if now_remote_diff < 0 else 0
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/util/util.py
# DAY = 86400
# HOUR = 3600
# MINUTE = 60
# def remove_backspaces(line):
# def report_fatal(msg: str, logger):
# def sha256_checksum(filename, block_size=65536):
# def filehash(filename, block_size=65536, hashobj=None):
# def rand_string(length):
# def _looks_like_url(name):
# def parse_s3_path(qualified: str):
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
# def compression_to_extension(compression):
# def compression_to_taropt(compression):
# def _compression_to_extension_taropt(compression):
# def timeit(method):
#     def timed(*args, **kw):
# def sixdecode(sval):
# def shquote(sval):
# def parse_duration(duration_str):
# def parse_verbosity(verbosity=None):
# def str2duration(sval):
# def get_temp_filename() -> str:
# def delete_local_path(local_path: str, root: str, shallow: bool):
# def delete_local_folders(local_folder_path: str, root: str):
# def rm_rf(path):
# def check_for_kb_interrupt():
# def add_packages(list1, list2):


import os
import shutil
from typing import Dict
from studio.storage.storage_setup import get_storage_verbose_level
from studio.storage.storage_type import StorageType
from studio.storage.storage_handler import StorageHandler
from studio.util import logs
from studio.util import util
            self.logger.debug("Deleting local file {0}.".format(key_path))
            util.delete_local_path(key_path, self.store_root, False)

    @classmethod
    def get_id(cls, config: Dict) -> str:
        endpoint = config.get('endpoint', None)
        if endpoint is None:
            return None
        return '[local]{0}'.format(endpoint)

    def _get_file_path_from_key(self, key: str):
        return str(os.path.join(self.store_root, key))

    def get_file_url(self, key, method='GET'):
        return self._get_file_path_from_key(key)

    def get_file_timestamp(self, key):
        key_path: str = self._get_file_path_from_key(key)
        if os.path.exists(key_path):
            return os.path.getmtime(key_path)
        else:
            return None

    def get_qualified_location(self, key):
        return 'file:/' + self.store_root + '/' + key

    def get_endpoint(self):
        return self.endpoint

    def _report_fatal(self, msg: str):

# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# Path: studio/storage/storage_type.py
# class StorageType(Enum):
#     storageHTTP = 1
#     storageS3 = 2
#     storageLocal = 3
#     storageFirebase = 4
#     storageDockerHub = 5
#     storageSHub = 6
# 
#     storageInvalid = 99
# 
# Path: studio/storage/storage_handler.py
# class StorageHandler:
#     def __init__(self, storage_type: StorageType,
#                  logger,
#                  measure_timestamp_diff=False,
#                  compression=None):
#         self.type = storage_type
#         self.logger = logger
#         self.compression = compression
#         self._timestamp_shift = 0
#         if measure_timestamp_diff:
#             try:
#                 self._timestamp_shift = self._measure_timestamp_diff()
#             except BaseException:
#                 check_for_kb_interrupt()
#                 self._timestamp_shift = 0
# 
#     @classmethod
#     def get_id(cls, config: Dict) -> str:
#         raise NotImplementedError("Not implemented: upload_file")
# 
#     def upload_file(self, key, local_path):
#         raise NotImplementedError("Not implemented: upload_file")
# 
#     def download_file(self, key, local_path):
#         raise NotImplementedError("Not implemented: download_file")
# 
#     def download_remote_path(self, remote_path, local_path):
#         raise NotImplementedError("Not implemented: download_remote_path")
# 
#     def delete_file(self, key, shallow=True):
#         raise NotImplementedError("Not implemented: delete_file")
# 
#     def get_file_url(self, key, method='GET'):
#         raise NotImplementedError("Not implemented: get_file_url")
# 
#     def get_file_timestamp(self, key):
#         raise NotImplementedError("Not implemented: get_file_timestamp")
# 
#     def get_qualified_location(self, key):
#         raise NotImplementedError("Not implemented: get_qualified_location")
# 
#     def get_local_destination(self, remote_path: str):
#         raise NotImplementedError("Not implemented: get_local_destination")
# 
#     def get_timestamp_shift(self):
#         return self._timestamp_shift
# 
#     def get_compression(self):
#         return self.compression
# 
#     def cleanup(self):
#         pass
# 
#     def _measure_timestamp_diff(self):
#         max_diff = 60
#         tmpfile = get_temp_filename() + '.txt'
#         with open(tmpfile, 'w') as f:
#             f.write('timestamp_diff_test')
#         key = 'tests/' + str(uuid.uuid4())
#         self.upload_file(key, tmpfile)
#         remote_timestamp = self.get_file_timestamp(key)
# 
#         if remote_timestamp is not None:
#             now_remote_diff = time.time() - remote_timestamp
#             self.storage_handler.delete_file(key)
#             os.remove(tmpfile)
# 
#             assert -max_diff < now_remote_diff and \
#                 now_remote_diff < max_diff, \
#                 "Timestamp difference is more than 60 seconds. " + \
#                 "You'll need to adjust local clock for caching " + \
#                 "to work correctly"
# 
#             return -now_remote_diff if now_remote_diff < 0 else 0
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/util/util.py
# DAY = 86400
# HOUR = 3600
# MINUTE = 60
# def remove_backspaces(line):
# def report_fatal(msg: str, logger):
# def sha256_checksum(filename, block_size=65536):
# def filehash(filename, block_size=65536, hashobj=None):
# def rand_string(length):
# def _looks_like_url(name):
# def parse_s3_path(qualified: str):
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
# def compression_to_extension(compression):
# def compression_to_taropt(compression):
# def _compression_to_extension_taropt(compression):
# def timeit(method):
#     def timed(*args, **kw):
# def sixdecode(sval):
# def shquote(sval):
# def parse_duration(duration_str):
# def parse_verbosity(verbosity=None):
# def str2duration(sval):
# def get_temp_filename() -> str:
# def delete_local_path(local_path: str, root: str, shallow: bool):
# def delete_local_folders(local_folder_path: str, root: str):
# def rm_rf(path):
# def check_for_kb_interrupt():
# def add_packages(list1, list2):


# Path: studio/storage/local_storage_handler.py
import os
import shutil
from typing import Dict
from studio.storage.storage_setup import get_storage_verbose_level
from studio.storage.storage_type import StorageType
from studio.storage.storage_handler import StorageHandler
from studio.util import logs
from studio.util import util

            self.logger.debug("Deleting local file {0}.".format(key_path))
            util.delete_local_path(key_path, self.store_root, False)

    @classmethod
    def get_id(cls, config: Dict) -> str:
        endpoint = config.get('endpoint', None)
        if endpoint is None:
            return None
        return '[local]{0}'.format(endpoint)

    def _get_file_path_from_key(self, key: str):
        return str(os.path.join(self.store_root, key))

    def get_file_url(self, key, method='GET'):
        return self._get_file_path_from_key(key)

    def get_file_timestamp(self, key):
        key_path: str = self._get_file_path_from_key(key)
        if os.path.exists(key_path):
            return os.path.getmtime(key_path)
        else:
            return None

    def get_qualified_location(self, key):
        return 'file:/' + self.store_root + '/' + key

    def get_endpoint(self):
        return self.endpoint

    def _report_fatal(self, msg: str):

        util.report_fatal(msg, self.logger)