当前位置: 首页>>代码示例>>Python>>正文


Python Memory.deleteFile方法代码示例

本文整理汇总了Python中memory.Memory.deleteFile方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.deleteFile方法的具体用法?Python Memory.deleteFile怎么用?Python Memory.deleteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.deleteFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Memory

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import deleteFile [as 别名]
from memory import Memory

m = Memory()

r = m.alloc("xyz", 14)
print r
print m

r = m.alloc("abc", 12)
print r
print m




r = m.read("xyz", 4, 5)
print r
print m

r = m.deleteFile("xyz")
print r
print m

r = m.deleteFile("abc")
print r
print m
开发者ID:not-inept,项目名称:opsys-p4-server-and-clustered-memory,代码行数:28,代码来源:memtest1.py

示例2: set

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import deleteFile [as 别名]

#.........这里部分代码省略.........
        args[2] = int(args[2])
        if args[1] in self.files:
            client.send("ERROR: FILE EXISTS.\n")
            print "[thread", thread + "] Sent: ERROR: FILE EXISTS."
            data = client.recv(args[2])  # can we assume data will be sent regardless of error?
            return
        response = self.memory.alloc(args[1], args[2])
        if not response[0]:
            client.send("ERROR: INSUFFICIENT DISK SPACE.\n")
            print "[thread", thread + "] Sent: ERROR: INSUFFICIENT DISK SPACE."
            data = client.recv(args[2])  # can we assume data will be sent regardless of error?
            return
        # actually do the storing stuff
        data = client.recv(args[2])
        f = open(".storage/" + args[1], "w")
        f.write(data)
        self.files.add(args[1])
        print "[thread", thread + "] Stored file '%s' (%s bytes; %s blocks; %s" % response, (
            "cluster" if response[3] == 1 else "cluster"
        ) + ")"
        print "[thread", thread + "] Simulated Clustered Disk Space Allocation:"
        print self.memory
        client.send("ACK\n")
        print "[thread", thread + "] Sent: ACK"

    def read(self, client, args):
        thread = str(threading.current_thread().ident)
        if len(args) != 4:
            client.send("ERROR: INVALID COMMAND.\n")
            print "[thread", thread + "] Sent: ERROR: INVALID COMMAND."
            return
        if args[1] not in self.files:
            client.send("ERROR: NO SUCH FILE.\n")
            print "[thread", thread + "] Sent: ERROR: NO SUCH FILE."
            return
        args[2] = int(args[2])
        args[3] = int(args[3])
        data = open(".storage/" + args[1], "r").read()
        if args[2] + args[3] > len(data) or args[2] < 0 or args[3] < 0:
            client.send("ERROR: INVALID BYTE RANGE.\n")
            print "[thread", thread + "] Sent: ERROR: INVALID BYTE RANGE."
            return
        # TODO: (1) Memory dump / print output
        result = "ACK " + str(args[3]) + "\n" + data[args[2] : args[2] + args[3]]
        print "[thread", thread + "] Sent: ACK", args[3]
        client.send(result)
        response = self.memory.read(args[1], args[2], args[3])
        print "[thread", thread + "] Sent %s bytes (from %s '%s' blocks) from offset %s." % response

    def delete(self, client, args):
        thread = str(threading.current_thread().ident)
        if len(args) != 2:
            client.send("ERROR: INVALID COMMAND.\n")
            print "[thread", thread + "] Sent: INVALID COMMAND."
            return
        if args[1] not in self.files:
            client.send("ERROR: NO SUCH FILE.\n")
            print "[thread", thread + "] Sent: ERROR: NO SUCH FILE."
            return
        os.remove(".storage/" + args[1])
        self.files.remove(args[1])
        response = self.memory.deleteFile(args[1])
        client.send("ACK\n")
        print "[thread", thread + "] Deleted", args[1], "file '%s' (deallocated %s blocks)" % response
        print "[thread", thread + "] Simulated Clustered Disk Space Allocation:"
        print self.memory
        print "[thread", thread + "] Sent: ACK"

    def dir(self, client):
        thread = str(threading.current_thread().ident)
        files_sorted = sorted(self.files, key=str.lower)
        result = str(len(self.files)) + "\n"
        for f in files_sorted:
            result += f + "\n"
        print "[thread", thread + "] Sent list of %d" % len(self.files), (
            "file" if len(self.files) == 1 else "files"
        ) + "."
        client.send(result)

    def handler(self, cmd, client):
        # Handles specific client connections until they close
        thread = str(threading.current_thread().ident)
        while cmd:
            print "[thread", thread + "] Rcvd:", cmd
            args = cmd.split(" ")
            args[0] = args[0].strip()
            if args[0] == "STORE":
                self.store(client, args)
            elif args[0] == "READ":
                self.read(client, args)
            elif args[0] == "DELETE":
                self.delete(client, args)
            elif args[0] == "DIR":
                self.dir(client)
            else:
                client.send("ERROR: INVALID COMMAND.\n")
                print "[thread", thread + "] Sent: ERROR: INVALID COMMAND."
            cmd = self.process_line(client).strip()
        print "[thread", thread + "] Client closed its socket....terminating."
        client.close()
开发者ID:not-inept,项目名称:opsys-p4-server-and-clustered-memory,代码行数:104,代码来源:server.py


注:本文中的memory.Memory.deleteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。