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