diff options
author | Papoteur <papoteur@mageialinux-online.org> | 2016-05-05 15:51:59 +0200 |
---|---|---|
committer | Papoteur <papoteur@mageialinux-online.org> | 2016-05-05 15:51:59 +0200 |
commit | 4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8 (patch) | |
tree | 1aa4648a8c190b881d5045a42cb20e7344727102 /mageiaSync | |
parent | bfa0ea4ee5af8bdd068a072aaf52a321104dc7eb (diff) | |
download | MageiaSync-4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8.tar MageiaSync-4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8.tar.gz MageiaSync-4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8.tar.bz2 MageiaSync-4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8.tar.xz MageiaSync-4b6d6fdd2d704c1446e1235d9f126cb23e10e3a8.zip |
Add the count of renamed files and directories.
Diffstat (limited to 'mageiaSync')
-rw-r--r-- | mageiaSync/mageiaSyncExt.py | 35 | ||||
-rw-r--r-- | mageiaSync/mageiasync.py | 9 |
2 files changed, 24 insertions, 20 deletions
diff --git a/mageiaSync/mageiaSyncExt.py b/mageiaSync/mageiaSyncExt.py index 5c79ec9..451f73e 100644 --- a/mageiaSync/mageiaSyncExt.py +++ b/mageiaSync/mageiaSyncExt.py @@ -200,21 +200,26 @@ class syncThread(QThread): self.list=[] self.quit() -def rename(directory,oldRelease,newRelease): - options=['d', 'f'] - for option in options: - commande=['find', directory, '-type' ,option, '-exec','rename',oldRelease,newRelease, '{}', '+'] - process = Popen(commande, shell=False, stdout=PIPE, stderr=PIPE) - process.poll() - while True : - item=process.stdout.readline().rstrip() - process.poll() - if process.returncode != None: - if process.returncode!=0: - item=process.stderr.readline().rstrip() - return 1, item - break - return 0 #"Success in renaming" +def rename(directory,oldRelease,newRelease, nbf, nbr): + # nbf: number of files renamed + # nbr: number of directories renamed + # the function is recursive + for entry in os.listdir(directory): + name = entry + entry=os.path.join(directory,entry) + print(entry, os.path.isfile(entry), os.path.isdir(entry), name.startswith(oldRelease)) + if os.path.isfile(entry): + if name.startswith(oldRelease): + newPath = os.path.join( os.path.dirname(entry) , name.replace(oldRelease, newRelease,1)) + os.rename(entry, newPath) + nbf = nbf + 1 + if os.path.isdir(entry): + nbf, nbr = rename(entry,oldRelease,newRelease, nbf, nbr) + if name.startswith(oldRelease) : + newPath = os.path.join( os.path.dirname(entry) , name.replace(oldRelease, newRelease,1)) + os.rename(entry, newPath) + nbr = nbr + 1 + return nbf, nbr class findIsos(QThread): endSignal=pyqtSignal(int) diff --git a/mageiaSync/mageiasync.py b/mageiaSync/mageiasync.py index 9dc4c7b..3582e2a 100644 --- a/mageiaSync/mageiasync.py +++ b/mageiaSync/mageiasync.py @@ -447,11 +447,10 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow): self.rd.chooseDir.setText(self.destination) answer=self.rd.exec_() if answer: - returncode=mageiaSyncExt.rename(self.rd.chooseDir.text(),self.rd.oldRelease.text(),str(self.rd.newRelease.text())) - if returncode==1: - returnMsg="Error in renaming" - else: - returnMsg=self.tr("Success in renaming") + nbf, nbr = mageiaSyncExt.rename(self.rd.chooseDir.text(),\ + self.rd.oldRelease.text(),str(self.rd.newRelease.text()),\ + 0,0) + returnMsg=(self.tr("Renaming {0} files and {1} directories")).format(nbf, nbr) self.lvMessage(returnMsg) self.updateList() self.rd.close() |