# Path: linux_story/commands_real.py
# def shell_command(real_loc, line, command_word=""):
#     """
#     Suitable for launching commands which don't involve curses.
# 
#     Args:
#         real_loc (str): the current location of the user.
#         line (str): line user typed not including the command word.
#         command_word (str): command you want to run (e.g. ls).
# 
#     Returns:
#         bool: False if error, True otherwise.
#     """
# 
#     if command_word:
#         line = command_word + " " + line
# 
#     line = line.replace('~', fake_home_dir)
#     args = line.split(" ")
# 
#     # run the command
#     p = subprocess.Popen(args, cwd=real_loc,
#                          stdout=subprocess.PIPE,
#                          stderr=subprocess.PIPE)
#     stdout, stderr = p.communicate()
# 
#     if stderr:
#         print stderr.strip().replace(fake_home_dir, '~')
#         return False
# 
#     if stdout:
#         if command_word == "cat":
#             print stdout
# 
#         else:
#             print stdout.strip()
# 
#     # notifying the SoundManager about the command that was run
#     sounds_manager.on_command_run(args)
# 
#     # should this return stdout?
#     return True
# 
# def launch_application(real_path, line, command_word=""):
#     '''
#     This is appropriate for commands which use curses (e.g. less).
# 
#     Args:
#         real_path (str): the current location of the user.
#         line (str): the line (not including the command word) the user entered.
#         command_word (str): the command that we want to launch.
# 
#     Returns:
#         None.
#     '''
# 
#     line = line.replace('~', fake_home_dir)
#     line = " ".join([command_word] + line.split(" "))
# 
#     p = subprocess.Popen(line, cwd=real_path, shell=True)
#     stdout, stderr = p.communicate()
# 
#     if stdout:
#         print stdout.strip()
# 
#     if stderr:
#         print stderr.strip()
# 
# Path: linux_story/story/terminals/terminal_cd.py
# class TerminalCd(TerminalCat):
#     terminal_commands = ["ls", "cat", "cd"]
# 
#     def do_cd(self, line):
#         if self.__check_cd(line):
#             self._set_command_blocked(False)
#             new_path = cd(self._location.get_real_path(), line)
#             if not not_locked(new_path):
#                 self._set_command_blocked(True)
#                 print (
#                     _("bash: cd: " + line + ": Permission denied")
#                 )
#             elif new_path:
#                 self._location.set_real_path(new_path)
#                 self._set_prompt()
#         else:
#             self._set_command_blocked(True)
#             print (_("Nice try! But you entered an unexpected destination path."))
# 
#     def complete_cd(self, text, line, begidx, endidx):
#         try:
#             return self._autocomplete_files(text, line, begidx, endidx, only_dirs=True)
#         except Exception as e:
#             print str(e)
# 
#     def __check_cd(self, line):
#         """If returns True, that means that cd will bring the user closer
#         to their destination, so cd should be allowed to run with the
#         user's choice of path.
#         """
# 
#         # Get the current list of the paths that we're allowed to go on
#         route = route_between_paths(self._location.get_fake_path(), self._location.get_end_dir())
# 
#         if not route and self._dirs_to_attempt:
#             route = route_between_paths(self._location.get_fake_path(), self._dirs_to_attempt)
# 
#         if line:
#             if line.startswith("~"):
#                 new_path = line
#             else:
#                 new_path = os.path.join(self._location.get_fake_path(), line)
#         else:
#             # If the user didn't enter a path, assume they want to go to
#             # home folder
#             new_path = '~'
# 
#         new_path = os.path.abspath(os.path.expanduser(new_path))
#         if new_path in route:
#             return True
# 
#         return False


from linux_story.commands_real import shell_command, launch_application
from linux_story.story.terminals.terminal_cd import TerminalCd
# terminal_mv.py
#
# Copyright (C) 2014-2016 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# A terminal for one of the challenges




class TerminalMv(TerminalCd):
    terminal_commands = ["ls", "cat", "cd", "mv"]

    def do_mv(self, line):
        if "*" in line:
            launch_application(self._location.get_real_path(), line, "mv")
        else:

# Path: linux_story/commands_real.py
# def shell_command(real_loc, line, command_word=""):
#     """
#     Suitable for launching commands which don't involve curses.
# 
#     Args:
#         real_loc (str): the current location of the user.
#         line (str): line user typed not including the command word.
#         command_word (str): command you want to run (e.g. ls).
# 
#     Returns:
#         bool: False if error, True otherwise.
#     """
# 
#     if command_word:
#         line = command_word + " " + line
# 
#     line = line.replace('~', fake_home_dir)
#     args = line.split(" ")
# 
#     # run the command
#     p = subprocess.Popen(args, cwd=real_loc,
#                          stdout=subprocess.PIPE,
#                          stderr=subprocess.PIPE)
#     stdout, stderr = p.communicate()
# 
#     if stderr:
#         print stderr.strip().replace(fake_home_dir, '~')
#         return False
# 
#     if stdout:
#         if command_word == "cat":
#             print stdout
# 
#         else:
#             print stdout.strip()
# 
#     # notifying the SoundManager about the command that was run
#     sounds_manager.on_command_run(args)
# 
#     # should this return stdout?
#     return True
# 
# def launch_application(real_path, line, command_word=""):
#     '''
#     This is appropriate for commands which use curses (e.g. less).
# 
#     Args:
#         real_path (str): the current location of the user.
#         line (str): the line (not including the command word) the user entered.
#         command_word (str): the command that we want to launch.
# 
#     Returns:
#         None.
#     '''
# 
#     line = line.replace('~', fake_home_dir)
#     line = " ".join([command_word] + line.split(" "))
# 
#     p = subprocess.Popen(line, cwd=real_path, shell=True)
#     stdout, stderr = p.communicate()
# 
#     if stdout:
#         print stdout.strip()
# 
#     if stderr:
#         print stderr.strip()
# 
# Path: linux_story/story/terminals/terminal_cd.py
# class TerminalCd(TerminalCat):
#     terminal_commands = ["ls", "cat", "cd"]
# 
#     def do_cd(self, line):
#         if self.__check_cd(line):
#             self._set_command_blocked(False)
#             new_path = cd(self._location.get_real_path(), line)
#             if not not_locked(new_path):
#                 self._set_command_blocked(True)
#                 print (
#                     _("bash: cd: " + line + ": Permission denied")
#                 )
#             elif new_path:
#                 self._location.set_real_path(new_path)
#                 self._set_prompt()
#         else:
#             self._set_command_blocked(True)
#             print (_("Nice try! But you entered an unexpected destination path."))
# 
#     def complete_cd(self, text, line, begidx, endidx):
#         try:
#             return self._autocomplete_files(text, line, begidx, endidx, only_dirs=True)
#         except Exception as e:
#             print str(e)
# 
#     def __check_cd(self, line):
#         """If returns True, that means that cd will bring the user closer
#         to their destination, so cd should be allowed to run with the
#         user's choice of path.
#         """
# 
#         # Get the current list of the paths that we're allowed to go on
#         route = route_between_paths(self._location.get_fake_path(), self._location.get_end_dir())
# 
#         if not route and self._dirs_to_attempt:
#             route = route_between_paths(self._location.get_fake_path(), self._dirs_to_attempt)
# 
#         if line:
#             if line.startswith("~"):
#                 new_path = line
#             else:
#                 new_path = os.path.join(self._location.get_fake_path(), line)
#         else:
#             # If the user didn't enter a path, assume they want to go to
#             # home folder
#             new_path = '~'
# 
#         new_path = os.path.abspath(os.path.expanduser(new_path))
#         if new_path in route:
#             return True
# 
#         return False


# Path: linux_story/story/terminals/terminal_mv.py
from linux_story.commands_real import shell_command, launch_application
from linux_story.story.terminals.terminal_cd import TerminalCd

# terminal_mv.py
#
# Copyright (C) 2014-2016 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# A terminal for one of the challenges




class TerminalMv(TerminalCd):
    terminal_commands = ["ls", "cat", "cd", "mv"]

    def do_mv(self, line):
        if "*" in line:
            launch_application(self._location.get_real_path(), line, "mv")
        else:

            shell_command(self._location.get_real_path(), line, "mv")