| 113 | ################################################################################ |
| 114 | |
| 115 | class Shell: |
| 116 | |
| 117 | # The Users Interface |
| 118 | def __init__(self, context): |
| 119 | assert context.__class__ is Context |
| 120 | self.__context = context |
| 121 | self.__commands = ['chdir', 'getcwd', 'listdir', \ |
| 122 | 'mkdir', 'rmdir', 'remove', 'exit'] |
| 123 | self.__programs = ['type', 'edit'] |
| 124 | print 'Welcome to DAL' |
| 125 | print '==============' |
| 126 | while True: |
| 127 | try: |
| 128 | prompt = raw_input('>>> ') |
| 129 | except: |
| 130 | continue |
| 131 | if prompt == 'help': |
| 132 | print 'COMMANDS:' |
| 133 | print ' chdir: change current working directory' |
| 134 | print ' getcwd: get current working directory' |
| 135 | print ' listdir: display directory contents' |
| 136 | print ' mkdir: make a new directory' |
| 137 | print ' rmdir: remove an old directory' |
| 138 | print ' remove: remove a file' |
| 139 | print ' exit: terminates this shell' |
| 140 | print 'PROGRAMS:' |
| 141 | print ' type: display the contents of a file' |
| 142 | print ' edit: create a new file' |
| 143 | else: |
| 144 | prompt = prompt.split(' ') |
| 145 | command = prompt[0] |
| 146 | path = ' '.join(prompt[1:]) |
| 147 | if command in self.__commands: |
| 148 | if command == 'chdir': |
| 149 | self.__chdir(path) |
| 150 | elif command == 'getcwd': |
| 151 | self.__getcwd() |
| 152 | elif command == 'listdir': |
| 153 | self.__listdir(path) |
| 154 | elif command == 'mkdir': |
| 155 | self.__mkdir(path) |
| 156 | elif command == 'rmdir': |
| 157 | self.__rmdir(path) |
| 158 | elif command == 'remove': |
| 159 | self.__remove(path) |
| 160 | else: |
| 161 | break |
| 162 | elif command in self.__programs: |
| 163 | if command == 'type': |
| 164 | try: |
| 165 | Type(self.__context, path) |
| 166 | except: |
| 167 | print 'Type has crashed.' |
| 168 | else: |
| 169 | try: |
| 170 | Edit(self.__context, path) |
| 171 | except: |
| 172 | print 'Edit has crashed.' |