8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 import shutil |
11 import shutil |
12 import re |
12 import re |
|
13 import contextlib |
13 |
14 |
14 from PyQt5.QtCore import QProcess, pyqtSignal, QFileInfo |
15 from PyQt5.QtCore import QProcess, pyqtSignal, QFileInfo |
15 from PyQt5.QtWidgets import QApplication, QDialog, QInputDialog, QLineEdit |
16 from PyQt5.QtWidgets import QApplication, QDialog, QInputDialog, QLineEdit |
16 |
17 |
17 from E5Gui.E5Application import e5App |
18 from E5Gui.E5Application import e5App |
770 being edited and has unsaved modification, they can be saved or the |
771 being edited and has unsaved modification, they can be saved or the |
771 operation may be aborted. |
772 operation may be aborted. |
772 |
773 |
773 @param name file/directory name to be diffed (string) |
774 @param name file/directory name to be diffed (string) |
774 """ |
775 """ |
775 if isinstance(name, list): |
776 names = name[:] if isinstance(name, list) else [name] |
776 names = name[:] |
|
777 else: |
|
778 names = [name] |
|
779 for nam in names: |
777 for nam in names: |
780 if os.path.isfile(nam): |
778 if os.path.isfile(nam): |
781 editor = e5App().getObject("ViewManager").getOpenEditor(nam) |
779 editor = e5App().getObject("ViewManager").getOpenEditor(nam) |
782 if editor and not editor.checkDirty(): |
780 if editor and not editor.checkDirty(): |
783 return |
781 return |
1104 if line and line[0] in " MADRCU!?": |
1102 if line and line[0] in " MADRCU!?": |
1105 flag = line[1] |
1103 flag = line[1] |
1106 path = line[3:].split(" -> ")[-1] |
1104 path = line[3:].split(" -> ")[-1] |
1107 name = os.path.normcase(os.path.join(repodir, path)) |
1105 name = os.path.normcase(os.path.join(repodir, path)) |
1108 dirName = os.path.dirname(name) |
1106 dirName = os.path.dirname(name) |
1109 if name.startswith(dname): |
1107 if name.startswith(dname) and flag in "?!": |
1110 if flag in "?!": |
1108 isDir = name.endswith(("/", "\\")) |
1111 isDir = name.endswith(("/", "\\")) |
1109 if isDir: |
1112 if isDir: |
1110 name = name[:-1] |
1113 name = name[:-1] |
1111 if name in names: |
1114 if name in names: |
1112 names[name] = self.canBeAdded |
1115 names[name] = self.canBeAdded |
1113 if isDir: |
1116 if isDir: |
1114 # it's a directory |
1117 # it's a directory |
1115 for nname in names: |
1118 for nname in names: |
1116 if nname.startswith(name): |
1119 if nname.startswith(name): |
1117 names[nname] = self.canBeAdded |
1120 names[nname] = self.canBeAdded |
|
1121 if flag not in "?!": |
1118 if flag not in "?!": |
1122 self.statusCache[name] = self.canBeCommitted |
1119 self.statusCache[name] = self.canBeCommitted |
1123 self.statusCache[dirName] = self.canBeCommitted |
1120 self.statusCache[dirName] = self.canBeCommitted |
1124 else: |
1121 else: |
1125 self.statusCache[name] = self.canBeAdded |
1122 self.statusCache[name] = self.canBeAdded |
1168 entries = [] |
1165 entries = [] |
1169 for pat in patterns: |
1166 for pat in patterns: |
1170 entries.extend(Utilities.direntries(name, True, pat)) |
1167 entries.extend(Utilities.direntries(name, True, pat)) |
1171 |
1168 |
1172 for entry in entries: |
1169 for entry in entries: |
1173 try: |
1170 with contextlib.suppress(OSError): |
1174 os.remove(entry) |
1171 os.remove(entry) |
1175 except OSError: |
|
1176 pass |
|
1177 |
1172 |
1178 def vcsCommandLine(self, name): |
1173 def vcsCommandLine(self, name): |
1179 """ |
1174 """ |
1180 Public method used to execute arbitrary Git commands. |
1175 Public method used to execute arbitrary Git commands. |
1181 |
1176 |
1386 "__pycache__/", |
1381 "__pycache__/", |
1387 "*.DS_Store", |
1382 "*.DS_Store", |
1388 ] |
1383 ] |
1389 |
1384 |
1390 ignoreName = os.path.join(name, Git.IgnoreFileName) |
1385 ignoreName = os.path.join(name, Git.IgnoreFileName) |
1391 if os.path.exists(ignoreName): |
1386 res = ( |
1392 res = E5MessageBox.yesNo( |
1387 E5MessageBox.yesNo( |
1393 self.__ui, |
1388 self.__ui, |
1394 self.tr("Create {0} file").format(ignoreName), |
1389 self.tr("Create {0} file").format(ignoreName), |
1395 self.tr("""<p>The file <b>{0}</b> exists already.""" |
1390 self.tr("""<p>The file <b>{0}</b> exists already.""" |
1396 """ Overwrite it?</p>""").format(ignoreName), |
1391 """ Overwrite it?</p>""").format(ignoreName), |
1397 icon=E5MessageBox.Warning) |
1392 icon=E5MessageBox.Warning) |
1398 else: |
1393 if os.path.exists(ignoreName) else |
1399 res = True |
1394 True |
|
1395 ) |
1400 if res: |
1396 if res: |
1401 try: |
1397 try: |
1402 # create a .gitignore file |
1398 # create a .gitignore file |
1403 with open(ignoreName, "w") as ignore: |
1399 with open(ignoreName, "w") as ignore: |
1404 ignore.write("\n".join(ignorePatterns)) |
1400 ignore.write("\n".join(ignorePatterns)) |
3574 return |
3570 return |
3575 |
3571 |
3576 cfgFile = os.path.join(repodir, self.adminDir, "config") |
3572 cfgFile = os.path.join(repodir, self.adminDir, "config") |
3577 if not os.path.exists(cfgFile): |
3573 if not os.path.exists(cfgFile): |
3578 # create an empty one |
3574 # create an empty one |
3579 try: |
3575 with contextlib.suppress(OSError), open(cfgFile, "w"): |
3580 with open(cfgFile, "w"): |
|
3581 pass |
|
3582 except OSError: |
|
3583 pass |
3576 pass |
3584 self.repoEditor = MiniEditor(cfgFile, "Properties") |
3577 self.repoEditor = MiniEditor(cfgFile, "Properties") |
3585 self.repoEditor.show() |
3578 self.repoEditor.show() |
3586 |
3579 |
3587 def gitEditUserConfig(self): |
3580 def gitEditUserConfig(self): |
3596 if dlg.exec() == QDialog.DialogCode.Accepted: |
3589 if dlg.exec() == QDialog.DialogCode.Accepted: |
3597 firstName, lastName, email = dlg.getData() |
3590 firstName, lastName, email = dlg.getData() |
3598 else: |
3591 else: |
3599 firstName, lastName, email = ( |
3592 firstName, lastName, email = ( |
3600 "Firstname", "Lastname", "email_address") |
3593 "Firstname", "Lastname", "email_address") |
3601 try: |
3594 with contextlib.suppress(OSError), open(cfgFile, "w") as f: |
3602 with open(cfgFile, "w") as f: |
3595 f.write("[user]\n") |
3603 f.write("[user]\n") |
3596 f.write(" name = {0} {1}\n".format(firstName, lastName)) |
3604 f.write(" name = {0} {1}\n".format(firstName, lastName)) |
3597 f.write(" email = {0}\n".format(email)) |
3605 f.write(" email = {0}\n".format(email)) |
|
3606 except OSError: |
|
3607 # ignore these |
|
3608 pass |
|
3609 self.userEditor = MiniEditor(cfgFile, "Properties") |
3598 self.userEditor = MiniEditor(cfgFile, "Properties") |
3610 self.userEditor.show() |
3599 self.userEditor.show() |
3611 |
3600 |
3612 def gitShowConfig(self, projectDir): |
3601 def gitShowConfig(self, projectDir): |
3613 """ |
3602 """ |