Compare commits

...

3 Commits

Author SHA1 Message Date
Micke Nordin 9fc9c77396
Fix init screen to use alert dialog
3 years ago
Micke Nordin c541c60aa9
Refactor: sorting methods, and make some
3 years ago
Micke Nordin 17b78797dc
Refactor: sorting methods, and make some
3 years ago

@ -8,6 +8,7 @@ from typing import Union
import wx
import wx.lib.scrolledpanel as scrolled
import wx.lib.dialogs as dialogs
import gnupg
from pass_handler import Pass, copy_to_clipboard, get_password_from_path, pass_pull, pass_push, run_command
@ -92,6 +93,7 @@ class PassUi(wx.Frame):
@redraw
def add_init(self):
"""add_init"""
select_label: str = "Select GPG Key"
if self.gpg_key:
label: wx.StaticText = wx.StaticText(self.pnl, label="Selected GPG key:")
@ -103,15 +105,18 @@ class PassUi(wx.Frame):
self.sizer.Add(gpg_btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON,
lambda event: self.gpg_button_clicked(), gpg_btn)
init_btn: wx.Button = wx.Button(self.pnl, label="Init Local Password Store")
git_btn: wx.Button = wx.Button(self.pnl, label="Clone Remote Password Store From Git")
self.sizer.Add(init_btn, 0, wx.EXPAND) # pylint: disable=no-member
self.sizer.Add(git_btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON,
lambda event: self.git_button_clicked(), git_btn)
if self.gpg_key:
init_btn: wx.Button = wx.Button(self.pnl, label="Init Local Password Store")
git_btn: wx.Button = wx.Button(self.pnl, label="Init Git Password Store")
self.sizer.Add(init_btn, 0, wx.EXPAND) # pylint: disable=no-member
self.sizer.Add(git_btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON,
lambda event: self.git_button_clicked(), git_btn)
self.Bind(wx.EVT_BUTTON,
lambda event: self.init_button_clicked(), init_btn)
else:
self.Bind(wx.EVT_BUTTON,
lambda event: dialogs.alertDialog(message='You must select a GPG key'), init_btn)
def add_push_pull(self):
"""add_push_pull."""
@ -125,7 +130,7 @@ class PassUi(wx.Frame):
def add_tools(self, index: Union[None, int] = None):
"""add_tools.
:param index:
:param index: Union[None.int]
"""
btn: wx.Button = wx.Button(self.pnl, label="Show tools")
font: wx.Font = btn.GetFont().MakeBold()
@ -138,17 +143,27 @@ class PassUi(wx.Frame):
def back_button_clicked(self, index: Union[None, int] = None):
"""back_button_clicked.
:param index:
:param index: Union[None.int]
"""
if index:
self.show_password_dialog(index)
else:
self.add_buttons()
def choice_button_clicked(self, event):
"""choice_button_clicked
:param event: wx.Event
"""
choice = event.GetEventObject()
self.gpg_key = choice.GetString(choice.GetSelection())
print(self.gpg_key)
self.add_init()
def delete_password(self, index: int):
"""delete_password.
:param index:
:param index: int
"""
path: str = self.pass_handler.get_pass_path_from_index(index, "password")
dlg: wx.MessageDialog = wx.MessageDialog(self.pnl,
@ -162,20 +177,6 @@ class PassUi(wx.Frame):
self.pass_handler.delete_password(path)
self.back_button_clicked()
def make_back_button(self, index: Union[None, int] = None) -> wx.Button:
"""make_back_button.
:param index:
"""
if index is not None:
label: str = self.pass_handler.get_pass_path_from_index(index, "password")
else:
label: str = self.pass_handler.cur_dir.replace(self.pass_handler.top_dir, '')
btn: wx.Button = wx.Button(self.pnl, label=label + '')
font: wx.Font = btn.GetFont().MakeItalic().MakeBold()
btn.SetFont(font)
return btn
def git_button_clicked(self):
"""git_button_clicked.
@ -184,6 +185,26 @@ class PassUi(wx.Frame):
# self.pass_handler.pass_init(self.gpg_key, git_repo)
# self.add_buttons()
def git_submit_btn_clicked(self, widget_list) -> str:
default_ports = {'git': 9418, 'git+ssh': 22, 'https': 443}
user: str = widget_list[1].GetLineText(0)
password: str = widget_list[3].GetLineText(0)
protocol: str = widget_list[5].GetString(widget_list[5].GetSelection())
host: str = widget_list[7].GetLineText(0)
port: str = widget_list[9].GetLineText(0)
path: str = widget_list[11].GetLineText(0)
if not port:
port = default_ports[protocol]
self.file_str = 'protocol={}\nhost={}:{}{}\nusername=\npassword={}\n'.format(protocol, host, port, path, user,
password)
timeout_in_sec = 24 * 60 * 60
temp_tuple = tempfile.mkstemp(text=self.file_str)
run_command(['/usr/bin/git', 'credential-store', '--file', temp_tuple[1]])
run_command(
['/usr/bin/git', 'config', 'credential.helper', 'cache --timeout={}'.format(timeout_in_sec)])
os.unlink(temp_tuple[1])
self.init_button_clicked('{}://{}:{}{}'.format(protocol, host, port, path))
def gpg_button_clicked(self):
"""gpg_button_clicked.
@ -202,6 +223,20 @@ class PassUi(wx.Frame):
self.pass_handler.pass_init(self.gpg_key, repo)
self.add_buttons()
def make_back_button(self, index: Union[None, int] = None) -> wx.Button:
"""make_back_button.
:param index:
"""
if index is not None:
label: str = self.pass_handler.get_pass_path_from_index(index, "password")
else:
label: str = self.pass_handler.cur_dir.replace(self.pass_handler.top_dir, '')
btn: wx.Button = wx.Button(self.pnl, label=label + '')
font: wx.Font = btn.GetFont().MakeItalic().MakeBold()
btn.SetFont(font)
return btn
def password_button_clicked(self, index: int):
"""password_button_clicked.
@ -265,12 +300,6 @@ class PassUi(wx.Frame):
self.sizer.Add(choice, 0, wx.EXPAND)
self.Bind(wx.EVT_CHOICE, lambda event: self.choice_button_clicked(event), choice)
def choice_button_clicked(self, event):
choice = event.GetEventObject()
self.gpg_key = choice.GetString(choice.GetSelection())
print(self.gpg_key)
self.add_init()
@redraw
def show_new_dialog(self):
"""show_new_dialog.
@ -418,26 +447,6 @@ class PassUi(wx.Frame):
self.Bind(wx.EVT_BUTTON, lambda event, m_widgets=widget_list: self.git_submit_btn_clicked(m_widgets),
widget_list[12])
def git_submit_btn_clicked(self, widget_list) -> str:
default_ports = {'git': 9418, 'git+ssh': 22, 'https': 443}
user: str = widget_list[1].GetLineText(0)
password: str = widget_list[3].GetLineText(0)
protocol: str = widget_list[5].GetString(widget_list[5].GetSelection())
host: str = widget_list[7].GetLineText(0)
port: str = widget_list[9].GetLineText(0)
path: str = widget_list[11].GetLineText(0)
if not port:
port = default_ports[protocol]
self.file_str = 'protocol={}\nhost={}:{}{}\nusername=\npassword={}\n'.format(protocol, host, port, path, user,
password)
timeout_in_sec = 24 * 60 * 60
temp_tuple = tempfile.mkstemp(text=self.file_str)
run_command(['/usr/bin/git', 'credential-store', '--file', temp_tuple[1]])
run_command(
['/usr/bin/git', 'config', 'credential.helper', 'cache --timeout={}'.format(timeout_in_sec)])
os.unlink(temp_tuple[1])
self.init_button_clicked('{}://{}:{}{}'.format(protocol, host, port, path))
if __name__ == '__main__':
# When this module is run (not imported) then create the app, the

Loading…
Cancel
Save