aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mageiaSync/mageiaSyncExt.py35
-rw-r--r--mageiaSync/mageiasync.py9
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()