|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the gpg extension interface. |
|
8 """ |
|
9 |
|
10 from PyQt5.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 self.vcs.hgGetBookmarksList()) |
|
58 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
59 rev = dlg.getRevision(revset=False) |
|
60 |
|
61 if rev is not None: |
|
62 if rev == "": |
|
63 rev = "tip" |
|
64 args = self.vcs.initCommand("sigcheck") |
|
65 args.append(rev) |
|
66 |
|
67 dia = HgDialog(self.tr('Verify Signatures'), self.vcs) |
|
68 res = dia.startProcess(args) |
|
69 if res: |
|
70 dia.exec() |
|
71 |
|
72 def hgGpgSign(self, revisions=None): |
|
73 """ |
|
74 Public method used to list the available bookmarks. |
|
75 |
|
76 @param revisions list containing the revisions to be signed |
|
77 @type list of str |
|
78 """ |
|
79 if revisions is None: |
|
80 from .HgGpgSignDialog import HgGpgSignDialog |
|
81 dlg = HgGpgSignDialog(self.vcs.hgGetTagsList(), |
|
82 self.vcs.hgGetBranchesList(), |
|
83 self.vcs.hgGetBookmarksList()) |
|
84 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
85 revision, noCommit, message, keyId, local, force = ( |
|
86 dlg.getData() |
|
87 ) |
|
88 if revision: |
|
89 revisions = [revision] |
|
90 else: |
|
91 revisions = [] |
|
92 else: |
|
93 return |
|
94 else: |
|
95 noCommit = False |
|
96 message = "" |
|
97 keyId = "" |
|
98 local = False |
|
99 force = False |
|
100 |
|
101 args = self.vcs.initCommand("sign") |
|
102 if noCommit: |
|
103 args.append("--no-commit") |
|
104 if message: |
|
105 args.append("--message") |
|
106 args.append(message) |
|
107 if keyId: |
|
108 args.append("--key") |
|
109 args.append(keyId) |
|
110 if local: |
|
111 args.append("--local") |
|
112 if force: |
|
113 args.append("--force") |
|
114 for rev in revisions: |
|
115 args.append(rev) |
|
116 |
|
117 dia = HgDialog(self.tr('Sign Revision'), self.vcs) |
|
118 res = dia.startProcess(args) |
|
119 if res: |
|
120 dia.exec() |