def test_cat_folder():
    home = Folder('home')
    working_dir = Folder('working_dir')
    working_dir = home
    folder1 = Folder('folder1', home)
    file1 = File(folder1, 'file1', 'txt', 1000)
    assert cat(working_dir, 'folder1') == str(folder1)
예제 #2
0
파일: repl.py 프로젝트: igebus/pypm
 def do_cat(self, args):
     'Usage: cat [-r] [GROUP]...\n' \
     'Prints content of entries included in given GROUP(s) (current group by default)\n'
     args = parse(args)
     if "-r" in args:
         recursive = True
         args.remove('-r')
     else:
         recursive = False
     args = [self.path + node_path if node_path[0] != '/' else node_path for node_path in args]
     if not len(args):
         args.append(self.path)
     result = commands.cat(args, recursive)
     print(result)
def test_cat_file():
    home = Folder('home')
    working_dir = Folder('working_dir')
    working_dir = home
    file1 = File(home, 'file1', 'txt', 1000)
    assert cat(working_dir, 'file1') == str(file1)
예제 #4
0
def main():
    home = Folder('home')
    working_dir = Folder('working_dir')
    working_dir = home
    answer = True
    starting_msg = "File system is working. Type help if needed or exit to end program."
    print(starting_msg)
    while answer:
        try:
            path = get_path(working_dir, home)

            answer = input(path).split()

            if answer[0] == "cd":
                new_working_dir = cd(answer, working_dir, home)
                if new_working_dir:
                    working_dir = new_working_dir
                else:
                    print("Incorrect usage of: cd. Try again")
            elif answer[0] == 'mkdir':
                # make folder
                try:
                    Folder(answer[1], working_dir)
                except Exception:
                    print("Incorrect usage of: mkdir. Try again")
            elif answer[0] == 'mk':
                # make file
                try:
                    File(working_dir, answer[1], answer[2], answer[3])
                except Exception:
                    print("Incorrect usage of: mk. Try again")
            elif answer[0] == 'rm':
                # delete file or folder
                if len(answer) == 2:
                    to_be_deleted = working_dir.find(answer[1])
                    if to_be_deleted:
                        print(rm(to_be_deleted, working_dir, home))
                    else:
                        print(f"Error. {answer[1]} - Element does not exist")
                else:
                    print("Incorrect usage of: rm. Try again")
            elif answer[0] == 'ls':
                # print structure
                print(ls(working_dir, answer))
            elif answer[0] == 'cat':
                # print file/folder info
                print(cat(working_dir, answer[1]))
            elif answer[0] == 'size':
                # print folder size
                try:
                    size = working_dir.find(answer[1]).count_size_recursive()
                    print(f'Size: {size} kB')
                except AttributeError:
                    print("Incorrect usage of: size. Try again")
            elif answer[0] == 'wc':
                # count elements in folder
                try:
                    print(wc(working_dir, answer))
                except Exception:
                    print("Incorrect usage of: wc. Try again")
            elif answer[0] == 'pwd':
                print(working_dir.name)
            elif answer[0] == 'cp':
                try:
                    cp(working_dir, answer, home)
                except Exception:
                    print("Incorrect usage of: cp. Try again")
            elif answer[0] == 'mv':
                try:
                    mv(working_dir, answer, home)
                except Exception:
                    print("Incorrect usage of: mv. Try again")
            elif answer[0] == 'help':
                print(help())
            elif answer[0] == 'exit':
                # end program
                answer = False
            else:
                print("Command not found")
        except IndexError:
            print("No command was given. Try again.")
            main()
예제 #5
0
from disk_manager import DiskManager
from commands import cat, ls
from document import File
from path import Path

if __name__ == "__main__":
    #Create a disk instance
    disk = DiskManager()
    #Create a command object instance
    path = Path('c:\sandbox')
    #Define our command
    cmd = ls(path)
    #set & call our command
    disk.setCommand(cmd)
    for d in disk.runCommand():
        print d

    # In[130]:

    #define our command Object (File)
    fileObj = File('c:\sandbox\ipconfig.txt')
    cmd = cat(fileObj)
    disk.setCommand(cmd)
    for line in disk.runCommand():
        print line
예제 #6
0
def on_cat(bot, update):
    path = update.message.text[4:].strip()
    user = update.message.from_user['username']
    bot.sendMessage(update.message.chat_id,
                    text='<pre>%s</pre>' % cat(user, path),
                    parse_mode='HTML')