Project/Project.py

changeset 610
3a625b0793d8
parent 608
d8fea1e76975
child 613
5a6ee2af8ec0
equal deleted inserted replaced
608:d8fea1e76975 610:3a625b0793d8
754 self.pdata["VCSOTHERDATA"] = [copy.deepcopy(self.vcs.vcsGetOtherData())] 754 self.pdata["VCSOTHERDATA"] = [copy.deepcopy(self.vcs.vcsGetOtherData())]
755 755
756 if fn is None: 756 if fn is None:
757 fn = self.pfile 757 fn = self.pfile
758 758
759 res = self.__writeXMLProject(fn) 759 f = QFile(fn)
760 if f.open(QIODevice.WriteOnly):
761 ProjectWriter(f, os.path.splitext(os.path.basename(fn))[0]).writeXML()
762 res = True
763 else:
764 E5MessageBox.critical(self.ui,
765 self.trUtf8("Save project file"),
766 self.trUtf8("<p>The project file <b>{0}</b> could not be written.</p>")\
767 .format(fn))
768 res = False
760 769
761 if res: 770 if res:
762 self.pfile = os.path.abspath(fn) 771 self.pfile = os.path.abspath(fn)
763 self.ppath = os.path.abspath(os.path.dirname(fn)) 772 self.ppath = os.path.abspath(os.path.dirname(fn))
764 if Utilities.isWindowsPlatform(): 773 if Utilities.isWindowsPlatform():
770 779
771 # insert filename into list of recently opened projects 780 # insert filename into list of recently opened projects
772 self.__syncRecent() 781 self.__syncRecent()
773 782
774 return res 783 return res
775
776 def __writeXMLProject(self, fn = None):
777 """
778 Private method to write the project data to an XML file.
779
780 @param fn the filename of the project file (string)
781 @return flag indicating success (boolean)
782 """
783 try:
784 if self.pdata["EOL"][0] == 0:
785 newline = None
786 else:
787 newline = self.getEolString()
788 if fn.lower().endswith("e4pz"):
789 try:
790 import gzip
791 except ImportError:
792 E5MessageBox.critical(self.ui,
793 self.trUtf8("Save project file"),
794 self.trUtf8("""Compressed project files not supported."""
795 """ The compression library is missing."""))
796 return False
797 f = io.StringIO(newline = newline)
798 else:
799 f = open(fn, "w", encoding = "utf-8", newline = newline)
800
801 ProjectWriter(f, os.path.splitext(os.path.basename(fn))[0]).writeXML()
802
803 if fn.lower().endswith("e4pz"):
804 g = gzip.open(fn, "wb")
805 g.write(f.getvalue().encode("utf-8"))
806 g.close()
807 f.close()
808
809 except IOError:
810 E5MessageBox.critical(self.ui,
811 self.trUtf8("Save project file"),
812 self.trUtf8("<p>The project file <b>{0}</b> could not be written.</p>")\
813 .format(fn))
814 return False
815
816 return True
817 784
818 def __readUserProperties(self): 785 def __readUserProperties(self):
819 """ 786 """
820 Private method to read in the user specific project file (.e4q) 787 Private method to read in the user specific project file (.e4q)
821 """ 788 """

eric ide

mercurial