# Path: linux_story/common.py
# def get_max_challenge_number():
# def get_username():
# def get_story_file(name):


import os
import os.path
import gettext
import re
import sys
from kano.colours import colourize256, decorate_string
from kano.logging import logger
from kano_profile.apps import \
    save_app_state_variable, load_app_state_variable, \
    increment_app_state_variable
from linux_story.common import \
    localized_story_files_dir_pattern, \
    fallback_story_files_dir
    except Exception as e:
            logger.error('Unexpected error while loading the ascii art'
                         ' - [{}]'.format(e))

    return ascii_art


def get_path_to_file_in_system(name):
    """
    Finds the path of a file (asset), first looking for any translation,
    and falling back to the default location.

    Args:
        name (str) - the name of the asset file

    Returns:
        path (str) - the path to the file (asset)
    """

    path_in_system = None

    lang_dirs = get_language_dirs()

    for lang_dir in lang_dirs:
        asset_path = os.path.join(localized_story_files_dir_pattern.format(lang_dir), name)
        if os.path.isfile(asset_path):
            path_in_system = asset_path
            break

    if path_in_system is None:

# Path: linux_story/common.py
# def get_max_challenge_number():
# def get_username():
# def get_story_file(name):


# Path: linux_story/helper_functions.py
import os
import os.path
import gettext
import re
import sys
from kano.colours import colourize256, decorate_string
from kano.logging import logger
from kano_profile.apps import \
    save_app_state_variable, load_app_state_variable, \
    increment_app_state_variable
from linux_story.common import \
    localized_story_files_dir_pattern, \
    fallback_story_files_dir

    except Exception as e:
            logger.error('Unexpected error while loading the ascii art'
                         ' - [{}]'.format(e))

    return ascii_art


def get_path_to_file_in_system(name):
    """
    Finds the path of a file (asset), first looking for any translation,
    and falling back to the default location.

    Args:
        name (str) - the name of the asset file

    Returns:
        path (str) - the path to the file (asset)
    """

    path_in_system = None

    lang_dirs = get_language_dirs()

    for lang_dir in lang_dirs:
        asset_path = os.path.join(localized_story_files_dir_pattern.format(lang_dir), name)
        if os.path.isfile(asset_path):
            path_in_system = asset_path
            break

    if path_in_system is None:

        path_in_system = os.path.join(fallback_story_files_dir, name)