# Path: automlk/store.py
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# def exists_key_store(key):
#     """
#     checks if a key exists
# 
#     :param key: key of the data
#     :return: True if the key exists else False
#     """
#     if get_use_redis():
#         return rds.exists(str(key))
#     else:
#         return os.path.exists(store_folder + '/' + __clean_key(key) + '.json')
# 
# def set_key_store(key, value):
#     """
#     sets value to key in store
# 
#     :param key: key of the data
#     :param value: value of the data to store
#     """
#     if get_use_redis():
#         rds.set(str(key), json.dumps(value))
#     else:
#         with open(store_folder + '/' + __clean_key(key) + '.json', 'w') as f:
#             json.dump(value, f)
# 
# def incr_key_store(key, amount=1):
#     """
#     increments value of key in store with amount
# 
#     :param key: key of the data
#     :param amount: amount to add
#     :return: new value
#     """
#     if get_use_redis():
#         return rds.incr(str(key), amount)
#     else:
#         if exists_key_store(key):
#             value = get_key_store(key)
#             set_key_store(key, value + amount)
#             return value + amount
#         else:
#             set_key_store(key, amount)
#             return amount
# 
# def rpush_key_store(key, value):
#     """
#     add value to the end of a list of key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     :return: None
#     """
#     if get_use_redis():
#         rds.rpush(str(key), json.dumps(value))
#     else:
#         if exists_key_store(key):
#             l = get_key_store(key)
#             if isinstance(l, list):
#                 set_key_store(key, l + [value])
#             else:
#                 set_key_store(key, [value])
#         else:
#             set_key_store(key, [value])


from .store import get_key_store, exists_key_store, set_key_store, incr_key_store, rpush_key_store


def get_folder_list():
    """
    returns the list of folders

    :return:
    """
    if exists_key_store('folders:list'):
        return get_key_store('folders:list')
    else:
        # initialize folder list with root (All)

# Path: automlk/store.py
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# def exists_key_store(key):
#     """
#     checks if a key exists
# 
#     :param key: key of the data
#     :return: True if the key exists else False
#     """
#     if get_use_redis():
#         return rds.exists(str(key))
#     else:
#         return os.path.exists(store_folder + '/' + __clean_key(key) + '.json')
# 
# def set_key_store(key, value):
#     """
#     sets value to key in store
# 
#     :param key: key of the data
#     :param value: value of the data to store
#     """
#     if get_use_redis():
#         rds.set(str(key), json.dumps(value))
#     else:
#         with open(store_folder + '/' + __clean_key(key) + '.json', 'w') as f:
#             json.dump(value, f)
# 
# def incr_key_store(key, amount=1):
#     """
#     increments value of key in store with amount
# 
#     :param key: key of the data
#     :param amount: amount to add
#     :return: new value
#     """
#     if get_use_redis():
#         return rds.incr(str(key), amount)
#     else:
#         if exists_key_store(key):
#             value = get_key_store(key)
#             set_key_store(key, value + amount)
#             return value + amount
#         else:
#             set_key_store(key, amount)
#             return amount
# 
# def rpush_key_store(key, value):
#     """
#     add value to the end of a list of key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     :return: None
#     """
#     if get_use_redis():
#         rds.rpush(str(key), json.dumps(value))
#     else:
#         if exists_key_store(key):
#             l = get_key_store(key)
#             if isinstance(l, list):
#                 set_key_store(key, l + [value])
#             else:
#                 set_key_store(key, [value])
#         else:
#             set_key_store(key, [value])


# Path: automlk/folders.py
from .store import get_key_store, exists_key_store, set_key_store, incr_key_store, rpush_key_store



def get_folder_list():
    """
    returns the list of folders

    :return:
    """
    if exists_key_store('folders:list'):
        return get_key_store('folders:list')
    else:
        # initialize folder list with root (All)

        set_key_store('folders:counter', 0)