# Path: linux_story/common.py
# def get_story_file(name):
#     return os.path.join(fallback_story_files_dir, name)
# 
# Path: linux_story/story/challenges/CompanionMisc.py
# class StepTemplateEleanorBernard(StepTemplate):
#     companion_command = "cat Eleanor"
# 
#     def check_command(self, last_user_input):
#         spoke = self._companion_speaks(last_user_input)
#         if not spoke:
#             return self._default_check_command(last_user_input)
# 
#     def block_command(self, line):
#         if "basement" in line and ("ls" in line or "cat" in line):
#             print bernard_text
#             return True
#         else:
#             return StepTemplate.block_command(self, line)
# 
# Path: linux_story/step_helper_functions.py
# def unblock_cd_commands(line):
#     if line.startswith("mkdir") or \
#             (line.startswith("mv") and not line.strip() == 'mv --help'):
#         print _('Nice try! But you do not need that command for this challenge')
#         return True
#     return False
# 
# Path: linux_story/story/terminals/terminal_nano.py
# class TerminalNano(TerminalMkdir):
#     terminal_commands = ["ls", "cat", "cd", "mv", "echo", "mkdir", "nano"]
# 
#     def __init__(self, step, location, dirs_to_attempt, client):
#         self._step_nano = step.get_nano_logic()
# 
#         TerminalMkdir.__init__(self, step, location, dirs_to_attempt, client)
# 
#     def do_nano(self, line):
# 
#         ##########################################
#         # set up step_nano
#         self._step_nano.set_nano_running(True)
#         self._step_nano.opened_nano(line)
# 
#         # Read contents of the file
#         text = self.read_goal_contents()
#         self._step_nano.set_nano_content(text)
#         ##########################################
# 
#         # Read nano in a separate thread
#         t = threading.Thread(target=self.try_and_get_pipe_contents)
#         t.daemon = True
#         t.start()
# 
#         # If the line is given, it is the filepath of the file we are
#         # adjusting.
#         # if line:
#         #    self.set_last_nano_filepath(line)
# 
#         nano(self._location.get_real_path(), line)
# 
#     def try_and_get_pipe_contents(self):
#         try:
#             self._step_nano.get_pipe_contents()
#         except Exception as e:
#             logger.error(
#                 "\nFailed to get nano contents, exception {}".format(str(e))
#             )
#             self._step.send_hint("\nFailed to get nano contents, {}".format(str(e)))
# 
#     def read_goal_contents(self):
#         text = ""
#         end_path = generate_real_path(self._step_nano.get_goal_nano_filepath())
# 
#         if os.path.exists(end_path):
#             # check contents of file contains the self.end_text
#             f = open(end_path, "r")
#             text = f.read()
#             f.close()
# 
#         return text


import os
from linux_story.common import get_story_file
from linux_story.story.challenges.CompanionMisc import StepTemplateEleanorBernard
from linux_story.step_helper_functions import unblock_cd_commands
from linux_story.story.terminals.terminal_nano import TerminalNano
        _("{{lb:Head to the}} {{bb:shed-shop.}}")
    ]
    start_dir = "~/town/east/restaurant/.cellar"
    end_dir = "~/town/east/shed-shop"

    path_hints = {
        "~/town/east/restaurant/.cellar": {
            "blocked": _("\n{{rb:Use}} {{yb:cd ../}} {{rb:to go back.}}")
        },
        "~/town/east/restaurant": {
            "not_blocked": _("\n{{gb:You head upstairs}}"),
            "blocked": _("\n{{rb:Use}} {{yb:cd ../}} {{rb:to go back.}}")
        },
        "~/town/east": {
            "not_blocked": _("\n{{gb:Now go into the}} {{bb:shed-shop}}{{gb:.}}"),
            "blocked": _("\n{{rb:Use}} {{yb:cd shed-shop/}}{{rb:.}}")
        }
    }

    def check_command(self, line):
        if self.get_fake_path() == self.end_dir:
            return True
        elif "cd" in line and not self.get_command_blocked():
            hint = self.path_hints[self.get_fake_path()]["not_blocked"]
        else:
            hint = self.path_hints[self.get_fake_path()]["blocked"]

        self.send_hint(hint)

    def block_command(self, line):

# Path: linux_story/common.py
# def get_story_file(name):
#     return os.path.join(fallback_story_files_dir, name)
# 
# Path: linux_story/story/challenges/CompanionMisc.py
# class StepTemplateEleanorBernard(StepTemplate):
#     companion_command = "cat Eleanor"
# 
#     def check_command(self, last_user_input):
#         spoke = self._companion_speaks(last_user_input)
#         if not spoke:
#             return self._default_check_command(last_user_input)
# 
#     def block_command(self, line):
#         if "basement" in line and ("ls" in line or "cat" in line):
#             print bernard_text
#             return True
#         else:
#             return StepTemplate.block_command(self, line)
# 
# Path: linux_story/step_helper_functions.py
# def unblock_cd_commands(line):
#     if line.startswith("mkdir") or \
#             (line.startswith("mv") and not line.strip() == 'mv --help'):
#         print _('Nice try! But you do not need that command for this challenge')
#         return True
#     return False
# 
# Path: linux_story/story/terminals/terminal_nano.py
# class TerminalNano(TerminalMkdir):
#     terminal_commands = ["ls", "cat", "cd", "mv", "echo", "mkdir", "nano"]
# 
#     def __init__(self, step, location, dirs_to_attempt, client):
#         self._step_nano = step.get_nano_logic()
# 
#         TerminalMkdir.__init__(self, step, location, dirs_to_attempt, client)
# 
#     def do_nano(self, line):
# 
#         ##########################################
#         # set up step_nano
#         self._step_nano.set_nano_running(True)
#         self._step_nano.opened_nano(line)
# 
#         # Read contents of the file
#         text = self.read_goal_contents()
#         self._step_nano.set_nano_content(text)
#         ##########################################
# 
#         # Read nano in a separate thread
#         t = threading.Thread(target=self.try_and_get_pipe_contents)
#         t.daemon = True
#         t.start()
# 
#         # If the line is given, it is the filepath of the file we are
#         # adjusting.
#         # if line:
#         #    self.set_last_nano_filepath(line)
# 
#         nano(self._location.get_real_path(), line)
# 
#     def try_and_get_pipe_contents(self):
#         try:
#             self._step_nano.get_pipe_contents()
#         except Exception as e:
#             logger.error(
#                 "\nFailed to get nano contents, exception {}".format(str(e))
#             )
#             self._step.send_hint("\nFailed to get nano contents, {}".format(str(e)))
# 
#     def read_goal_contents(self):
#         text = ""
#         end_path = generate_real_path(self._step_nano.get_goal_nano_filepath())
# 
#         if os.path.exists(end_path):
#             # check contents of file contains the self.end_text
#             f = open(end_path, "r")
#             text = f.read()
#             f.close()
# 
#         return text


# Path: linux_story/story/challenges/challenge_30.py
import os
from linux_story.common import get_story_file
from linux_story.story.challenges.CompanionMisc import StepTemplateEleanorBernard
from linux_story.step_helper_functions import unblock_cd_commands
from linux_story.story.terminals.terminal_nano import TerminalNano

        _("{{lb:Head to the}} {{bb:shed-shop.}}")
    ]
    start_dir = "~/town/east/restaurant/.cellar"
    end_dir = "~/town/east/shed-shop"

    path_hints = {
        "~/town/east/restaurant/.cellar": {
            "blocked": _("\n{{rb:Use}} {{yb:cd ../}} {{rb:to go back.}}")
        },
        "~/town/east/restaurant": {
            "not_blocked": _("\n{{gb:You head upstairs}}"),
            "blocked": _("\n{{rb:Use}} {{yb:cd ../}} {{rb:to go back.}}")
        },
        "~/town/east": {
            "not_blocked": _("\n{{gb:Now go into the}} {{bb:shed-shop}}{{gb:.}}"),
            "blocked": _("\n{{rb:Use}} {{yb:cd shed-shop/}}{{rb:.}}")
        }
    }

    def check_command(self, line):
        if self.get_fake_path() == self.end_dir:
            return True
        elif "cd" in line and not self.get_command_blocked():
            hint = self.path_hints[self.get_fake_path()]["not_blocked"]
        else:
            hint = self.path_hints[self.get_fake_path()]["blocked"]

        self.send_hint(hint)

    def block_command(self, line):

        return unblock_cd_commands(line)