aboutsummaryrefslogtreecommitdiffstats
path: root/mageiasync
diff options
context:
space:
mode:
authorpapoteur-mga <yves.brungard_git@gadz.org>2014-09-20 13:53:04 +0200
committerpapoteur-mga <yves.brungard_git@gadz.org>2014-09-20 13:53:04 +0200
commit9b2c3e138b8209010d5a0135533454db7e1496db (patch)
treecf242209d850fe77879a34773a9fcea2a451c931 /mageiasync
parent5e078bf8f2c40e5d559656cd65dd219903cbcfa0 (diff)
downloadMageiaSync-9b2c3e138b8209010d5a0135533454db7e1496db.tar
MageiaSync-9b2c3e138b8209010d5a0135533454db7e1496db.tar.gz
MageiaSync-9b2c3e138b8209010d5a0135533454db7e1496db.tar.bz2
MageiaSync-9b2c3e138b8209010d5a0135533454db7e1496db.tar.xz
MageiaSync-9b2c3e138b8209010d5a0135533454db7e1496db.zip
Adding python3 compatibility
Diffstat (limited to 'mageiasync')
-rw-r--r--mageiasync/mageiaSyncExt.py27
-rw-r--r--mageiasync/mageiasync.py85
2 files changed, 57 insertions, 55 deletions
diff --git a/mageiasync/mageiaSyncExt.py b/mageiasync/mageiaSyncExt.py
index 95db0d8..65c0554 100644
--- a/mageiasync/mageiaSyncExt.py
+++ b/mageiasync/mageiaSyncExt.py
@@ -29,7 +29,7 @@ class checkThread(QThread):
try:
with open(self.destination+'/'+self.path+'/'+self.name, 'rb') as f:
while True:
- block = f.read(2**10)
+ block = f.read(2**10)
if not block: break
hashfunc.update(block)
sumcalc=hashfunc.hexdigest()
@@ -44,7 +44,7 @@ class checkThread(QThread):
if sumcalc==sumcheck:
return True
return False
-
+
def processDate(self):
import datetime as datetime
import time
@@ -68,13 +68,13 @@ class checkThread(QThread):
return True
else:
return False
-
+
def setup(self, destination, path,name,isoIndex):
self.destination=destination
self.path=path
self.name=name
self.isoIndex=isoIndex
-
+
def run(self):
signal=200+self.isoIndex
isoSize=QFileInfo(str(self.destination)+'/'+self.path+'/' +self.name).size()
@@ -92,7 +92,7 @@ class checkThread(QThread):
checkDate=self.processDate()
self.dateSignal.emit(self.isoIndex+128*checkDate)
self.quit()
-
+
class syncThread(QThread):
progressSignal = pyqtSignal(int)
@@ -116,7 +116,7 @@ class syncThread(QThread):
def params(self, password, bwl):
self.password=password
self.bwl=bwl # Bandwith limit
-
+
def stop(self):
self.stopped=True
try:
@@ -126,7 +126,7 @@ class syncThread(QThread):
self.lvM.emit("Process rsync already stopped")
# Init progressbar and speed counter
self.endSignal.emit(0)
-
+
def run(self):
if len(self.list)==0:
self.lvM.emit("No entry selected")
@@ -157,7 +157,7 @@ class syncThread(QThread):
if not errorOccured:
buf=''
while not self.stopped:
- letter=self.process.stdout.read(1)
+ letter=self.process.stdout.read(1).decode('unicode_escape')
buf=buf+letter
if letter=='\n' or letter=='\r':
progressL=re.findall("([0-9]*)%", buf)
@@ -226,13 +226,14 @@ class findIsos(QThread):
self.path=path
self.password=password
self.destination=destination
+ self.lvM.emit(path+password+destination)
def getList(self):
return self.list
def getLocal(self):
return self.localList
-
+
def run(self):
# Lists ISO files in local directory
root=QDir(self.destination)
@@ -259,7 +260,7 @@ class findIsos(QThread):
except OSError as e:
self.lvM.emit("Command rsync not found: "+str(e))
self.endSignal.emit(1)
- return
+ return
except ValueError as e:
self.lvM.emit("Error in rsync parameters: "+str(e))
self.endSignal.emit(2)
@@ -271,8 +272,9 @@ class findIsos(QThread):
return
process.poll()
while True :
- item=process.stdout.readline().rstrip()
- if item.lower().endswith('.iso') :
+ item=process.stdout.readline().rstrip().decode('unicode_escape')
+ self.lvM.emit(item)
+ if str(item.lower()).endswith('.iso') :
words=item.split()
self.list.append(words[-1])
process.poll()
@@ -280,4 +282,3 @@ class findIsos(QThread):
break
self.endSignal.emit(0)
-#syncIso('rsync://ftp5.gwdg.de/pub/linux/mageia/iso/4.1/Mageia-4.1-LiveCD-GNOME-en-i586-CD/', "/documents/Mageia-4/Mageia-4.1-LiveCD-GNOME-en-i586-CD/", "y8d5qr38728128I") \ No newline at end of file
diff --git a/mageiasync/mageiasync.py b/mageiasync/mageiasync.py
index 1469996..25ff2b6 100644
--- a/mageiasync/mageiasync.py
+++ b/mageiasync/mageiasync.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
-
-from PyQt5.QtWidgets import ( QApplication, QProgressDialog, QMainWindow,
- QDialog, QFileDialog,)
+
+from PyQt5.QtWidgets import ( QProgressDialog, QMainWindow,
+ QDialog, QFileDialog, QApplication)
from PyQt5.QtGui import ( QStandardItemModel,QStandardItem, )
from PyQt5 import QtCore # , Qt, QThread, QObject, pyqtSignal)
import sys
@@ -12,7 +12,7 @@ import mageiaSyncDBrename
class prefsDialog(QDialog,mageiaSyncDBprefs.Ui_prefsDialog ):
-
+
def __init__(self, parent=None):
QDialog.__init__(self,parent)
self.setupUi(self)
@@ -20,7 +20,7 @@ class prefsDialog(QDialog,mageiaSyncDBprefs.Ui_prefsDialog ):
class renameDialog(QDialog,mageiaSyncDBrename.Ui_renameDialog ):
# Display a dialog box to choose to rename an old collection of ISOs to a new one
-
+
def __init__(self, parent=None):
QDialog.__init__(self,parent)
self.setupUi(self)
@@ -29,7 +29,7 @@ class renameDialog(QDialog,mageiaSyncDBrename.Ui_renameDialog ):
class LogWindow(QProgressDialog):
# Display a box at start during the remote directory list loading
-
+
def __init__(self, parent=None):
super(LogWindow, self).__init__(parent)
self.setWindowModality(QtCore.Qt.WindowModal)
@@ -40,13 +40,13 @@ class LogWindow(QProgressDialog):
self.setAutoReset(False)
self.setAutoClose(False)
self.setMinimumDuration(1)
-
+
def perform(self):
self.progressDialog.setValue(self.progress)
-
+
class dbWarning(QProgressDialog):
# Display a box at start during the remote directory list loading
-
+
def __init__(self, parent=None):
super(dbWarning, self).__init__(parent)
self.setWindowModality(QtCore.Qt.WindowModal)
@@ -57,10 +57,10 @@ class dbWarning(QProgressDialog):
self.setAutoReset(False)
self.setAutoClose(False)
self.setMinimumDuration(1)
-
+
def perform(self):
self.progressDialog.setValue(self.progress)
-
+
class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
# Display the main window
def __init__(self, parent=None):
@@ -75,16 +75,16 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
self.stop.setEnabled(False)
self.destination=''
self.rsyncThread = mageiaSyncExt.syncThread(self) # create a thread to launch rsync
- self.rsyncThread.progressSignal.connect(self.setProgress)
- self.rsyncThread.speedSignal.connect(self.setSpeed)
- self.rsyncThread.sizeSignal.connect(self.setSize)
- self.rsyncThread.remainSignal.connect(self.setRemain)
- self.rsyncThread.endSignal.connect(self.syncEnd)
+ self.rsyncThread.progressSignal.connect(self.setProgress)
+ self.rsyncThread.speedSignal.connect(self.setSpeed)
+ self.rsyncThread.sizeSignal.connect(self.setSize)
+ self.rsyncThread.remainSignal.connect(self.setRemain)
+ self.rsyncThread.endSignal.connect(self.syncEnd)
self.rsyncThread.lvM.connect(self.lvMessage)
self.rsyncThread.checkSignal.connect(self.checks)
self.checkThreads=[] # A list of thread for each iso
- # Model for list view in a table
+ # Model for list view in a table
self.model = QStandardItemModel(0, 6, self)
headers=["Directory","Name","Size","Date","SHA1","MD5"]
i=0
@@ -103,7 +103,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
def multiSelect(self):
# allows to select multiple lines in remote ISOs list
self.listIsos.setSelectionMode(2)
-
+
def add(self, iso):
# Add an remote ISO in list
self.listIsos.addItem(iso)
@@ -115,7 +115,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
if isoSize==0:
itemSize=QStandardItem('--')
else:
- formatedSize='{:n}'.format(isoSize) #.replace(","," ")
+ formatedSize='{:n}'.format(isoSize).replace(","," ")
itemSize=QStandardItem(formatedSize)
itemSize.setTextAlignment(QtCore.Qt.AlignVCenter|QtCore.Qt.AlignHCenter)
itemDate=QStandardItem("--/--/--")
@@ -126,7 +126,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
itemCheck5.setTextAlignment(QtCore.Qt.AlignVCenter|QtCore.Qt.AlignHCenter)
self.model.appendRow([itemPath,itemIso,itemSize,itemDate, itemCheck1, itemCheck5,])
self.localListNames.append([path,iso])
-
+
def setProgress(self, value):
# Update the progress bar
self.IprogressBar.setValue(value)
@@ -138,11 +138,11 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
def setSize(self, value):
# Update the size field
self.Lsize.setText(str(value)+" bytes")
-
+
def setRemain(self,remainTime):
content=QtCore.QTime.fromString(remainTime,"h:mm:ss")
self.timeRemaining.setTime(content)
-
+
def checks(self,isoIndex):
# process a checking for each iso
# launches a thread for each iso
@@ -162,7 +162,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
col=(int)(isoIndex/100)
row=isoIndex-col*100
self.model.setData(self.model.index(row, col, QtCore.QModelIndex()), "Checking")
-
+
def md5Check(self,check):
if check>=128:
val="OK"
@@ -180,7 +180,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
val="Failed"
row=check
self.model.setData(self.model.index(row, 4, QtCore.QModelIndex()), val)
-
+
def dateCheck(self,check):
if check>=128:
val="OK"
@@ -193,8 +193,8 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
def sizeUpdate(self,signal,isoSize):
col=(int)(signal/100)
row=signal-col*100
- self.model.setData(self.model.index(row, col, QtCore.QModelIndex()), '{:n}'.format(isoSize))
-
+ self.model.setData(self.model.index(row, col, QtCore.QModelIndex()), '{:n}'.format(isoSize).replace(","," "))
+
def syncEnd(self, rc):
if rc==1:
self.lvMessage("Command rsync not found")
@@ -251,11 +251,11 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
def selectDestination(self):
# dialog box to select the destination (local directory)
- directory = QFileDialog.getExistingDirectory(self, 'Select a directory','~/')
- isosSync.destination = directory
+ directory = QFileDialog.getExistingDirectory(self, 'Select a directory','~/')
+ isosSync.destination = directory
self.pd.selectDest.setText(isosSync.destination)
-
+
def selectAllIsos(self):
# Select or unselect the ISOs in remote list
if self.selectAllState :
@@ -275,7 +275,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
self.actionPreferences.triggered.connect(self.prefs)
self.syncGo.clicked.connect(self.launchSync)
self.selectAll.clicked.connect(self.selectAllIsos)
-
+
def updateList(self):
# From the menu entry
self.lw = LogWindow()
@@ -284,21 +284,22 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
self.model.removeRows(0,self.model.rowCount())
if self.location == "" :
self.nameWithPath='rsync://'+self.user+'@bcd.mageia.org/isos/'+self.release+'/'
- print self.nameWithPath
+# print self.nameWithPath
else:
self.nameWithPath=self.location+'/'
+ self.lvMessage("Source: "+self.nameWithPath)
self.fillList = mageiaSyncExt.findIsos()
self.fillList.setup(self.nameWithPath, self.password,self.destination)
self.fillList.endSignal.connect(self.closeFill)
self.fillList.start()
-
+
def lvMessage( self,message):
- # Add a line in the logview
+ # Add a line in the logview
self.lvText.append(message)
-
+
def renameDir(self):
# Choose the directory where isos are stored
- directory = QFileDialog.getExistingDirectory(self, 'Select a directory',self.destination)
+ directory = QFileDialog.getExistingDirectory(self, 'Select a directory',self.destination)
self.rd.chooseDir.setText(directory)
def rename(self):
@@ -314,7 +315,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
returnMsg=mageiaSyncExt.rename(self.rd.chooseDir.text(),self.rd.oldRelease.text(),self.rd.newRelease.text())
self.lvMessage(returnMsg)
self.rd.close()
-
+
def prefs(self):
# From the menu entry
self.pd=prefsDialog()
@@ -335,8 +336,8 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
params.setValue("bwl",str(self.pd.bwl.value()))
self.prefsInit()
self.pd.close()
-
-
+
+
def launchSync(self):
self.IprogressBar.setEnabled(True)
self.stop.setEnabled(True)
@@ -388,7 +389,7 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
self.localAdd(path,iso, isoSize)
self.fillList.quit()
self.lw.hide()
-
+
def stopSync(self):
self.rsyncThread.stop()
self.IprogressBar.setEnabled(False)
@@ -405,14 +406,14 @@ class IsosViewer(QMainWindow, mageiaSyncUI.Ui_mainWindow):
# look for Isos list and add it to the isoSync list. Update preferences
self.updateList()
self.multiSelect()
-
+
def close(self):
self.rsyncThread.stop()
exit(0)
-
-
+
if __name__=='__main__':
app = QApplication(sys.argv)
isosSync = IsosViewer()
isosSync.main()
sys.exit(app.exec_())
+