def update(self, count, block_size, total): if not self.initiatlized: self.initiatlized = True self.pb = view.ProgressBar(total=total, rate_refresh=self.rate_refresh, count=0, name=self.name) self.view.add_progress_bar(self.pb) else: self.pb.update(block_size) self.view.update_progress_bars()
def __upload(self, filepath, filename, token, stamp, server, port): """ Wysylanie pliku znajdujacego sie pod 'filepath' i nazwanie go 'filename' #TODO: Opis i podpis """ #Tworzenie naglowka size = os.path.getsize(filepath) header, contenttail = self.__create_header(server, port, token, stamp, filename, size) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(glob_timeout) ip = socket.gethostbyname_ex(server)[2][0] sock.connect((ip, int(port))) sock.send(header) f = open(filepath, 'rb') pb = view.ProgressBar(total=size, rate_refresh=0.5, count=0, name=filepath) self.view.add_progress_bar(pb) last_time = time.time() #g = open("log_upload" + filename + ".txt", "w") #time.sleep(random.random()*10) #g.write(header) #g.close() try: while True: chunk = f.read(1024) if not chunk: break #g.write(chunk) #self.view.print_( 'Sending Chunk: ' + str(len(chunk)) ) sock.send(chunk) #self.view.print_( 'Chunk sent' ) pb.update(len(chunk)) #self.view.print_( 'Updating progressbar' ) now = time.time() if now - last_time > 0.5: self.view.update_progress_bars() last_time = now f.close() #self.view.print_( 'Sending tail' ) sock.send(contenttail) except Exception, e: if self.debug: trbck = sys.exc_info()[2] debug_fun(trbck) raise e
def __resume(self, filepath, filename, token, server, port, stamp, filesize_sent): """ Wznawianie uploadowania pliku filepath o nazwie filename o danych: folder_id, chomik_id, token, server, port, stamp """ #Tworzenie naglowka size = os.path.getsize(filepath) header, contenttail = self.__create_header(server, port, token, stamp, filename, (size - filesize_sent), resume_from=filesize_sent) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(glob_timeout) ip = socket.gethostbyname_ex(server)[2][0] sock.connect((ip, int(port))) sock.send(header) f = open(filepath, 'rb') f.seek(filesize_sent) pb = view.ProgressBar(total=size, rate_refresh=0.5, count=filesize_sent, name=filepath) self.view.add_progress_bar(pb) last_time = time.time() #g = open("log_resume" + filename + ".txt", "w") #g.write(header) #g.close() try: while True: chunk = f.read(1024) if not chunk: break sock.send(chunk) pb.update(len(chunk)) now = time.time() if now - last_time > 0.5: self.view.update_progress_bars() last_time = now f.close() sock.send(contenttail) except Exception, e: if self.debug: trbck = sys.exc_info()[2] debug_fun(trbck) raise e