def main(self, argv): f = File() f2 = File() f2.open() f.open() f.write() f2.close()
def decode(socket): fixed = bytearray(6) socket.recv_into(fixed, flags=MSG_WAITALL) file_path_length = byte_utils.bytes_to_char(fixed, 0) file_is_directory = byte_utils.bytes_to_boolean(fixed, 1) file_last_modified = byte_utils.bytes_to_unsigned_int(fixed, 2) file_size = None if not file_is_directory: fixed = bytearray(4) socket.recv_into(fixed, flags=MSG_WAITALL) file_size = byte_utils.bytes_to_unsigned_int(fixed, 0) strings = bytearray(file_path_length) socket.recv_into(strings, flags=MSG_WAITALL) file_path = byte_utils.bytes_to_string(strings, file_path_length, 0) if utils.DEBUG_LEVEL >= 3: utils.log_message("DEBUG", "Decoded send file packet: ") utils.log_message("DEBUG", "File path length: " + str(file_path_length)) utils.log_message("DEBUG", "Is directory: " + str(file_is_directory)) utils.log_message( "DEBUG", "Last modified: " + str(utils.format_timestamp(file_last_modified))) utils.log_message("DEBUG", "File size: " + str(file_size)) utils.log_message("DEBUG", "File Path: " + str(file_path)) # parse file's contents to File().write() 1024 chunks if is not directory if not file_is_directory: chunk_size = min(SendFilePacket.CHUNK_SIZE, file_size) remaining = file_size file_wrapper = File() received_bytes_acc = 0 while remaining > 0: if utils.DEBUG_LEVEL >= 3: utils.log_message("DEBUG", "Chunk size: " + str(chunk_size)) chunk = bytearray(chunk_size) received_bytes = socket.recv_into(chunk, flags=MSG_WAITALL) received_bytes_acc += received_bytes file_wrapper.write(chunk) remaining -= received_bytes chunk_size = min(chunk_size, remaining) file_wrapper.close() if utils.DEBUG_LEVEL >= 1: utils.log_message( "DEBUG", "File size is " + str(file_size) + " and received bytes are " + str(received_bytes_acc)) utils.log_message( "DEBUG", "File is located in " + str(file_wrapper.get_path())) else: file_wrapper = Directory() packet = SendFilePacket( FileInfo(file_path, file_is_directory, file_last_modified, file_size, file_wrapper)) return packet
def decode(socket): fixed = bytearray(6) socket.recv_into(fixed, flags=MSG_WAITALL) file_path_length = byte_utils.bytes_to_char(fixed, 0) file_is_directory = byte_utils.bytes_to_boolean(fixed, 1) file_last_modified = byte_utils.bytes_to_unsigned_int(fixed, 2) file_size = None if not file_is_directory: fixed = bytearray(4) socket.recv_into(fixed, flags=MSG_WAITALL) file_size = byte_utils.bytes_to_unsigned_int(fixed, 0) strings = bytearray(file_path_length) socket.recv_into(strings, flags=MSG_WAITALL) file_path = byte_utils.bytes_to_string(strings, file_path_length, 0) if utils.DEBUG_LEVEL >= 3: utils.log_message("DEBUG", "Decoded send file packet: ") utils.log_message("DEBUG", "File path length: " + str(file_path_length)) utils.log_message("DEBUG", "Is directory: " + str(file_is_directory)) utils.log_message("DEBUG", "Last modified: " + str(utils.format_timestamp(file_last_modified))) utils.log_message("DEBUG", "File size: " + str(file_size)) utils.log_message("DEBUG", "File Path: " + str(file_path)) # parse file's contents to File().write() 1024 chunks if is not directory if not file_is_directory: chunk_size = min(SendFilePacket.CHUNK_SIZE, file_size) remaining = file_size file_wrapper = File() received_bytes_acc = 0 while remaining > 0: if utils.DEBUG_LEVEL >= 3: utils.log_message("DEBUG", "Chunk size: " + str(chunk_size)) chunk = bytearray(chunk_size) received_bytes = socket.recv_into(chunk, flags=MSG_WAITALL) received_bytes_acc += received_bytes file_wrapper.write(chunk) remaining -= received_bytes chunk_size = min(chunk_size, remaining) file_wrapper.close() if utils.DEBUG_LEVEL >= 1: utils.log_message("DEBUG", "File size is " + str(file_size) + " and received bytes are " + str( received_bytes_acc)) utils.log_message("DEBUG", "File is located in " + str(file_wrapper.get_path())) else: file_wrapper = Directory() packet = SendFilePacket(FileInfo(file_path, file_is_directory, file_last_modified, file_size, file_wrapper)) return packet
def pdf2txt(path): outfile = "%s.txt" % ospath(path).stem if not ospath.exists(outfile): File.write(outfile, extract_text(path)) return outfile
def main(self, argv): f = File() f.open() f.write() f.close() print "Done."
def main(self, argv): f = File() f.open() f.write()