Project/Project.py

changeset 5599
033967644b1f
parent 5587
ea526b78ee6c
child 5616
adcffadf4962
equal deleted inserted replaced
5597:3d88d53f8c2b 5599:033967644b1f
782 if dn not in self.otherssubdirs: 782 if dn not in self.otherssubdirs:
783 self.otherssubdirs.append(dn) 783 self.otherssubdirs.append(dn)
784 784
785 # create hash value, if it doesn't have one 785 # create hash value, if it doesn't have one
786 if reader.version.startswith("5.") and not self.pdata["HASH"]: 786 if reader.version.startswith("5.") and not self.pdata["HASH"]:
787 hash = str(QCryptographicHash.hash( 787 hashStr = str(QCryptographicHash.hash(
788 QByteArray(self.ppath.encode("utf-8")), 788 QByteArray(self.ppath.encode("utf-8")),
789 QCryptographicHash.Sha1).toHex(), 789 QCryptographicHash.Sha1).toHex(),
790 encoding="utf-8") 790 encoding="utf-8")
791 self.pdata["HASH"] = hash 791 self.pdata["HASH"] = hashStr
792 self.setDirty(True) 792 self.setDirty(True)
793 793
794 return res 794 return res
795 795
796 def __writeProject(self, fn=None): 796 def __writeProject(self, fn=None):
809 copy.deepcopy(self.vcs.vcsGetOptions()) 809 copy.deepcopy(self.vcs.vcsGetOptions())
810 self.pdata["VCSOTHERDATA"] = \ 810 self.pdata["VCSOTHERDATA"] = \
811 copy.deepcopy(self.vcs.vcsGetOtherData()) 811 copy.deepcopy(self.vcs.vcsGetOtherData())
812 812
813 if not self.pdata["HASH"]: 813 if not self.pdata["HASH"]:
814 hash = str(QCryptographicHash.hash( 814 hashStr = str(QCryptographicHash.hash(
815 QByteArray(self.ppath.encode("utf-8")), 815 QByteArray(self.ppath.encode("utf-8")),
816 QCryptographicHash.Sha1).toHex(), 816 QCryptographicHash.Sha1).toHex(),
817 encoding="utf-8") 817 encoding="utf-8")
818 self.pdata["HASH"] = hash 818 self.pdata["HASH"] = hashStr
819 819
820 if fn is None: 820 if fn is None:
821 fn = self.pfile 821 fn = self.pfile
822 822
823 f = QFile(fn) 823 f = QFile(fn)
1510 1510
1511 if dirty: 1511 if dirty:
1512 self.setDirty(True) 1512 self.setDirty(True)
1513 1513
1514 @pyqtSlot() 1514 @pyqtSlot()
1515 def addFiles(self, filter=None, startdir=None): 1515 def addFiles(self, fileTypeFilter=None, startdir=None):
1516 """ 1516 """
1517 Public slot used to add files to the project. 1517 Public slot used to add files to the project.
1518 1518
1519 @param filter filter to be used by the add file dialog 1519 @param fileTypeFilter filter to be used by the add file dialog
1520 (string out of source, form, resource, interface, others) 1520 (string out of source, form, resource, interface, others)
1521 @param startdir start directory for the selection dialog 1521 @param startdir start directory for the selection dialog
1522 """ 1522 """
1523 if startdir is None: 1523 if startdir is None:
1524 startdir = self.ppath 1524 startdir = self.ppath
1525 from .AddFileDialog import AddFileDialog 1525 from .AddFileDialog import AddFileDialog
1526 dlg = AddFileDialog(self, self.parent(), filter, startdir=startdir) 1526 dlg = AddFileDialog(self, self.parent(), fileTypeFilter,
1527 startdir=startdir)
1527 if dlg.exec_() == QDialog.Accepted: 1528 if dlg.exec_() == QDialog.Accepted:
1528 fnames, target, isSource = dlg.getData() 1529 fnames, target, isSource = dlg.getData()
1529 if target != '': 1530 if target != '':
1530 for fn in fnames: 1531 for fn in fnames:
1531 targetfile = os.path.join(target, os.path.basename(fn)) 1532 targetfile = os.path.join(target, os.path.basename(fn))
1556 " not be added to <b>{1}</b>.</p>" 1557 " not be added to <b>{1}</b>.</p>"
1557 "<p>Reason: {2}</p>") 1558 "<p>Reason: {2}</p>")
1558 .format(fn, target, str(why))) 1559 .format(fn, target, str(why)))
1559 continue 1560 continue
1560 1561
1561 self.appendFile(targetfile, isSource or filter == 'source') 1562 self.appendFile(targetfile,
1563 isSource or fileTypeFilter == 'source')
1562 else: 1564 else:
1563 E5MessageBox.critical( 1565 E5MessageBox.critical(
1564 self.ui, 1566 self.ui,
1565 self.tr("Add file"), 1567 self.tr("Add file"),
1566 self.tr("The target directory must not be empty.")) 1568 self.tr("The target directory must not be empty."))
1659 if os.path.isdir(ns): 1661 if os.path.isdir(ns):
1660 nt = os.path.join(target, name) 1662 nt = os.path.join(target, name)
1661 self.__addRecursiveDirectory(filetype, ns, nt) 1663 self.__addRecursiveDirectory(filetype, ns, nt)
1662 1664
1663 @pyqtSlot() 1665 @pyqtSlot()
1664 def addDirectory(self, filter=None, startdir=None): 1666 def addDirectory(self, fileTypeFilter=None, startdir=None):
1665 """ 1667 """
1666 Public method used to add all files of a directory to the project. 1668 Public method used to add all files of a directory to the project.
1667 1669
1668 @param filter filter to be used by the add directory dialog 1670 @param fileTypeFilter filter to be used by the add directory dialog
1669 (string out of source, form, resource, interface, others) 1671 (string out of source, form, resource, interface, others)
1670 @param startdir start directory for the selection dialog (string) 1672 @param startdir start directory for the selection dialog (string)
1671 """ 1673 """
1672 if startdir is None: 1674 if startdir is None:
1673 startdir = self.ppath 1675 startdir = self.ppath
1674 from .AddDirectoryDialog import AddDirectoryDialog 1676 from .AddDirectoryDialog import AddDirectoryDialog
1675 dlg = AddDirectoryDialog( 1677 dlg = AddDirectoryDialog(
1676 self, filter, self.parent(), startdir=startdir) 1678 self, fileTypeFilter, self.parent(), startdir=startdir)
1677 if dlg.exec_() == QDialog.Accepted: 1679 if dlg.exec_() == QDialog.Accepted:
1678 filetype, source, target, recursive = dlg.getData() 1680 filetype, source, target, recursive = dlg.getData()
1679 if target == '': 1681 if target == '':
1680 E5MessageBox.critical( 1682 E5MessageBox.critical(
1681 self.ui, 1683 self.ui,
2170 self.addLanguageAct.setEnabled( 2172 self.addLanguageAct.setEnabled(
2171 bool(self.pdata["TRANSLATIONPATTERN"])) 2173 bool(self.pdata["TRANSLATIONPATTERN"]))
2172 2174
2173 self.projectAboutToBeCreated.emit() 2175 self.projectAboutToBeCreated.emit()
2174 2176
2175 hash = str(QCryptographicHash.hash( 2177 hashStr = str(QCryptographicHash.hash(
2176 QByteArray(self.ppath.encode("utf-8")), 2178 QByteArray(self.ppath.encode("utf-8")),
2177 QCryptographicHash.Sha1).toHex(), 2179 QCryptographicHash.Sha1).toHex(),
2178 encoding="utf-8") 2180 encoding="utf-8")
2179 self.pdata["HASH"] = hash 2181 self.pdata["HASH"] = hashStr
2180 2182
2181 # create the project directory if it doesn't exist already 2183 # create the project directory if it doesn't exist already
2182 if not os.path.isdir(self.ppath): 2184 if not os.path.isdir(self.ppath):
2183 try: 2185 try:
2184 os.makedirs(self.ppath) 2186 os.makedirs(self.ppath)
4244 autoInclude = Preferences.getProject("AutoIncludeNewFiles") 4246 autoInclude = Preferences.getProject("AutoIncludeNewFiles")
4245 recursiveSearch = Preferences.getProject("SearchNewFilesRecursively") 4247 recursiveSearch = Preferences.getProject("SearchNewFilesRecursively")
4246 newFiles = [] 4248 newFiles = []
4247 4249
4248 dirs = self.subdirs[:] 4250 dirs = self.subdirs[:]
4249 for dir in dirs: 4251 for directory in dirs:
4250 curpath = os.path.join(self.ppath, dir) 4252 curpath = os.path.join(self.ppath, directory)
4251 try: 4253 try:
4252 newSources = os.listdir(curpath) 4254 newSources = os.listdir(curpath)
4253 except OSError: 4255 except OSError:
4254 newSources = [] 4256 newSources = []
4255 if self.pdata["TRANSLATIONPATTERN"]: 4257 if self.pdata["TRANSLATIONPATTERN"]:
4269 continue 4271 continue
4270 4272
4271 # set fn to project relative name 4273 # set fn to project relative name
4272 # then reset ns to fully qualified name for insertion, 4274 # then reset ns to fully qualified name for insertion,
4273 # possibly. 4275 # possibly.
4274 if dir == "": 4276 if directory == "":
4275 fn = ns 4277 fn = ns
4276 else: 4278 else:
4277 fn = os.path.join(dir, ns) 4279 fn = os.path.join(directory, ns)
4278 ns = os.path.abspath(os.path.join(curpath, ns)) 4280 ns = os.path.abspath(os.path.join(curpath, ns))
4279 4281
4280 # do not bother with dirs here... 4282 # do not bother with dirs here...
4281 if os.path.isdir(ns): 4283 if os.path.isdir(ns):
4282 if recursiveSearch: 4284 if recursiveSearch:

eric ide

mercurial