Project/Project.py

changeset 535
4b00d7336e19
parent 524
d66ebf1a33e2
child 536
6d8d39753c82
equal deleted inserted replaced
533:bc6063d2ab83 535:4b00d7336e19
1769 except IOError as why: 1769 except IOError as why:
1770 QMessageBox.critical(None, 1770 QMessageBox.critical(None,
1771 self.trUtf8("Add file"), 1771 self.trUtf8("Add file"),
1772 self.trUtf8("<p>The selected file <b>{0}</b> could not be" 1772 self.trUtf8("<p>The selected file <b>{0}</b> could not be"
1773 " added to <b>{1}</b>.</p><p>Reason: {2}</p>") 1773 " added to <b>{1}</b>.</p><p>Reason: {2}</p>")
1774 .format(fn, target, str(why)), 1774 .format(fn, target, str(why)))
1775 QMessageBox.StandardButtons(\
1776 QMessageBox.Abort))
1777 return 1775 return
1778 1776
1779 self.appendFile(targetfile, isSource or filter == 'source') 1777 self.appendFile(targetfile, isSource or filter == 'source')
1780 else: 1778 else:
1781 QMessageBox.critical(None, 1779 QMessageBox.critical(None,
1782 self.trUtf8("Add file"), 1780 self.trUtf8("Add file"),
1783 self.trUtf8("The target directory must not be empty."), 1781 self.trUtf8("The target directory must not be empty."))
1784 QMessageBox.StandardButtons(\
1785 QMessageBox.Abort))
1786 1782
1787 def __addSingleDirectory(self, filetype, source, target, quiet = False): 1783 def __addSingleDirectory(self, filetype, source, target, quiet = False):
1788 """ 1784 """
1789 Private method used to add all files of a single directory to the project. 1785 Private method used to add all files of a single directory to the project.
1790 1786
1821 except IOError as why: 1817 except IOError as why:
1822 QMessageBox.critical(None, 1818 QMessageBox.critical(None,
1823 self.trUtf8("Add directory"), 1819 self.trUtf8("Add directory"),
1824 self.trUtf8("<p>The target directory <b>{0}</b> could not be" 1820 self.trUtf8("<p>The target directory <b>{0}</b> could not be"
1825 " created.</p><p>Reason: {1}</p>") 1821 " created.</p><p>Reason: {1}</p>")
1826 .format(target, str(why)), 1822 .format(target, str(why)))
1827 QMessageBox.StandardButtons(\
1828 QMessageBox.Abort))
1829 return 1823 return
1830 1824
1831 for file in files: 1825 for file in files:
1832 for pattern in ignorePatterns: 1826 for pattern in ignorePatterns:
1833 if fnmatch.fnmatch(file, pattern): 1827 if fnmatch.fnmatch(file, pattern):
1889 if dlg.exec_() == QDialog.Accepted: 1883 if dlg.exec_() == QDialog.Accepted:
1890 filetype, source, target, recursive = dlg.getData() 1884 filetype, source, target, recursive = dlg.getData()
1891 if target == '': 1885 if target == '':
1892 QMessageBox.critical(None, 1886 QMessageBox.critical(None,
1893 self.trUtf8("Add directory"), 1887 self.trUtf8("Add directory"),
1894 self.trUtf8("The target directory must not be empty."), 1888 self.trUtf8("The target directory must not be empty."))
1895 QMessageBox.StandardButtons(\
1896 QMessageBox.Abort))
1897 return 1889 return
1898 1890
1899 if filetype == 'OTHERS': 1891 if filetype == 'OTHERS':
1900 self.addToOthers(source) 1892 self.addToOthers(source)
1901 return 1893 return
1902 1894
1903 if source == '': 1895 if source == '':
1904 QMessageBox.critical(None, 1896 QMessageBox.critical(None,
1905 self.trUtf8("Add directory"), 1897 self.trUtf8("Add directory"),
1906 self.trUtf8("The source directory must not be empty."), 1898 self.trUtf8("The source directory must not be empty."))
1907 QMessageBox.StandardButtons(\
1908 QMessageBox.Abort))
1909 return 1899 return
1910 1900
1911 if recursive: 1901 if recursive:
1912 self.__addRecursiveDirectory(filetype, source, target) 1902 self.__addRecursiveDirectory(filetype, source, target)
1913 else: 1903 else:
4516 pkglistFile.close() 4506 pkglistFile.close()
4517 except IOError as why: 4507 except IOError as why:
4518 QMessageBox.critical(None, 4508 QMessageBox.critical(None,
4519 self.trUtf8("Create Package List"), 4509 self.trUtf8("Create Package List"),
4520 self.trUtf8("""<p>The file <b>PKGLIST</b> could not be created.</p>""" 4510 self.trUtf8("""<p>The file <b>PKGLIST</b> could not be created.</p>"""
4521 """<p>Reason: {0}</p>""").format(str(why)), 4511 """<p>Reason: {0}</p>""").format(str(why)))
4522 QMessageBox.StandardButtons(\
4523 QMessageBox.Ok))
4524 return 4512 return
4525 4513
4526 if not "PKGLIST" in self.pdata["OTHERS"]: 4514 if not "PKGLIST" in self.pdata["OTHERS"]:
4527 self.appendFile("PKGLIST") 4515 self.appendFile("PKGLIST")
4528 4516
4535 pkglist = os.path.join(self.ppath, "PKGLIST") 4523 pkglist = os.path.join(self.ppath, "PKGLIST")
4536 if not os.path.exists(pkglist): 4524 if not os.path.exists(pkglist):
4537 QMessageBox.critical(None, 4525 QMessageBox.critical(None,
4538 self.trUtf8("Create Plugin Archive"), 4526 self.trUtf8("Create Plugin Archive"),
4539 self.trUtf8("""<p>The file <b>PKGLIST</b> does not exist. """ 4527 self.trUtf8("""<p>The file <b>PKGLIST</b> does not exist. """
4540 """Aborting...</p>"""), 4528 """Aborting...</p>"""))
4541 QMessageBox.StandardButtons(\
4542 QMessageBox.Ok))
4543 return 4529 return
4544 4530
4545 if len(self.pdata["MAINSCRIPT"]) == 0 or \ 4531 if len(self.pdata["MAINSCRIPT"]) == 0 or \
4546 len(self.pdata["MAINSCRIPT"][0]) == 0: 4532 len(self.pdata["MAINSCRIPT"][0]) == 0:
4547 QMessageBox.critical(None, 4533 QMessageBox.critical(None,
4548 self.trUtf8("Create Plugin Archive"), 4534 self.trUtf8("Create Plugin Archive"),
4549 self.trUtf8("""The project does not have a main script defined. """ 4535 self.trUtf8("""The project does not have a main script defined. """
4550 """Aborting..."""), 4536 """Aborting..."""))
4551 QMessageBox.StandardButtons(\
4552 QMessageBox.Ok))
4553 return 4537 return
4554 4538
4555 try: 4539 try:
4556 pkglistFile = open(pkglist, "r", encoding = "utf-8") 4540 pkglistFile = open(pkglist, "r", encoding = "utf-8")
4557 names = pkglistFile.read() 4541 names = pkglistFile.read()
4559 names = sorted(names.splitlines()) 4543 names = sorted(names.splitlines())
4560 except IOError as why: 4544 except IOError as why:
4561 QMessageBox.critical(None, 4545 QMessageBox.critical(None,
4562 self.trUtf8("Create Plugin Archive"), 4546 self.trUtf8("Create Plugin Archive"),
4563 self.trUtf8("""<p>The file <b>PKGLIST</b> could not be read.</p>""" 4547 self.trUtf8("""<p>The file <b>PKGLIST</b> could not be read.</p>"""
4564 """<p>Reason: {0}</p>""").format(str(why)), 4548 """<p>Reason: {0}</p>""").format(str(why)))
4565 QMessageBox.StandardButtons(\
4566 QMessageBox.Ok))
4567 return 4549 return
4568 4550
4569 archive = \ 4551 archive = \
4570 os.path.join(self.ppath, self.pdata["MAINSCRIPT"][0].replace(".py", ".zip")) 4552 os.path.join(self.ppath, self.pdata["MAINSCRIPT"][0].replace(".py", ".zip"))
4571 try: 4553 try:
4576 except IOError as why: 4558 except IOError as why:
4577 QMessageBox.critical(None, 4559 QMessageBox.critical(None,
4578 self.trUtf8("Create Plugin Archive"), 4560 self.trUtf8("Create Plugin Archive"),
4579 self.trUtf8("""<p>The eric5 plugin archive file <b>{0}</b> could """ 4561 self.trUtf8("""<p>The eric5 plugin archive file <b>{0}</b> could """
4580 """not be created.</p>""" 4562 """not be created.</p>"""
4581 """<p>Reason: {1}</p>""").format(archive, str(why)), 4563 """<p>Reason: {1}</p>""").format(archive, str(why)))
4582 QMessageBox.StandardButtons(\
4583 QMessageBox.Ok))
4584 return 4564 return
4585 4565
4586 for name in names: 4566 for name in names:
4587 try: 4567 try:
4588 self.__createZipDirEntries(os.path.split(name)[0], archiveFile) 4568 self.__createZipDirEntries(os.path.split(name)[0], archiveFile)
4599 QMessageBox.critical(None, 4579 QMessageBox.critical(None,
4600 self.trUtf8("Create Plugin Archive"), 4580 self.trUtf8("Create Plugin Archive"),
4601 self.trUtf8("""<p>The file <b>{0}</b> could not be stored """ 4581 self.trUtf8("""<p>The file <b>{0}</b> could not be stored """
4602 """in the archive. Ignoring it.</p>""" 4582 """in the archive. Ignoring it.</p>"""
4603 """<p>Reason: {1}</p>""")\ 4583 """<p>Reason: {1}</p>""")\
4604 .format(os.path.join(self.ppath, name), str(why)), 4584 .format(os.path.join(self.ppath, name), str(why)))
4605 QMessageBox.StandardButtons(\
4606 QMessageBox.Ok))
4607 archiveFile.writestr("VERSION", version.encode("utf-8")) 4585 archiveFile.writestr("VERSION", version.encode("utf-8"))
4608 archiveFile.close() 4586 archiveFile.close()
4609 4587
4610 if not archive in self.pdata["OTHERS"]: 4588 if not archive in self.pdata["OTHERS"]:
4611 self.appendFile(archive) 4589 self.appendFile(archive)
4612 4590
4613 QMessageBox.information(None, 4591 QMessageBox.information(None,
4614 self.trUtf8("Create Plugin Archive"), 4592 self.trUtf8("Create Plugin Archive"),
4615 self.trUtf8("""<p>The eric5 plugin archive file <b>{0}</b> was """ 4593 self.trUtf8("""<p>The eric5 plugin archive file <b>{0}</b> was """
4616 """created successfully.</p>""").format(archive), 4594 """created successfully.</p>""").format(archive))
4617 QMessageBox.StandardButtons(\
4618 QMessageBox.Ok))
4619 4595
4620 def __pluginCreateSnapshotArchive(self): 4596 def __pluginCreateSnapshotArchive(self):
4621 """ 4597 """
4622 Private slot to create an eric5 plugin archive snapshot release. 4598 Private slot to create an eric5 plugin archive snapshot release.
4623 """ 4599 """
4657 except (IOError, UnicodeError) as why: 4633 except (IOError, UnicodeError) as why:
4658 QMessageBox.critical(None, 4634 QMessageBox.critical(None,
4659 self.trUtf8("Create Plugin Archive"), 4635 self.trUtf8("Create Plugin Archive"),
4660 self.trUtf8("""<p>The plugin file <b>{0}</b> could """ 4636 self.trUtf8("""<p>The plugin file <b>{0}</b> could """
4661 """not be read.</p>""" 4637 """not be read.</p>"""
4662 """<p>Reason: {1}</p>""").format(archive, str(why)), 4638 """<p>Reason: {1}</p>""").format(archive, str(why)))
4663 QMessageBox.StandardButtons(\
4664 QMessageBox.Ok))
4665 return b"", "" 4639 return b"", ""
4666 4640
4667 lineno = 0 4641 lineno = 0
4668 while lineno < len(sourcelines): 4642 while lineno < len(sourcelines):
4669 if sourcelines[lineno].startswith("version = "): 4643 if sourcelines[lineno].startswith("version = "):
4696 except (IOError, UnicodeError) as why: 4670 except (IOError, UnicodeError) as why:
4697 QMessageBox.critical(None, 4671 QMessageBox.critical(None,
4698 self.trUtf8("Create Plugin Archive"), 4672 self.trUtf8("Create Plugin Archive"),
4699 self.trUtf8("""<p>The plugin file <b>{0}</b> could """ 4673 self.trUtf8("""<p>The plugin file <b>{0}</b> could """
4700 """not be read.</p>""" 4674 """not be read.</p>"""
4701 """<p>Reason: {1}</p>""").format(archive, str(why)), 4675 """<p>Reason: {1}</p>""").format(archive, str(why)))
4702 QMessageBox.StandardButtons(\
4703 QMessageBox.Ok))
4704 return "" 4676 return ""
4705 4677
4706 for sourceline in sourcelines: 4678 for sourceline in sourcelines:
4707 if sourceline.startswith("version = "): 4679 if sourceline.startswith("version = "):
4708 version = sourceline.replace("version = ", "").strip()\ 4680 version = sourceline.replace("version = ", "").strip()\

eric ide

mercurial