aboutsummaryrefslogtreecommitdiffstats
path: root/mageiaSync/mageiaSyncExt.py
diff options
context:
space:
mode:
Diffstat (limited to 'mageiaSync/mageiaSyncExt.py')
-rw-r--r--mageiaSync/mageiaSyncExt.py35
1 files changed, 20 insertions, 15 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)