# Path: studio/artifacts/artifacts_tracker.py
# def get_studio_home():
#     if STUDIOML_HOME in os.environ.keys():
#         return os.environ[STUDIOML_HOME]
#     return os.path.join(os.path.expanduser('~'), '.studioml')
# 
# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# 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
# def check_for_kb_interrupt():
#     current_exc = sys.exc_info()[1]
#     if current_exc is None:
#         return
#     if isinstance(current_exc, KeyboardInterrupt):
#         raise current_exc
#     return
# 
# def rm_rf(path):
#     '''
#     remove file or a directory
#     '''
#     if not os.path.exists(path):
#         return
# 
#     if os.path.isfile(path):
#         os.remove(path)  # remove the file
#     elif os.path.isdir(path):
#         shutil.rmtree(path)  # remove dir and all contains
#     else:
#         raise ValueError("file {0} is not a file or dir.".format(path))


import os
import uuid
import time
import filelock
from studio.artifacts.artifacts_tracker import get_studio_home
from studio.storage.storage_setup import get_storage_verbose_level
from studio.util import logs
from studio.util.util import check_for_kb_interrupt, rm_rf
                if not is_active:
                    return None, None
                if any(files):
                    first_file = min([(p, self._get_time(p)) for p in files],
                                     key=lambda t: t[1])[0]
                    first_file = os.path.join(self.path, first_file)

                    with open(first_file, 'r') as f_in:
                        data = f_in.read()

                    if acknowledge:
                        self.acknowledge(first_file)
                        return data, None
                    return data, first_file

            if total_wait_time >= timeout:
                return None, None
            time.sleep(sleep_in_seconds)
            total_wait_time += sleep_in_seconds

    def enqueue(self, data):
        with self._lock:
            filename = os.path.join(self.path, str(uuid.uuid4()))
            with open(filename, 'w') as f_out:
                f_out.write(data)

    def acknowledge(self, key):
        try:
            os.remove(key)
        except BaseException:

# Path: studio/artifacts/artifacts_tracker.py
# def get_studio_home():
#     if STUDIOML_HOME in os.environ.keys():
#         return os.environ[STUDIOML_HOME]
#     return os.path.join(os.path.expanduser('~'), '.studioml')
# 
# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# 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
# def check_for_kb_interrupt():
#     current_exc = sys.exc_info()[1]
#     if current_exc is None:
#         return
#     if isinstance(current_exc, KeyboardInterrupt):
#         raise current_exc
#     return
# 
# def rm_rf(path):
#     '''
#     remove file or a directory
#     '''
#     if not os.path.exists(path):
#         return
# 
#     if os.path.isfile(path):
#         os.remove(path)  # remove the file
#     elif os.path.isdir(path):
#         shutil.rmtree(path)  # remove dir and all contains
#     else:
#         raise ValueError("file {0} is not a file or dir.".format(path))


# Path: studio/queues/local_queue.py
import os
import uuid
import time
import filelock
from studio.artifacts.artifacts_tracker import get_studio_home
from studio.storage.storage_setup import get_storage_verbose_level
from studio.util import logs
from studio.util.util import check_for_kb_interrupt, rm_rf

                if not is_active:
                    return None, None
                if any(files):
                    first_file = min([(p, self._get_time(p)) for p in files],
                                     key=lambda t: t[1])[0]
                    first_file = os.path.join(self.path, first_file)

                    with open(first_file, 'r') as f_in:
                        data = f_in.read()

                    if acknowledge:
                        self.acknowledge(first_file)
                        return data, None
                    return data, first_file

            if total_wait_time >= timeout:
                return None, None
            time.sleep(sleep_in_seconds)
            total_wait_time += sleep_in_seconds

    def enqueue(self, data):
        with self._lock:
            filename = os.path.join(self.path, str(uuid.uuid4()))
            with open(filename, 'w') as f_out:
                f_out.write(data)

    def acknowledge(self, key):
        try:
            os.remove(key)
        except BaseException:

            check_for_kb_interrupt()