From 59aa04c585f22fce7e8fabc9ee8fce6e30d2b1b1 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Thu, 30 Mar 2023 17:50:07 +0200 Subject: Fix reading output from rsync, which now uses local settings Add check for available space --- mageiaSync/mageiaSyncExt.py | 42 ++++++++++++++++++++++++++---------------- mageiaSync/mageiasync.py | 3 ++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/mageiaSync/mageiaSyncExt.py b/mageiaSync/mageiaSyncExt.py index 2f29fa4..55eac1e 100644 --- a/mageiaSync/mageiaSyncExt.py +++ b/mageiaSync/mageiaSyncExt.py @@ -5,7 +5,10 @@ Created on Sat Jul 12 21:42:56 2014 @author: yves """ -import re, os, gnupg +import re +import os +import gnupg +import shutil from subprocess import Popen, PIPE from PyQt5.QtCore import QDir, QFileInfo,pyqtSignal,QThread @@ -98,9 +101,9 @@ class syncThread(QThread): self.stopped=False self.list=[] - def setup(self,nameWithPath, destination,row,): + def setup(self,nameWithPath, destination, size, row,): # row is the index in 'model' - iso={'nameWithPath':str(nameWithPath),'destination':str(destination),'row':row} + iso={'nameWithPath':str(nameWithPath), 'destination':str(destination), 'row':row, 'size':size} self.list.append(iso) def params(self, password, bwl): @@ -122,6 +125,11 @@ class syncThread(QThread): if len(self.list)==0: self.lvM.emit(self.tr("No entry selected")) for iso in self.list: + # Check free space + _, _, free = shutil.disk_usage(self.destination) + if free <= iso("size"): + self.lvM.emit( self.tr("Space available {:.3f} Mb isn't enough ({:.3f} Mb needed)"). format(free/1024/1024, iso["size"]/1024/1024)) + continue errorOccured=True self.lvM.emit(self.tr("Starting rsync with ")+iso['nameWithPath']) if self.bwl!=0: @@ -129,12 +137,11 @@ class syncThread(QThread): else: commande=['rsync','-avP','--no-p','--modify-window=1', iso['nameWithPath'], iso['destination']] try: + envir = os.environ.copy() + envir['LC_ALL']="C" if self.password != "": - envir = os.environ.copy() envir['RSYNC_PASSWORD']=str(self.password) - self.process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE, env=envir) - else: - self.process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE) + self.process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE, env=envir) errorOccured=False except OSError as e: self.endSignal.emit(1) @@ -156,27 +163,31 @@ class syncThread(QThread): speedM=re.findall("([0-9.]*)MB/s", buf) remain=re.findall("[0-9]*:[0-9]*:[0-9]*",buf) sizeB=re.findall("[1-9](?:\d{0,2})(?:,\d{3})*",buf) + failed=re.findall("\(28\)",buf) if len(progressL) != 0: - progress= float(progressL[0]) + progress= int(progressL[0]) self.progressSignal.emit(progress) if len(sizeB) != 0: - self.sizeSignal.emit(sizeB[0].replace(","," ")) + self.sizeSignal.emit(sizeB[0].replace(","," ")) else: if (len(buf) !=0): self.lvM.emit(buf.rstrip()) if len(speedK) != 0: speed= float(speedK[0]) - self.speedSignal.emit(speed) + self.speedSignal.emit(int(speed)) if len(speedM) != 0: speed= 1024*float(speedM[0]) - self.speedSignal.emit(speed) + self.speedSignal.emit(int(speed)) if len(remain) != 0: self.remainSignal.emit(remain[0]) + if len(failed) != 0: + # no space left + self.stopped = True + self.lvM.emit(self.tr("Ending with {}, no space left").format(iso['nameWithPath'])) buf="" self.process.poll() if self.process.returncode != None: break - self.lvM.emit(self.tr("Ending with ")+iso['nameWithPath']) if self.stopped: break else: @@ -252,12 +263,11 @@ class findIsos(QThread): # List the remote directory commande = ['rsync', '-avHP', '--list-only',str(self.path)] try: + envir = os.environ.copy() + envir['LC_ALL']="C" if self.password != "": - envir = os.environ.copy() envir['RSYNC_PASSWORD']=str(self.password) - process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE, env=envir) - else: - process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE) + process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE, env=envir) except OSError as e: self.lvM.emit(self.tr("Command rsync not found: ")+str(e)) self.endSignal.emit(1) diff --git a/mageiaSync/mageiasync.py b/mageiaSync/mageiasync.py index 068d779..ffc8015 100644 --- a/mageiaSync/mageiasync.py +++ b/mageiaSync/mageiasync.py @@ -523,6 +523,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow): remoteRow = isoIndex.row() path = self.modelRemote.data(self.modelRemote.index(remoteRow,0)) name = self.modelRemote.data(self.modelRemote.index(remoteRow,1)) + size = int(self.modelRemote.data(self.modelRemote.index(remoteRow,2)).replace(" ","")) try: # Look for ISO in local list item=self.model.findItems(name,QtCore.Qt.MatchExactly,1)[0] @@ -539,7 +540,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow): self.nameWithPath=self.location+path if (not str(path).endswith('/')): self.nameWithPath+='/' - self.rsyncThread.setup(self.nameWithPath, self.destination+'/'+path+'/',row) + self.rsyncThread.setup(self.nameWithPath, self.destination+'/'+path+'/', size, row) self.rsyncThread.start() # start the thread def closeFill(self,code): -- cgit v1.2.1