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


Python File.get_file_size方法代码示例

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


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

示例1: added

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import get_file_size [as 别名]
    def added(self, path, client):
        path = path.replace("\\", "/")
        file_extension_pattern=self.path_to_watch+"/chunks"
        if (re.search("Thumbs.db", path) == None):
            # Checks if folder is chunks, only if it isn't it will send modifications
            if (re.search(file_extension_pattern,path) == None):
                # Prints message of file added
                print_message("Added: " + path)

                if (os.path.isfile(path)):
                    # Creates file information
                    f = File(path, client)
                    f.generate_file_id()
                    f.get_salt()
                    file_size = f.get_file_size()

                    # Gets relative_path location
                    relative_path = path.split(self.path_to_watch)[1].replace("\\", "/")
                    modification_date = f.get_modification_date().replace(" ", "T").split(".")[0] +"Z"
                    # Sends request to server with information about the new file
                    url = self.api+'files/create.php'
                    values = {'apikey': '12',
                              'path': relative_path,
                              'user': client.get_email(),
                              'modification': f.get_file_id(),
                              'dateModified': modification_date,
                              'size': str(int(file_size))
                              }
                    response = json_request(url, values)
                    if (response['result'] == 'notEnoughSpace'):
                        print_message("Not enough space. Space left to use " + str(response['spaceLeft']))
                        window = Tkinter.Tk()
                        window.wm_withdraw()

                        tkMessageBox.showerror(title="Budibox", message="Not enough space! Space left to use " + str(response['spaceLeft']) + "bytes !")
                        return

                    if (response['result'] != 'ok'):
                        print_message("Error sending information created about file " + path)
                        return

                    print_message("Created file " + path + " successfully")

                    url = self.api+'files/getId.php'
                    values = {'apikey': '12',
                              'path': relative_path,
                              'user': client.get_email(),
                              }

                    response = json_request(url, values)

                    if (response['result'] != 'ok'):
                        print_message("Error getting fileId of " + path)
                        return

                    print_message("Get fileId of " + path + "successfully")

                    # Send information about chunks to server
                    db_file_id = response['id']
                    f.generate_chunks(db_file_id)
开发者ID:hsdrose,项目名称:feup-sdis-budibox,代码行数:62,代码来源:watcher.py

示例2: modified

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import get_file_size [as 别名]
    def modified(self, path, client):
        path = path.replace("\\", "/")
        file_extension_pattern=self.path_to_watch+"/chunks"

        if (re.search("Thumbs.db", path) == None):
            # Checks if folder is chunks, only if it isn't it will send notifications
            if (re.search(file_extension_pattern,path) != None):
                if (os.path.isfile(path)):
                    print_message("Modified in chunks path: " + path)
                    file_name = path.replace(file_extension_pattern, "")
                    modification = file_name.split("_")[0].replace("/", "")
                    chunk_number = file_name.split("_")[1].split(".")[0]
                    url = self.api+'chunks/deleted.php'
                    values = {'apikey': '12',
                              'modification': modification,
                              'number': chunk_number,
                              'computerId': self.computer_id
                              }

                    response = json_request(url, values)



                    if (response['result'] == 'ok'):
                        print_message("Deleted chunk successfully " + file_name)

                    else:
                        print_message("Error sending delete chunk message of " + file_name)
            else:
                if (os.path.isfile(path)):
                    print_message("Modified " +  path)
                    # Creates file information
                    f = File(path, client)
                    f.generate_file_id()
                    f.get_salt()
                    file_size = f.get_file_size()

                    # Gets relative_path location
                    relative_path = path.split(self.path_to_watch)[1].replace("\\", "/")
                    modification_date = f.get_modification_date().replace(" ", "T").split(".")[0] +"Z"
                    # Sends request to server with information about the new file
                    url = self.api+'files/modify.php'
                    values = {'apikey': '12',
                              'path': relative_path,
                              'user': client.get_email(),
                              'modification': f.get_file_id(),
                              'dateModified': modification_date,
                              'size': str(int(file_size))
                              }

                    response = json_request(url, values)

                    if (response['result'] == 'notEnoughSpace'):
                        print_message("Not enough space. Space left to use " + str(response['spaceLeft']))
                        window = Tkinter.Tk()
                        window.wm_withdraw()

                        tkMessageBox.showerror(title="Budibox", message="Not enough space! Space left to use " + str(response['spaceLeft']) + "bytes !")
                        return


                    if (response['result'] != 'ok'):
                        print_message("Error sending information modify about file " + path)
                        return

                    print_message("Sent modify message of: " + path)

                    url = self.api+'files/getId.php'
                    values = {'apikey': '12',
                              'path': relative_path,
                              'user': client.get_email(),
                              }

                    response = json_request(url, values)

                    if (response['result'] != 'ok'):
                        print_message("Error getting fileId of " + path)
                        return

                    # Send information about chunks to server
                    db_file_id = response['id']
                    f.generate_chunks(db_file_id)
开发者ID:hsdrose,项目名称:feup-sdis-budibox,代码行数:84,代码来源:watcher.py


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