9 |
9 |
10 import os |
10 import os |
11 import shutil |
11 import shutil |
12 import re |
12 import re |
13 import contextlib |
13 import contextlib |
|
14 import pathlib |
14 |
15 |
15 from PyQt6.QtCore import QProcess, pyqtSignal, QFileInfo |
16 from PyQt6.QtCore import QProcess, pyqtSignal |
16 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog, QLineEdit |
17 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog, QLineEdit |
17 |
18 |
18 from EricWidgets.EricApplication import ericApp |
19 from EricWidgets.EricApplication import ericApp |
19 from EricWidgets import EricMessageBox, EricFileDialog |
20 from EricWidgets import EricMessageBox, EricFileDialog |
20 |
21 |
2341 EricFileDialog.DontConfirmOverwrite) |
2342 EricFileDialog.DontConfirmOverwrite) |
2342 |
2343 |
2343 if not fname: |
2344 if not fname: |
2344 return # user aborted |
2345 return # user aborted |
2345 |
2346 |
2346 ext = QFileInfo(fname).suffix() |
2347 fpath = pathlib.Path(fname) |
2347 if not ext: |
2348 if not fpath.suffix: |
2348 ex = selectedFilter.split("(*")[1].split(")")[0] |
2349 ex = selectedFilter.split("(*")[1].split(")")[0] |
2349 if ex: |
2350 if ex: |
2350 fname += ex |
2351 fpath = fpath.with_suffix(ex) |
2351 if QFileInfo(fname).exists(): |
2352 if fpath.exists(): |
2352 res = EricMessageBox.yesNo( |
2353 res = EricMessageBox.yesNo( |
2353 self.__ui, |
2354 self.__ui, |
2354 self.tr("Create Bundle"), |
2355 self.tr("Create Bundle"), |
2355 self.tr("<p>The Git bundle file <b>{0}</b> " |
2356 self.tr("<p>The Git bundle file <b>{0}</b> " |
2356 "already exists. Overwrite it?</p>") |
2357 "already exists. Overwrite it?</p>") |
2357 .format(fname), |
2358 .format(fpath), |
2358 icon=EricMessageBox.Warning) |
2359 icon=EricMessageBox.Warning) |
2359 if not res: |
2360 if not res: |
2360 return |
2361 return |
2361 fname = Utilities.toNativeSeparators(fname) |
2362 |
2362 self.__lastBundlePath = os.path.dirname(fname) |
2363 self.__lastBundlePath = str(fpath.parent) |
2363 |
2364 |
2364 args = self.initCommand("bundle") |
2365 args = self.initCommand("bundle") |
2365 args.append("create") |
2366 args.append("create") |
2366 args.append(fname) |
2367 args.append(str(fpath)) |
2367 for rev in revs: |
2368 for rev in revs: |
2368 args.append(rev) |
2369 args.append(rev) |
2369 |
2370 |
2370 dia = GitDialog(self.tr('Create Bundle'), self) |
2371 dia = GitDialog(self.tr('Create Bundle'), self) |
2371 res = dia.startProcess(args, repodir) |
2372 res = dia.startProcess(args, repodir) |
2692 EricFileDialog.DontConfirmOverwrite) |
2693 EricFileDialog.DontConfirmOverwrite) |
2693 |
2694 |
2694 if not fname: |
2695 if not fname: |
2695 return # user aborted |
2696 return # user aborted |
2696 |
2697 |
2697 ext = QFileInfo(fname).suffix() |
2698 fpath = pathlib.Path(fname) |
2698 if not ext: |
2699 if not fpath.suffix: |
2699 ex = selectedFilter.split("(*")[1].split(")")[0] |
2700 ex = selectedFilter.split("(*")[1].split(")")[0] |
2700 if ex: |
2701 if ex: |
2701 fname += ex |
2702 fpath = fpath.with_suffix(ex) |
2702 if QFileInfo(fname).exists(): |
2703 if fpath.exists(): |
2703 res = EricMessageBox.yesNo( |
2704 res = EricMessageBox.yesNo( |
2704 self.__ui, |
2705 self.__ui, |
2705 self.tr("Create Bisect Replay File"), |
2706 self.tr("Create Bisect Replay File"), |
2706 self.tr("<p>The Git bisect replay file <b>{0}</b> " |
2707 self.tr("<p>The Git bisect replay file <b>{0}</b> " |
2707 "already exists. Overwrite it?</p>") |
2708 "already exists. Overwrite it?</p>") |
2708 .format(fname), |
2709 .format(fpath), |
2709 icon=EricMessageBox.Warning) |
2710 icon=EricMessageBox.Warning) |
2710 if not res: |
2711 if not res: |
2711 return |
2712 return |
2712 fname = Utilities.toNativeSeparators(fname) |
2713 self.__lastReplayPath = str(fpath.parent) |
2713 self.__lastReplayPath = os.path.dirname(fname) |
|
2714 |
2714 |
2715 try: |
2715 try: |
2716 with open(fname, "w") as f: |
2716 with fpath.open("w") as f: |
2717 f.write(output) |
2717 f.write(output) |
2718 except OSError as err: |
2718 except OSError as err: |
2719 EricMessageBox.critical( |
2719 EricMessageBox.critical( |
2720 self.__ui, |
2720 self.__ui, |
2721 self.tr("Create Bisect Replay File"), |
2721 self.tr("Create Bisect Replay File"), |
2722 self.tr( |
2722 self.tr( |
2723 """<p>The file <b>{0}</b> could not be written.</p>""" |
2723 """<p>The file <b>{0}</b> could not be written.</p>""" |
2724 """<p>Reason: {1}</p>""") |
2724 """<p>Reason: {1}</p>""") |
2725 .format(fname, str(err))) |
2725 .format(fpath, str(err))) |
2726 |
2726 |
2727 def gitBisectEditReplayFile(self, projectDir): |
2727 def gitBisectEditReplayFile(self, projectDir): |
2728 """ |
2728 """ |
2729 Public method used to edit a bisect replay file. |
2729 Public method used to edit a bisect replay file. |
2730 |
2730 |