|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the gpg extension interface. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QDialog |
|
11 |
|
12 from ..HgExtension import HgExtension |
|
13 from ..HgDialog import HgDialog |
|
14 from ..HgRevisionSelectionDialog import HgRevisionSelectionDialog |
|
15 |
|
16 |
|
17 class Gpg(HgExtension): |
|
18 """ |
|
19 Class implementing the gpg extension interface. |
|
20 """ |
|
21 def __init__(self, vcs): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param vcs reference to the Mercurial vcs object |
|
26 """ |
|
27 super().__init__(vcs) |
|
28 |
|
29 self.gpgSignaturesDialog = None |
|
30 |
|
31 def shutdown(self): |
|
32 """ |
|
33 Public method used to shutdown the gpg interface. |
|
34 """ |
|
35 if self.gpgSignaturesDialog is not None: |
|
36 self.gpgSignaturesDialog.close() |
|
37 |
|
38 def hgGpgSignatures(self): |
|
39 """ |
|
40 Public method used to list all signed changesets. |
|
41 """ |
|
42 from .HgGpgSignaturesDialog import HgGpgSignaturesDialog |
|
43 self.gpgSignaturesDialog = HgGpgSignaturesDialog(self.vcs) |
|
44 self.gpgSignaturesDialog.show() |
|
45 self.gpgSignaturesDialog.start() |
|
46 |
|
47 def hgGpgVerifySignatures(self, rev=None): |
|
48 """ |
|
49 Public method used to verify the signatures of a revision. |
|
50 |
|
51 @param rev revision to check (string) |
|
52 """ |
|
53 if rev is None: |
|
54 dlg = HgRevisionSelectionDialog( |
|
55 self.vcs.hgGetTagsList(), |
|
56 self.vcs.hgGetBranchesList(), |
|
57 bookmarksList=self.vcs.hgGetBookmarksList(), |
|
58 revset=False |
|
59 ) |
|
60 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
61 rev = dlg.getRevision() |
|
62 |
|
63 if rev is not None: |
|
64 if rev == "": |
|
65 rev = "tip" |
|
66 args = self.vcs.initCommand("sigcheck") |
|
67 args.append(rev) |
|
68 |
|
69 dia = HgDialog(self.tr('Verify Signatures'), self.vcs) |
|
70 res = dia.startProcess(args) |
|
71 if res: |
|
72 dia.exec() |
|
73 |
|
74 def hgGpgSign(self, revisions=None): |
|
75 """ |
|
76 Public method used to list the available bookmarks. |
|
77 |
|
78 @param revisions list containing the revisions to be signed |
|
79 @type list of str |
|
80 """ |
|
81 if revisions is None: |
|
82 from .HgGpgSignDialog import HgGpgSignDialog |
|
83 dlg = HgGpgSignDialog(self.vcs.hgGetTagsList(), |
|
84 self.vcs.hgGetBranchesList(), |
|
85 self.vcs.hgGetBookmarksList()) |
|
86 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
87 revision, noCommit, message, keyId, local, force = ( |
|
88 dlg.getData() |
|
89 ) |
|
90 if revision: |
|
91 revisions = [revision] |
|
92 else: |
|
93 revisions = [] |
|
94 else: |
|
95 return |
|
96 else: |
|
97 noCommit = False |
|
98 message = "" |
|
99 keyId = "" |
|
100 local = False |
|
101 force = False |
|
102 |
|
103 args = self.vcs.initCommand("sign") |
|
104 if noCommit: |
|
105 args.append("--no-commit") |
|
106 if message: |
|
107 args.append("--message") |
|
108 args.append(message) |
|
109 if keyId: |
|
110 args.append("--key") |
|
111 args.append(keyId) |
|
112 if local: |
|
113 args.append("--local") |
|
114 if force: |
|
115 args.append("--force") |
|
116 for rev in revisions: |
|
117 args.append(rev) |
|
118 |
|
119 dia = HgDialog(self.tr('Sign Revision'), self.vcs) |
|
120 res = dia.startProcess(args) |
|
121 if res: |
|
122 dia.exec() |