Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (54 sloc) 1.56 KB
#!/usr/bin/python
import sys, logging, copy
from dFile import dFile
from dFolder import dFolder
from dDrive import dDrive
if len(sys.argv)!=1:
print "Usage: python ."
sys.exit(1)
print "Welcome to Darwin File Manager!"
print "Type help to get a list of commands.\n"
logging.basicConfig(level=logging.DEBUG)
drive = dDrive('', None).initData()
folder = drive
cmds = [
['cat', 'Create and view files', 'cat [>] FILE'],
['cd', 'Change directory', 'cd [DIR]'],
['cp', 'Copy source to destination', 'cp SOURCE DEST'],
['exit', 'Exit this file manager', 'exit'],
['help', 'Display this help text', 'help [COMMAND]'],
['ls', 'List information about files', 'ls [-l] [FILE|DIR]'],
['mkdir', 'Create directory if not exists', 'mkdir DIR'],
['mv', 'Rename source to destination', 'mv SOURCE DEST'],
['rm', 'Remove (unlink) the files', 'rm (FILE|DIR)'],
]
def cnf(cmd):
print "%s: command not found"%(cmd)
def cnu(cmd):
cmd = filter(lambda x: x[0]==cmd, cmds)[0]
print "Usage: %s"%(cmd[2])
def nfd(path):
print "%s: No such file or directory"%(path)
try:
while True:
print "[%s]$"%(folder.getName()),
args = raw_input().strip().split()
if len(args)==0: continue
bin = drive.find('bin')
if bin is not None:
cmd = bin.find(args[0])
if cmd is not None:
exec(cmd.read())
else:
cnf(args[0])
else:
print "No such folder '/bin'"
except EOFError:
print "\n\nYou evolved from a monkey!"
sys.exit(1)
except KeyboardInterrupt:
print "\n\nYou are not fit to survive!"
sys.exit(1)
except Exception as ex:
logging.exception("You have died!")
sys.exit(1)