diff options
Diffstat (limited to 'mageiaSync/mageiaSyncExt.py')
-rw-r--r-- | mageiaSync/mageiaSyncExt.py | 42 |
1 files changed, 26 insertions, 16 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) |