# 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
# 
# 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


from linux_story.commands_real import shell_command
from linux_story.story.terminals.terminal_nano import TerminalNano
#!/usr/bin/env python

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



class TerminalChmod(TerminalNano):
    terminal_commands = [
        "ls", "cat", "cd", "mv", "echo", "mkdir", "nano", "chmod"
    ]

    def do_chmod(self, line):

# 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
# 
# 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/terminals/terminal_chmod.py
from linux_story.commands_real import shell_command
from linux_story.story.terminals.terminal_nano import TerminalNano

#!/usr/bin/env python

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



class TerminalChmod(TerminalNano):
    terminal_commands = [
        "ls", "cat", "cd", "mv", "echo", "mkdir", "nano", "chmod"
    ]

    def do_chmod(self, line):

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