50 from .HgClient import HgClient |
50 from .HgClient import HgClient |
51 from .HgImportDialog import HgImportDialog |
51 from .HgImportDialog import HgImportDialog |
52 from .HgExportDialog import HgExportDialog |
52 from .HgExportDialog import HgExportDialog |
53 from .HgPhaseDialog import HgPhaseDialog |
53 from .HgPhaseDialog import HgPhaseDialog |
54 from .HgGraftDialog import HgGraftDialog |
54 from .HgGraftDialog import HgGraftDialog |
|
55 from .HgAddSubrepositoryDialog import HgAddSubrepositoryDialog |
55 |
56 |
56 from .BookmarksExtension.bookmarks import Bookmarks |
57 from .BookmarksExtension.bookmarks import Bookmarks |
57 from .QueuesExtension.queues import Queues |
58 from .QueuesExtension.queues import Queues |
58 from .FetchExtension.fetch import Fetch |
59 from .FetchExtension.fetch import Fetch |
59 from .PurgeExtension.purge import Purge |
60 from .PurgeExtension.purge import Purge |
2626 res = dia.hasAddOrDelete() |
2628 res = dia.hasAddOrDelete() |
2627 self.checkVCSStatus() |
2629 self.checkVCSStatus() |
2628 return res |
2630 return res |
2629 |
2631 |
2630 ############################################################################ |
2632 ############################################################################ |
|
2633 ## Methods to deal with subrepositories are below. |
|
2634 ############################################################################ |
|
2635 |
|
2636 def getHgSubPath(self): |
|
2637 """ |
|
2638 Public method to get the path to the .hgsub file containing the definitions |
|
2639 of subrepositories. |
|
2640 |
|
2641 @return full path of the .hgsub file (string) |
|
2642 """ |
|
2643 ppath = self.__projectHelper.getProject().getProjectPath() |
|
2644 return os.path.join(ppath, ".hgsub") |
|
2645 |
|
2646 def hasSubrepositories(self): |
|
2647 """ |
|
2648 Public method to check, if the project might have subrepositories. |
|
2649 |
|
2650 @return flag indicating the existence of subrepositories (boolean) |
|
2651 """ |
|
2652 hgsub = self.getHgSubPath() |
|
2653 return os.path.isfile(hgsub) and os.stat(hgsub).st_size > 0 |
|
2654 |
|
2655 def hgAddSubrepository(self): |
|
2656 """ |
|
2657 Public method to add a subrepository. |
|
2658 """ |
|
2659 ppath = self.__projectHelper.getProject().getProjectPath() |
|
2660 hgsub = self.getHgSubPath() |
|
2661 dlg = HgAddSubrepositoryDialog(ppath) |
|
2662 if dlg.exec_() == QDialog.Accepted: |
|
2663 relPath, subrepoType, subrepoUrl = dlg.getData() |
|
2664 if subrepoType == "hg": |
|
2665 url = subrepoUrl |
|
2666 else: |
|
2667 url = "[{0}]{1}".format(subrepoType, subrepoUrl) |
|
2668 entry = "{0} = {1}\n".format(relPath, url) |
|
2669 |
|
2670 contents = [] |
|
2671 if os.path.isfile(hgsub): |
|
2672 # file exists; check, if such an entry exists already |
|
2673 needsAdd = False |
|
2674 try: |
|
2675 f = open(hgsub, "r") |
|
2676 contents = f.readlines() |
|
2677 f.close() |
|
2678 except IOError as err: |
|
2679 E5MessageBox.critical(self.__ui, |
|
2680 self.trUtf8("Add Subrepository"), |
|
2681 self.trUtf8("""<p>The subrepositories file .hgsub could not""" |
|
2682 """ be read.</p><p>Reason: {0}</p>""") |
|
2683 .format(str(err))) |
|
2684 return |
|
2685 |
|
2686 if entry in contents: |
|
2687 E5MessageBox.critical(self.__ui, |
|
2688 self.trUtf8("Add Subrepository"), |
|
2689 self.trUtf8("""<p>The subrepositories file .hgsub already""" |
|
2690 """ contains an entry <b>{0}</b>. Aborting...</p>""") |
|
2691 .format(entry)) |
|
2692 return |
|
2693 else: |
|
2694 needsAdd = True |
|
2695 |
|
2696 if contents and not contents[-1].endswith("\n"): |
|
2697 contents[-1] = contents[-1] + "\n" |
|
2698 contents.append(entry) |
|
2699 try: |
|
2700 f = open(hgsub, "w") |
|
2701 f.writelines(contents) |
|
2702 f.close() |
|
2703 except IOError as err: |
|
2704 E5MessageBox.critical(self.__ui, |
|
2705 self.trUtf8("Add Subrepository"), |
|
2706 self.trUtf8("""<p>The subrepositories file .hgsub could not""" |
|
2707 """ be written to.</p><p>Reason: {0}</p>""") |
|
2708 .format(str(err))) |
|
2709 return |
|
2710 |
|
2711 if needsAdd: |
|
2712 self.vcsAdd(hgsub) |
|
2713 self.__projectHelper.getProject().appendFile(hgsub) |
|
2714 |
|
2715 ############################################################################ |
2631 ## Methods to handle extensions are below. |
2716 ## Methods to handle extensions are below. |
2632 ############################################################################ |
2717 ############################################################################ |
2633 |
2718 |
2634 def __iniFileChanged(self, path): |
2719 def __iniFileChanged(self, path): |
2635 """ |
2720 """ |