Refactor: sorting methods, and make some

things clearer
main
Micke Nordin 3 years ago
parent e5d1be7c3b
commit 17b78797dc
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -125,7 +125,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 +138,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 +172,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 +180,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 +218,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 +295,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 +442,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