diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2023-01-22 02:02:13 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2023-01-22 02:02:13 +0100 |
commit | 86480e58eafc1fa3486e03155ed34e02b4595a24 (patch) | |
tree | 0e8f64c4003ea558e946b7a3347688904b451635 /kexi | |
parent | 135d005014a1e85295af4e379f026a361537ae5f (diff) | |
download | koffice-86480e58eafc1fa3486e03155ed34e02b4595a24.tar.gz koffice-86480e58eafc1fa3486e03155ed34e02b4595a24.zip |
Drop python2 support in scripts.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'kexi')
7 files changed, 123 insertions, 123 deletions
diff --git a/kexi/plugins/scripting/scripts/copycenter/CopyCenter.py b/kexi/plugins/scripting/scripts/copycenter/CopyCenter.py index edcc2891..7c934da3 100644 --- a/kexi/plugins/scripting/scripts/copycenter/CopyCenter.py +++ b/kexi/plugins/scripting/scripts/copycenter/CopyCenter.py @@ -27,7 +27,7 @@ class CopyCenter: return getattr(self.plugin, plugintype)(self.plugin) except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) return None def __init__(self, scriptpath): @@ -38,7 +38,7 @@ class CopyCenter: import os import sys if not os.path.exists(scriptpath): - print "The Path %s does not exist" % scriptpath + print("The Path %s does not exist" % scriptpath) else: import re regexp = re.compile('^CopyCenterPlugin(.*)\\.py$') @@ -47,17 +47,17 @@ class CopyCenter: if not os.path.isfile(file): continue m = regexp.match(f) if not m: continue - print "Plugin name=%s file=%s" % (m.group(1),file) + print("Plugin name=%s file=%s" % (m.group(1),file)) mylocals = {} try: - execfile(file, globals(), mylocals) - if mylocals.has_key("CopyCenterPlugin"): + exec(compile(open(file, "rb").read(), file, 'exec'), globals(), mylocals) + if "CopyCenterPlugin" in mylocals: plugin = mylocals.get("CopyCenterPlugin")(self) self.plugins[plugin.name] = self.Plugin(plugin) except: - print "Failed to import file=%s" % file + print("Failed to import file=%s" % file) import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) def getHomePath(self): """ Return the homedirectory. """ @@ -163,20 +163,20 @@ def runGuiApp(copycenter, name): #qt.TQObject.connect(self.listview, qt.SIGNAL("itemRenamed(QListViewItem*, int, const QString&)"), self.itemRenamed) def doubleClicked(self, **args): - print "CopyJobWidget.doubleClicked" + print("CopyJobWidget.doubleClicked") item = self.listview.selectedItem() if item and item.parent(): item.startRename(1) def readOptions(self,domnode,plugininst): - print "CopyJobWidget.readOptions plugintype=\"%s\"" % plugininst.plugintype + print("CopyJobWidget.readOptions plugintype=\"%s\"" % plugininst.plugintype) for node in domnode.childNodes: if node.nodeType == node.ELEMENT_NODE: v = node.getAttribute("value") plugininst.options[node.nodeName] = v - print "Option \"%s\" has value \"%s\" now." % (node.nodeName, v) + print("Option \"%s\" has value \"%s\" now." % (node.nodeName, v)) def jobfilecomboboxChanged(self, **args): - print "CopyJobWidget.jobfilecomboboxChanged" + print("CopyJobWidget.jobfilecomboboxChanged") import os import xml.dom.minidom filename = str(self.jobfilecombobox.currentText()) @@ -187,16 +187,16 @@ def runGuiApp(copycenter, name): sourcenode = elements.getElementsByTagName("Source")[0] destinationnode = elements.getElementsByTagName("Destination")[0] except: - raise "The XML-file \"%s\" does not contain a valid copy-job." % filename + raise Exception("The XML-file \"%s\" does not contain a valid copy-job." % filename) sourcepluginname = str(sourcenode.getAttribute('plugin')) if not self.dialog.sourcedata.combobox.listBox().findItem(sourcepluginname,qt.TQt.ExactMatch): - raise "There exists no plugin with the name \"%s\"." % sourcepluginname + raise Exception("There exists no plugin with the name \"%s\"." % sourcepluginname) self.dialog.sourcedata.combobox.setCurrentText(sourcepluginname) destinationpluginname = str(destinationnode.getAttribute('plugin')) if not self.dialog.destinationdata.combobox.listBox().findItem(destinationpluginname,qt.TQt.ExactMatch): - raise "There exists no plugin with the name \"%s\"." % destinationpluginname + raise Exception("There exists no plugin with the name \"%s\"." % destinationpluginname) self.dialog.destinationdata.combobox.setCurrentText(destinationpluginname) self.readOptions(sourcenode,self.dialog.getSourcePluginImpl()) @@ -213,10 +213,10 @@ def runGuiApp(copycenter, name): return s.replace("&", "&").replace("'", "'").replace("<", "<").replace(">", ">").replace('"', """) def writeOptions(self,writer,pluginname,plugininst): - print "CopyJobWidget.writeOptions" + print("CopyJobWidget.writeOptions") writer.write("<%s plugin=\"%s\">\n" % (plugininst.plugintype, pluginname)) for optionname in plugininst.options: - value = self.escape( unicode(plugininst.options[optionname]).encode("utf-8") ) + value = self.escape( str(plugininst.options[optionname]).encode("utf-8") ) writer.write("\t<%s value=\"%s\" />\n" % (optionname,value)) writer.write("</%s>\n" % plugininst.plugintype) @@ -236,7 +236,7 @@ def runGuiApp(copycenter, name): self.writeOptions(f, destinationpluginname, self.dialog.getDestinationPluginImpl()) f.write("</CopyCenterJob>\n") f.close() - print "File \%s\" successfully written." % filename + print("File \%s\" successfully written." % filename) def addItem(self, pluginimpl, afteritem = None, parentitem = None): #print "CopyJobWidget.addItem" @@ -262,11 +262,11 @@ def runGuiApp(copycenter, name): def okRename(self, columnindex): if columnindex == 1: n = str(self.text(0)) - if not self.pluginimpl.options.has_key(n): - raise "No such option \"%s\"" % n + if n not in self.pluginimpl.options: + raise Exception("No such option \"%s\"" % n) qt.TQListViewItem.okRename(self,columnindex) v = str(qt.TQListViewItem.text(self,1)) - print "Option \"%s\" has value \"%s\" now." % (n,v) + print("Option \"%s\" has value \"%s\" now." % (n,v)) self.pluginimpl.options[n] = v def text(self, columnindex): @@ -287,18 +287,18 @@ def runGuiApp(copycenter, name): afteritem = self.addItem(pluginimpl, afteritem, item) afteritem.setText(0,str(i)) afteritem.setText(1,str(pluginimpl.options[i])) - print "CopyJobWidget.updateItem Added item with name \"%s\" and value \"%s\"" % (str(i),str(pluginimpl.options[i])) + print("CopyJobWidget.updateItem Added item with name \"%s\" and value \"%s\"" % (str(i),str(pluginimpl.options[i]))) pass def maybeUpdate(self): - print "CopyJobWidget.maybeUpdate" + print("CopyJobWidget.maybeUpdate") self.listview.clear() try: self.updateItem(self.dialog.getDestinationPluginName(), self.dialog.getDestinationPluginImpl()) self.updateItem(self.dialog.getSourcePluginName(), self.dialog.getSourcePluginImpl()) except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) self.listview.clear() #-------------------------------------------------------------------- @@ -382,7 +382,7 @@ def runGuiApp(copycenter, name): sourceimpl = self.dialog.getSourcePluginImpl() self.textbrowser.append("Source: %s" % sourcename) if sourceimpl == None: - raise "No such source." + raise Exception("No such source.") try: sourceimpl.init(copierer) @@ -391,7 +391,7 @@ def runGuiApp(copycenter, name): destinationimpl = self.dialog.getDestinationPluginImpl() self.textbrowser.append("<hr>Destination: %s" % destinationname) if destinationimpl == None: - raise "No such destination." + raise Exception("No such destination.") try: destinationimpl.init(copierer) @@ -418,7 +418,7 @@ def runGuiApp(copycenter, name): self.setCaption("Copy failed") self.textbrowser.append("<b>Error: %s</b>" % sys.exc_info()[0]) import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) #self.progressbar.setEnabled(False) self.donebtn.setEnabled(True) self.cancelbtn.setEnabled(False) @@ -468,11 +468,11 @@ def runGuiApp(copycenter, name): self.scrollview.viewport().setPaletteBackgroundColor(self.paletteBackgroundColor()) except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) qt.TQObject.connect(self.combobox, qt.SIGNAL("activated(int)"), self.activated) def updatePlugin(self): - print "DataSelector.updatePlugin" + print("DataSelector.updatePlugin") self.pluginimpl = None text = str(self.combobox.currentText()) plugin = self.dialog.copycenter.plugins[text] @@ -488,7 +488,7 @@ def runGuiApp(copycenter, name): self.mainbox = None def updateMainBox(self): - print "DataSelector.updateMainBox" + print("DataSelector.updateMainBox") self.removeMainBox() self.mainbox = qt.TQVBox( self.scrollview.viewport() ) self.mainbox.setSpacing(2) @@ -497,7 +497,7 @@ def runGuiApp(copycenter, name): self.pluginimpl.createWidget(self.dialog, self.mainbox) except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) self.mainbox.setStretchFactor(qt.TQWidget(self.mainbox), 1) self.mainbox.show() self.scrollview.addChild(self.mainbox) @@ -507,12 +507,12 @@ def runGuiApp(copycenter, name): self.updateMainBox() def maybeUpdate(self): - print "DataSelector.maybeUpdate" + print("DataSelector.maybeUpdate") self.removeMainBox() qt.TQTimer.singleShot(50, self.activated) def maybeDone(self): - print "DataSelector.maybeDone" + print("DataSelector.maybeDone") if self.pluginimpl.widget == None: return for optionname in self.pluginimpl.options: self.pluginimpl.options[optionname] = self.pluginimpl.widget.getOptionValue(optionname) @@ -588,7 +588,7 @@ def runGuiApp(copycenter, name): defaultfile = os.path.join(self.copycenter.homepath,"default.copycenterjob.xml") if os.path.isfile(defaultfile): - print "Reading default copy job file: %s" % defaultfile + print("Reading default copy job file: %s" % defaultfile) self.jobsbox.jobfilecombobox.setCurrentText(defaultfile) def getSourcePluginName(self): diff --git a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginKexiDB.py b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginKexiDB.py index 0b78bfa1..20b81212 100644 --- a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginKexiDB.py +++ b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginKexiDB.py @@ -104,33 +104,33 @@ class CopyCenterPlugin: self.copierer = copierer if self.kexidbconnection == None: if self.plugin.widget == None: - raise "No connection established." + raise Exception("No connection established.") self.copierer.appendProgressMessage("<i>Trying to connect...</i>") if self.plugin.widget.driverbox.driver == None: - raise "Invalid driver." + raise Exception("Invalid driver.") if not self.plugin.widget.connectClicked(): - raise "Failed to connect." + raise Exception("Failed to connect.") connectiondata = self.kexidbconnection.data() self.copierer.appendProgressMessage("Connected: %s %s" % (connectiondata.driverName(),connectiondata.serverInfoString())) tablename = str(self.plugin.widget.tablebox.tableedit.text()) if tablename == "": - raise "No table defined" + raise Exception("No table defined") fields = [ f.strip() for f in str(self.plugin.widget.fieldbox.fieldsedit.text()).split(",") if len(f) > 0 ] if len(fields) < 1: - raise "No fields defined" + raise Exception("No fields defined") self.tableschema = self.kexidbconnection.tableSchema(tablename) - if not self.tableschema: raise "No such tableschema \"%s\"" % tablename + if not self.tableschema: raise Exception("No such tableschema \"%s\"" % tablename) self.copierer.appendProgressMessage("Table: %s" % self.tableschema.name()) if len(fields) == 1 and fields[0] == "*": self.fieldlist = self.tableschema.fieldlist() else: self.fieldlist = self.tableschema.fieldlist().subList(fields) - if not self.fieldlist: raise "No such fields \"%s\"" % fields + if not self.fieldlist: raise Exception("No such fields \"%s\"" % fields) fieldlistnames = self.fieldlist.names() - if len(fieldlistnames) < 1: raise "No valid fields defined for \"%s\"" % fields + if len(fieldlistnames) < 1: raise Exception("No valid fields defined for \"%s\"" % fields) self.copierer.appendProgressMessage("Fields: %s" % fieldlistnames) def finish(self): if self.plugin.widget == None: @@ -146,24 +146,24 @@ class CopyCenterPlugin: return self.copierer == None def initRead(self): - print "Initialize read" + print("Initialize read") #queryschema = self.plugin.copycenterplugin.drivermanager.querySchema() queryschema = self.tableschema.query() queryschema.fieldlist().setFields(self.fieldlist) - print "QuerySchema: %s" % queryschema.fieldlist().names() + print("QuerySchema: %s" % queryschema.fieldlist().names()) whereexpression = str(self.plugin.widget.whereedit.text()) if whereexpression != "": - print "WHERE-expression: %s" % whereexpression + print("WHERE-expression: %s" % whereexpression) if not queryschema.setWhereExpression(whereexpression): - raise "Invalid WHERE-expression." + raise Exception("Invalid WHERE-expression.") #print "QuerySchema statement=%s" % queryschema.statement() self.kexidbcursor = self.kexidbconnection.executeQuerySchema(queryschema) if not self.kexidbcursor: - raise "Failed to create cursor." + raise Exception("Failed to create cursor.") if not self.kexidbcursor.moveFirst(): - raise "The cursor has no records to read from." + raise Exception("The cursor has no records to read from.") def readRecord(self): if self.kexidbcursor == None or self.kexidbcursor.eof(): @@ -176,15 +176,15 @@ class CopyCenterPlugin: return record def initWrite(self): - print "Initialize write" + print("Initialize write") def writeRecord(self,record): - print "write record: %s" % record + print("write record: %s" % record) if self.kexidbconnection.insertRecord(self.fieldlist,record): - print "=> insert successfully" + print("=> insert successfully") self.copierer.writeSuccess(record, 1) else: - print "=> insert failed: %s" % self.kexidbconnection.lastError() + print("=> insert failed: %s" % self.kexidbconnection.lastError()) self.copierer.writeFailed(record) #import time #time.sleep(1) @@ -546,10 +546,10 @@ class CopyCenterPlugin: connectiondata = self.copycenterplugin.drivermanager.createConnectionDataByFile(file) if connectiondata == None: - raise "Unsupported file." + raise Exception("Unsupported file.") drivername = connectiondata.driverName().lower() - print "driver: %s" % drivername + print("driver: %s" % drivername) for i in range(1,self.driverbox.drivercombo.count()): if drivername == self.driverbox.drivercombo.text(i).lower(): self.driverbox.drivercombo.setCurrentItem(i) @@ -570,7 +570,7 @@ class CopyCenterPlugin: def connectClicked(self): if self.driverbox.driver == None: - print "No driver selected." + print("No driver selected.") return False connectiondata = self.copycenterplugin.drivermanager.createConnectionData() if self.driverbox.driver.isFileDriver(): @@ -588,18 +588,18 @@ class CopyCenterPlugin: connectiondata.setPassword(str(self.driverbox.passedit.text())) connectiondata.setUserName(str(self.driverbox.useredit.text())) connectiondata.setDatabaseName(str(self.driverbox.dbedit.text())) - print "Creating connection" + print("Creating connection") connection = self.driverbox.driver.createConnection(connectiondata) - print "Trying to connect" + print("Trying to connect") if not connection.connect(): qt.TQMessageBox.critical(self,"Failed to connect",connection.lastError()) return False - print "Use database \"%s\"" % connectiondata.databaseName() + print("Use database \"%s\"" % connectiondata.databaseName()) if not connection.useDatabase( connectiondata.databaseName() ): qt.TQMessageBox.critical(self,"Failed to connect",connection.lastError()) return False - print "dbnames = %s" % connection.databaseNames() - print "tablenames = %s" % connection.tableNames() + print("dbnames = %s" % connection.databaseNames()) + print("tablenames = %s" % connection.tableNames()) #self.useDatabase(connection, filename) self.plugin.connection.kexidbconnection = connection diff --git a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py index 40d1a317..76e544a6 100644 --- a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py +++ b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py @@ -28,9 +28,9 @@ class CopyCenterPlugin: def _init(self,copierer): self.copierer = copierer if not self.widget.connectClicked(): - raise "Failed to connect with database." + raise Exception("Failed to connect with database.") if self.database == None or not self.database.isOpen(): - raise "Database is not initialized or not opened." + raise Exception("Database is not initialized or not opened.") self.copierer.appendProgressMessage("Connected: %s %s@%s:%i %s" % (str(self.database.driverName()),str(self.database.userName()),str(self.database.hostName()),self.database.port(),str(self.database.databaseName())) ) self.isfinished = False @@ -66,25 +66,25 @@ class CopyCenterPlugin: self.cursor = qtsql.TQSqlCursor(tablename,True,self.database) self.cursor.setFilter(wherestatement) if not self.cursor.select(): - raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ) + raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )) self.fieldlist = [] for fieldname in str(self.widget.fieldedit.text()).split(","): fn = fieldname.strip() if fn != "": field = self.cursor.field(fn) if not field: - raise "There exists no such field \"%s\" in the table \"%s\"." % (fn,tablename) + raise Exception("There exists no such field \"%s\" in the table \"%s\"." % (fn,tablename)) self.fieldlist.append(str(field.name())) if len(self.fieldlist) < 1: - raise "No fields for table \"%s\" defined." % tablename + raise Exception("No fields for table \"%s\" defined." % tablename) copierer.appendProgressMessage("SQL: %s" % str(self.cursor.executedQuery())) def read(self): - if not self.cursor.next(): + if not next(self.cursor): return None record = [] for fieldname in self.fieldlist: - record.append( unicode(self.cursor.value(fieldname).toString()).encode("latin-1") ) + record.append( str(self.cursor.value(fieldname).toString()).encode("latin-1") ) #print "read record: %s" % record return record @@ -124,14 +124,14 @@ class CopyCenterPlugin: def initInsert(self): self.write = self.writeInsert if not self.cursor.select(): - raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ) + raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )) for fieldname in self.fieldlist: # check fieldlist field = self.cursor.field(fieldname) - if not field: raise "There exists no such field \"%s\" in the table \"%s\"." % (fieldname, self.cursor.name()) + if not field: raise Exception("There exists no such field \"%s\" in the table \"%s\"." % (fieldname, self.cursor.name())) self.copierer.appendProgressMessage("Insert SQL: %s" % str(self.cursor.executedQuery())) def writeInsert(self, record): - print "insert record: %s" % record + print("insert record: %s" % record) from TQt import qt cursorrecord = self.cursor.primeInsert() count = len(record) @@ -145,9 +145,9 @@ class CopyCenterPlugin: cursorrecord.setValue(self.fieldlist[i], v) rowcount = self.cursor.insert() if rowcount < 1: - drv = unicode(self.cursor.lastError().driverText()).encode("latin-1") - db = unicode(self.cursor.lastError().databaseText()).encode("latin-1") - print "failed: %s %s" % (drv,db) + drv = str(self.cursor.lastError().driverText()).encode("latin-1") + db = str(self.cursor.lastError().databaseText()).encode("latin-1") + print("failed: %s %s" % (drv,db)) self.copierer.writeFailed(record) else: self.copierer.writeSuccess(record,rowcount) @@ -158,9 +158,9 @@ class CopyCenterPlugin: def initUpdate(self): self.write = self.writeUpdate self.indexfieldname = str(self.widget.indexedit.text()).strip() - if self.indexfieldname == "": raise "No index-field defined." + if self.indexfieldname == "": raise Exception("No index-field defined.") pkindex = self.cursor.index(self.indexfieldname) - if not pkindex: raise "Invalid index-field defined." + if not pkindex: raise Exception("Invalid index-field defined.") self.cursor.setPrimaryIndex(pkindex) #self.cursor.setMode( qtsql.TQSqlCursor.Insert | qtsql.TQSqlCursor.Update ) self.copierer.appendProgressMessage("Update SQL: %s" % str(self.cursor.executedQuery())) @@ -173,13 +173,13 @@ class CopyCenterPlugin: indexvalue = record[idx] except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) - raise "Failed to determinate the value for the primary key." + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) + raise Exception("Failed to determinate the value for the primary key.") # select cursor and go to matching record. wherestatement = "%s = \"%s\"" % (self.indexfieldname, indexvalue) if not self.cursor.select(wherestatement): - raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ) - if not self.cursor.next(): + raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )) + if not next(self.cursor): #print "No such record to update !" return False # Prepare updating the record. @@ -202,7 +202,7 @@ class CopyCenterPlugin: self.copierer.writeFailed(record) else: self.copierer.writeSuccess(record,rowcount) - print "updated record (rowcount %s): %s" % (rowcount,record) + print("updated record (rowcount %s): %s" % (rowcount,record)) return True def __init__(self, copycenter): @@ -441,21 +441,21 @@ class CopyCenterPlugin: if optionname == 'indexfield': return str(self.indexedit.text()) except: import traceback - print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ) + print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )) return "" def connectClicked(self): if self.plugin.database != None and self.plugin.database.isOpen(): - print "already connected. not needed to reconnect..." + print("already connected. not needed to reconnect...") self.updateConnectState() return True - print "trying to connect..." + print("trying to connect...") from TQt import qtsql drivername = str(self.driveredit.currentText()) - print "drivername: %s" % drivername + print("drivername: %s" % drivername) connectionname = "CopyCenter%s" % self.plugin.plugintype - print "connectionname: %s" % connectionname + print("connectionname: %s" % connectionname) self.plugin.database = qtsql.TQSqlDatabase.addDatabase(drivername,connectionname) if not self.plugin.database: qt.TQMessageBox.critical(self,"Failed to connect","<qt>Failed to create database for driver \"%s\"</qt>" % drivername) @@ -479,16 +479,16 @@ class CopyCenterPlugin: if not self.plugin.database.open(): qt.TQMessageBox.critical(self,"Failed to connect","<qt>%s<br><br>%s</qt>" % (self.plugin.database.lastError().driverText(),self.plugin.database.lastError().databaseText())) return False - print "database is opened now!" + print("database is opened now!") self.updateConnectState() return True def disconnectClicked(self): - print "trying to disconnect..." + print("trying to disconnect...") if self.plugin.database: self.plugin.database.close() self.plugin.database = None - print "database is closed now!" + print("database is closed now!") self.updateConnectState() plugin.widget = MainWidget(plugin,self.dialog,parent) diff --git a/kexi/plugins/scripting/scripts/exportxhtml/ExportXHTML.py b/kexi/plugins/scripting/scripts/exportxhtml/ExportXHTML.py index cace0340..eff0e636 100644 --- a/kexi/plugins/scripting/scripts/exportxhtml/ExportXHTML.py +++ b/kexi/plugins/scripting/scripts/exportxhtml/ExportXHTML.py @@ -19,7 +19,7 @@ class Datasource: try: self.connection = keximainwindow.getConnection() except: - raise "No connection established. Please open a project before." + raise Exception("No connection established. Please open a project before.") self.schema = None @@ -65,9 +65,9 @@ class Datasource: if not self.cursor: self.cursor = self.connection.executeQuerySchema( self.queryschema ) if not self.cursor: - raise "Failed to execute queryschema." + raise Exception("Failed to execute queryschema.") if not self.cursor.moveFirst(): - raise "Failed to move cursor to first record." + raise Exception("Failed to move cursor to first record.") if self.cursor.eof(): self.cursor = None return None @@ -131,7 +131,7 @@ class HtmlExporter: if items == None: break output.write("<tr>") for item in items: - u = unicode(str(self.htmlescape(item)),"latin-1") + u = str(str(self.htmlescape(item)),"latin-1") output.write("<td>%s</td>" % u.encode("utf-8")) output.write("</tr>\n") output.write("</table>\n") @@ -144,7 +144,7 @@ class GuiApp: try: import gui except: - raise "Import of the Kross GUI module failed." + raise Exception("Import of the Kross GUI module failed.") self.dialog = gui.Dialog("Export XHTML") self.dialog.addLabel(self.dialog, "Export a table- or query-datasource to a XHTML-file.") @@ -176,10 +176,10 @@ class GuiApp: def doExport(self): file = str( self.file.get() ) query = str( self.datasourcelist.get() ) - print "Exporting '%s' to file '%s' ..." % (query,file) + print("Exporting '%s' to file '%s' ..." % (query,file)) if not self.datasource.setSource(query): - raise "Invalid datasource selected." + raise Exceptin("Invalid datasource selected.") #return style = str( self.stylelist.get() ) @@ -190,7 +190,7 @@ class GuiApp: exporter.write(f, style) f.close() - print "Successfully exported '%s' to file %s" % (query,file) + print("Successfully exported '%s' to file %s" % (query,file)) self.dialog.close() GuiApp( Datasource() ) diff --git a/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py b/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py index 200b3dee..03a6772a 100755 --- a/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py +++ b/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py @@ -28,7 +28,7 @@ class SaxInput: import xml.sax.saxlib import xml.sax.saxexts except: - raise "Import of the python xml.sax.saxlib module failed. This module is needed by the ImportXHTML python script." + raise Exception("Import of the python xml.sax.saxlib module failed. This module is needed by the ImportXHTML python script.") def read(self, outputwriter): """ Start reading and parsing the XML-file. """ @@ -83,7 +83,7 @@ class SaxInput: # Print some debugging-output to stdout. for idx in range(self.level): sys.stdout.write(' ') sys.stdout.write('Element: %s' % name) - for attrName in attrs.keys(): + for attrName in list(attrs.keys()): sys.stdout.write(' %s="%s"' % (attrName,attrs.get(attrName))) sys.stdout.write('\n') @@ -110,12 +110,12 @@ class SaxInput: self.field = None elif name == "td" and (self.level == len(self.tablebase) + 1): #if self.field == None: - # raise "Unexpected closing </td>" + # raise Exception("Unexpected closing </td>") self.record.setField( self.field ) self.field = None elif name == "th" and (self.level == len(self.tablebase) + 1): #if self.field == None: - # raise "Unexpected closing </td>" + # raise Exceptin("Unexpected closing </td>") self.record.setHeader( self.field ) self.field = None @@ -126,7 +126,7 @@ class SaxInput: if self.field != None: # the xml-data is unicode and we need to encode it # to latin-1 cause KexiDB deals only with latin-1. - u = unicode(chars[offset:offset+length]) + u = str(chars[offset:offset+length]) self.field.append(u.encode("latin-1")) # start the job @@ -163,14 +163,14 @@ class KexiDBOutput: def success(self, record): """ Called if a record was written successfully. """ - print "SUCCESS: %s" % str(record) + print("SUCCESS: %s" % str(record)) self.successcount += 1 if hasattr(self.outputwriter,"logfile"): self.addLog(record, "Success") def failed(self, record): """ Called if we failed to write a record. """ - print "FAILED: %s" % str(record) + print("FAILED: %s" % str(record)) self.failedcount += 1 if hasattr(self.outputwriter,"logfile"): self.addLog(record, "Failed") @@ -207,7 +207,7 @@ class KexiDBOutput: try: self.connection = keximainwindow.getConnection() except: - raise "No connection established. Please open a project before." + raise Exception("No connection established. Please open a project before.") self.fieldlist = None self.headerrecord = None @@ -215,9 +215,9 @@ class KexiDBOutput: def begin(self): """ Called before parsing starts. """ - print "START JOB" + print("START JOB") if self.fieldlist == None: - raise "Invalid tableschema or fieldlist!" + raise Exceptin("Invalid tableschema or fieldlist!") global KexiDBOutput self.result = KexiDBOutput.Result(self) if hasattr(self,"logfilename") and self.logfilename != None and self.logfilename != "": @@ -225,7 +225,7 @@ class KexiDBOutput: def end(self): """ Called if parsing is fineshed. """ - print "END JOB" + print("END JOB") self.logfile = None self.mapping = {} #self.headerrecord = None @@ -240,12 +240,12 @@ class KexiDBOutput: """ Set the tablename we like to import the data to. """ tableschema = self.connection.tableSchema(tablename) if tableschema == None: - raise "There exists no table with the name '%s'!" % tablename + raise Exceptin("There exists no table with the name '%s'!" % tablename) self.fieldlist = tableschema.fieldlist() fields = self.fieldlist.fields() for field in fields: - print "KexiDBOutput.setTable(%s): %s(%s)" % (tablename,field.name(),field.type()) - print "names=%s" % self.fieldlist.names() + print("KexiDBOutput.setTable(%s): %s(%s)" % (tablename,field.name(),field.type())) + print("names=%s" % self.fieldlist.names()) def setMapping(self, mapping): """ Set the tablefieldname=xmlcolnr dictonary we should map the data to. """ @@ -277,7 +277,7 @@ class KexiDBOutput: values = [] for k in self.fieldlist.names(): values.append( str(record.fields[ int(self.mapping[k]) ]) ) - print "Import values: %s" % values + print("Import values: %s" % values) try: if self.connection.insertRecord(self.fieldlist, values): @@ -343,7 +343,7 @@ class GuiApp: msgbox.show() self.doCancel() - except RuntimeError, e: + except RuntimeError as e: pass #except Exception, e: # import traceback @@ -392,7 +392,7 @@ class GuiApp: i += 1 if not field.isAutoInc(): l.set(i) - except ValueError, e: + except ValueError as e: if not field.type() in ("Integer","BigInteger","ShortInteger","Float","Double"): i += 1 l.set(i) @@ -411,7 +411,7 @@ class GuiApp: fieldname = field.name() colnr = str( l.get() ).split(":",1)[0] if colnr.isdigit(): - print "Table field '%s' is mapped to XML column '%s'" % (fieldname,colnr) + print("Table field '%s' is mapped to XML column '%s'" % (fieldname,colnr)) mapping[ fieldname ] = colnr self.outputwriter.setMapping(mapping) self.ok = True diff --git a/kexi/plugins/scripting/scripts/projectdocumentor/ProjectDocumentor.py b/kexi/plugins/scripting/scripts/projectdocumentor/ProjectDocumentor.py index 89a60301..cb4e0de7 100755 --- a/kexi/plugins/scripting/scripts/projectdocumentor/ProjectDocumentor.py +++ b/kexi/plugins/scripting/scripts/projectdocumentor/ProjectDocumentor.py @@ -20,7 +20,7 @@ class DataProvider: try: self.connection = keximainwindow.getConnection() except: - raise "No connection established. Please open the project to be documented first." + raise Exception("No connection established. Please open the project to be documented first.") def printConnection(self): condata = self.connection.data() @@ -96,7 +96,7 @@ class GuiApp: try: import gui except: - raise "Import of the Kross GUI module failed." + raise Exception("Import of the Kross GUI module failed.") self.dialog = gui.Dialog("Project Documentor") @@ -130,7 +130,7 @@ class GuiApp: def toHTML(self, value): import types result = "" - if isinstance(value, types.TupleType): + if isinstance(value, tuple): result += "<ul>" if len(value) == 1: result += "<li>%s</li>" % value @@ -142,7 +142,7 @@ class GuiApp: if i != "": result += "<li>%s</li>" % i result += "</ul>" - elif isinstance(value, types.ListType): + elif isinstance(value, list): for item in value: result += "%s" % self.toHTML(item) else: @@ -151,7 +151,7 @@ class GuiApp: def doSave(self): file = str( self.file.get() ) - print "Attempting to save project documentation to file: %s" % file + print("Attempting to save project documentation to file: %s" % file) f = open(file, "w") @@ -167,19 +167,19 @@ class GuiApp: for d in dir(self.dataprovider): if d.startswith("print"): - print "GuiApp.doSave() CHECK %s" % d + print("GuiApp.doSave() CHECK %s" % d) a = self.printCheckBoxes[d] if a and a.isChecked(): - print "GuiApp.doSave() BEGIN %s" % d + print("GuiApp.doSave() BEGIN %s" % d) value = getattr(self.dataprovider,d)() if value != None and len(value) > 0: f.write("<h2>%s</h2>" % d[5:]) f.write( self.toHTML(value) ) - print "GuiApp.doSave() END %s" % d + print("GuiApp.doSave() END %s" % d) f.close() - print "Successfully saved project documentation to file: %s" % file + print("Successfully saved project documentation to file: %s" % file) self.dialog.close() GuiApp( DataProvider() ) diff --git a/kexi/plugins/scripting/scripts/python/kexiapp/__init__.py b/kexi/plugins/scripting/scripts/python/kexiapp/__init__.py index b5224304..28cbdcad 100755 --- a/kexi/plugins/scripting/scripts/python/kexiapp/__init__.py +++ b/kexi/plugins/scripting/scripts/python/kexiapp/__init__.py @@ -14,7 +14,7 @@ Dual-licensed under LGPL v2+higher and the BSD license. try: import krosskexiapp -except ImportError, e: +except ImportError as e: raise "Import of the Kross KexiApp module failed.\n%s" % e def get(modulename): |