コード例 #1
0
import FileSystem
import time

FileSystem.Initialize_My_FileSystem()
fs = FileSystem.FileSystemOperations()
fsexit = 0
print("RAID5")
while fsexit == 0:
    command = raw_input("$ ")
    command = command.split()
    try:
        if command[0] == "mkdir":
            fs.mkdir(command[1])
        elif command[0] == "create":
            fs.create(command[1])
        elif command[0] == "write":
            path = command[1]
            data = command[2:len(command) - 1]
            data = ' '.join(str(item) for item in data)
            offset = command[len(command) - 1]
            start = time.clock()
            fs.write(str(path), str(data), int(offset))
            end = time.clock()
            #print("Time taken to perform write:", end - start)
        elif command[0] == "read":
            path = command[1]
            offset = command[2]
            size = command[3]
            start = time.clock()
            fs.read(path, int(offset), int(size))
            end = time.clock()
コード例 #2
0
ファイル: test.py プロジェクト: VipulBeriwal/FileSystem-POCSD
import FileSystem

FileSystem.Initialize_My_FileSystem()
interface = FileSystem.FileSystemOperations()

#1. MAKING NEW DIRECTORY
'''
interface.mkdir("/A")
interface.mkdir("/A/B")
interface.mkdir("/A/B/C")
interface.mkdir("D")
interface.status()
'''

#2. WRITING NEW FILES AND READING. [[BEFORE WRTING WE HAVE TO CRTEATE THE FILE ]]
'''
interface.create("/1.txt")
interface.write("/1.txt", "Principles of Computer System Design")
interface.mkdir("/A")
interface.create("/A/2.txt")
interface.write("/A/2.txt", "Hello World!")
interface.status()
interface.read("/1.txt")
interface.read("/A/2.txt", 2, 3)   #reading only 3 words from offset 2 (including the offset)
'''

#3. OVERWIRING OR APPEND FILE AT THE GIVEN OFFSET.
'''
interface.create("/1.txt")
interface.write("/1.txt", "ABC")
interface.read("/1.txt")
コード例 #3
0
def file_system_repl():
    fsop = FileSystem.FileSystemOperations()

    invalid_command = "That was not a recognized command, please follow the formatting seen in the menu choices."
    menu = """
    mkdir  <path>
    create <path>
    mv     <old_path> <new_path>
    read   <path> <offset>=0 <size>=-1 <delay>=0
    write  <path> <data> <offset>=0 <delay>=0
    rm     <path>
    status
    exit
    """
    print(menu)
    print(
        "Choose from the above commands in the following terminal:\n(Optional parameters must be specified in order if desired.)"
    )

    while True:
        print("$ ", end="")
        input = raw_input().strip()
        if input == "": continue
        try:
            command = input.split(" ")
        except:
            print(invalid_command)
            continue
        if len(command) == 0: continue
        elif command[0] == "mkdir":
            if (len(command) != 2):
                print(invalid_command)
                continue
            path = command[1]
            fsop.mkdir(path)
        elif command[0] == "create":
            if (len(command) != 2):
                print(invalid_command)
                continue
            path = command[1]
            if (path == '/'):
                print("Invalid path. Root exists.")
                continue
            fsop.create(path)
        elif command[0] == "mv":
            if (len(command) != 3):
                print(invalid_command)
                continue
            old_path = command[1]
            new_path = command[2]
            fsop.mv(old_path, new_path)
        elif command[0] == "read":
            if (len(command) < 2 or len(command) > 5):
                print(invalid_command)
                continue
            path = command[1]
            offset = 0
            size = -1
            delay_sec = 0
            if (len(command) >= 3):
                offset = int(command[2])
            if (len(command) >= 4):
                size = int(command[3])
            if (len(command) >= 5):
                delay_sec = int(command[4])
            fsop.read(path, offset, size, delay_sec)
        elif command[0] == "write":
            if (len(command) < 3 or len(command) > 5):
                print(invalid_command)
                continue
            path = command[1]
            data = command[2]
            offset = 0
            delay_sec = 0
            if (len(command) >= 4):
                offset = int(command[3])
            if (len(command) >= 5):
                delay_sec = int(command[4])
            fsop.write(path, data, offset, delay_sec)
        elif command[0] == "status":
            if (len(command) > 1):
                print(invalid_command)
                continue
            print(
                "Implementation of this method was deemed unecessary by Cody.")
            continue
        elif command[0] == "rm":
            if (len(command) != 2):
                print(invalid_command)
                continue
            path = command[1]
            fsop.rm(path)
        elif command[0] == "exit":
            if (len(command) > 1):
                print(invalid_command)
                continue
            print("Exiting demo...")
            quit()
        else:
            print(invalid_command)
            continue