Gui: fix some lint warnings

This commit is contained in:
wmayer
2023-03-24 20:12:06 +01:00
committed by wwmayer
parent 05d675364c
commit cd02704ff1
2 changed files with 31 additions and 24 deletions

View File

@@ -6,7 +6,7 @@ __url__ = "http://www.freecadweb.org"
__doc__ = "Tools for extracting or creating project files"
import os,sys,string
import os
import xml.sax
import xml.sax.handler
import xml.sax.xmlreader
@@ -14,58 +14,64 @@ import zipfile
# SAX handler to parse the Document.xml
class DocumentHandler(xml.sax.handler.ContentHandler):
""" Parse content of Document.xml or GuiDocument.xml """
def __init__(self, dirname):
""" Init parser """
super().__init__()
self.files = []
self.dirname = dirname
def startElement(self, name, attributes):
item=attributes.get("file")
if item != None:
self.files.append(os.path.join(self.dirname,str(item)))
def startElement(self, name, attrs):
item = attrs.get("file")
if item is not None:
self.files.append(os.path.join(self.dirname, str(item)))
def characters(self, data):
def characters(self, content):
return
def endElement(self, name):
return
def extractDocument(filename, outpath):
zfile=zipfile.ZipFile(filename)
files=zfile.namelist()
""" Extract files from project archive """
zfile = zipfile.ZipFile(filename)
files = zfile.namelist()
for i in files:
data=zfile.read(i)
dirs=i.split("/")
data = zfile.read(i)
dirs = i.split("/")
if len(dirs) > 1:
dirs.pop()
curpath=outpath
curpath = outpath
for j in dirs:
curpath=curpath+"/"+j
curpath = curpath + "/" + j
os.mkdir(curpath)
output=open(outpath+"/"+i,'wb')
output = open(outpath + "/"+i, 'wb')
output.write(data)
output.close()
def createDocument(filename, outpath):
files=getFilesList(filename)
dirname=os.path.dirname(filename)
guixml=os.path.join(dirname,"GuiDocument.xml")
""" Create project archive """
files = getFilesList(filename)
dirname = os.path.dirname(filename)
guixml = os.path.join(dirname, "GuiDocument.xml")
if os.path.exists(guixml):
files.extend(getFilesList(guixml))
compress=zipfile.ZipFile(outpath,'w',zipfile.ZIP_DEFLATED)
compress = zipfile.ZipFile(outpath, 'w', zipfile.ZIP_DEFLATED)
for i in files:
dirs=os.path.split(i)
compress.write(i,dirs[-1],zipfile.ZIP_DEFLATED)
dirs = os.path.split(i)
compress.write(i, dirs[-1], zipfile.ZIP_DEFLATED)
compress.close()
def getFilesList(filename):
dirname=os.path.dirname(filename)
handler=DocumentHandler(dirname)
parser=xml.sax.make_parser()
""" Determine list of files referenced in a Document.xml or GuiDocument.xml """
dirname = os.path.dirname(filename)
handler = DocumentHandler(dirname)
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
parser.parse(filename)
files=[]
files = []
files.append(filename)
files.extend(iter(handler.files))
return files

View File

@@ -115,8 +115,9 @@ void DlgProjectUtility::tryCreateArchive(const QString& source, const QString& t
str << "project_utility.createDocument(\"" << (const char*)source.toUtf8()
<< "\", \"" << (const char*)target.toUtf8() << "\")";
Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
if (openFile)
if (openFile) {
Application::Instance->open((const char*)target.toUtf8(),"FreeCAD");
}
}
catch (const Base::Exception& e) {
QMessageBox::critical(this, tr("Failed to create project"), QString::fromLatin1(e.what()));