Code clean up

Remove unused variables, fix return statements to be consistant
main
Micke Nordin 4 years ago
parent 353b19d8b3
commit d6b0842991

@ -20,7 +20,7 @@ class PassUi(wx.Frame):
:param kw: :param kw:
""" """
super().__init__(*args, **kw) super().__init__(*args, **kw)
# Find the top directory and set that to current dirtectory # Find the top directory and set that to current directory
self.topdir = os.environ.get('PASSWORD_STORE_DIR') self.topdir = os.environ.get('PASSWORD_STORE_DIR')
if not self.topdir: if not self.topdir:
self.topdir = os.environ.get('HOME') + '/.password-store' self.topdir = os.environ.get('HOME') + '/.password-store'
@ -43,7 +43,7 @@ class PassUi(wx.Frame):
btn = self.make_back_button() btn = self.make_back_button()
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event: self.path_button_clicked(event), btn) lambda event: self.path_button_clicked(), btn)
index = 0 index = 0
for cpath in self.cur_paths: for cpath in self.cur_paths:
if cpath != self.curdir: if cpath != self.curdir:
@ -52,7 +52,7 @@ class PassUi(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, path=cpath: self.path_button_clicked( lambda event, path=cpath: self.path_button_clicked(
event, path), path),
btn) btn)
index = index + 1 index = index + 1
index = 0 index = 0
@ -62,8 +62,8 @@ class PassUi(wx.Frame):
btn = wx.Button(self.pnl, label=label) btn = wx.Button(self.pnl, label=label)
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, index=index: self.password_button_clicked( lambda event, mindex=index: self.password_button_clicked(
event, index), mindex),
btn) btn)
index = index + 1 index = index + 1
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
@ -73,10 +73,10 @@ class PassUi(wx.Frame):
"""add_push_pull.""" """add_push_pull."""
pushbtn = wx.Button(self.pnl, label="Push to remote") pushbtn = wx.Button(self.pnl, label="Push to remote")
self.sizer.Add(pushbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(pushbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, lambda event: pass_push(event), pushbtn) self.Bind(wx.EVT_BUTTON, lambda event: pass_push(), pushbtn)
pullbtn = wx.Button(self.pnl, label="Pull from remote") pullbtn = wx.Button(self.pnl, label="Pull from remote")
self.sizer.Add(pullbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(pullbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, lambda event: pass_pull(event), pullbtn) self.Bind(wx.EVT_BUTTON, lambda event: pass_pull(), pullbtn)
def add_tools(self, index=None): def add_tools(self, index=None):
"""add_tools. """add_tools.
@ -88,13 +88,12 @@ class PassUi(wx.Frame):
btn.SetFont(font) btn.SetFont(font)
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, index=index: self.show_tools(event, index), lambda event, mindex=index: self.show_tools(mindex),
btn) btn)
def back_button_clicked(self, event, index=None): def back_button_clicked(self, index=None):
"""back_button_clicked. """back_button_clicked.
:param event:
:param index: :param index:
""" """
if index: if index:
@ -102,10 +101,9 @@ class PassUi(wx.Frame):
else: else:
self.add_buttons() self.add_buttons()
def delete_password(self, event, index): def delete_password(self, index):
"""delete_password. """delete_password.
:param event:
:param index: :param index:
""" """
path = self.get_pass_path_from_index(index, "password") path = self.get_pass_path_from_index(index, "password")
@ -116,13 +114,13 @@ class PassUi(wx.Frame):
dlg.SetOKCancelLabels("&Yes", "&Don't delete") dlg.SetOKCancelLabels("&Yes", "&Don't delete")
reply = dlg.ShowModal() reply = dlg.ShowModal()
if reply == wx.ID_CANCEL: if reply == wx.ID_CANCEL:
return True return
command1 = ['/usr/bin/pass', 'rm', '-f', path] command1 = ['/usr/bin/pass', 'rm', '-f', path]
result = run_command(command1) run_command(command1)
self.move_up() self.move_up()
self.cur_paths = self.get_pass_paths() self.cur_paths = self.get_pass_paths()
self.cur_passwords = self.get_pass_passwords() self.cur_passwords = self.get_pass_passwords()
self.back_button_clicked(event) self.back_button_clicked()
def get_pass_path_from_index(self, index, pathtype="path"): def get_pass_path_from_index(self, index, pathtype="path"):
"""get_pass_path_from_index. """get_pass_path_from_index.
@ -130,7 +128,6 @@ class PassUi(wx.Frame):
:param index: :param index:
:param pathtype: :param pathtype:
""" """
result = ""
if pathtype == "password": if pathtype == "password":
result = self.cur_passwords[index] result = self.cur_passwords[index]
else: else:
@ -163,7 +160,7 @@ class PassUi(wx.Frame):
:param index: :param index:
""" """
if index != None: if index is not None:
label = self.get_pass_path_from_index(index, "password") label = self.get_pass_path_from_index(index, "password")
else: else:
label = self.curdir.replace(self.topdir, '') label = self.curdir.replace(self.topdir, '')
@ -181,37 +178,34 @@ class PassUi(wx.Frame):
self.move_up() self.move_up()
return True return True
def password_button_clicked(self, event, index): def password_button_clicked(self, index):
"""password_button_clicked. """password_button_clicked.
:param event:
:param index: :param index:
""" """
self.show_password_dialog(index) self.show_password_dialog(index)
def path_button_clicked(self, event, path=None): def path_button_clicked(self, path=None):
"""path_button_clicked. """path_button_clicked.
:param event:
:param path: :param path:
""" """
if path == None: if path is None:
path = os.path.abspath(os.path.join(self.curdir, os.pardir)) path = os.path.abspath(os.path.join(self.curdir, os.pardir))
self.curdir = path self.curdir = path
self.cur_paths = self.get_pass_paths() self.cur_paths = self.get_pass_paths()
self.cur_passwords = self.get_pass_passwords() self.cur_passwords = self.get_pass_passwords()
self.add_buttons() self.add_buttons()
def save_to_pass(self, event, path, text, name=None): def save_to_pass(self, path, text, name=None):
"""save_to_pass. """save_to_pass.
:param event:
:param path: :param path:
:param text: :param text:
:param name: :param name:
""" """
fullpath = os.path.dirname(self.topdir + '/' + path.lstrip('/')) fullpath = os.path.dirname(self.topdir + '/' + path.lstrip('/'))
if name != None: if name is not None:
path = name.GetLineText(0) path = name.GetLineText(0)
fullpath = os.path.dirname(self.topdir + '/' + path.lstrip('/')) fullpath = os.path.dirname(self.topdir + '/' + path.lstrip('/'))
filename = fullpath + '.gpg' filename = fullpath + '.gpg'
@ -233,7 +227,7 @@ class PassUi(wx.Frame):
dlg.SetOKCancelLabels("&Yes", "&Don't save") dlg.SetOKCancelLabels("&Yes", "&Don't save")
reply = dlg.ShowModal() reply = dlg.ShowModal()
if reply == wx.ID_CANCEL: if reply == wx.ID_CANCEL:
return True return
password = str() password = str()
for lineno in range(text.GetNumberOfLines()): for lineno in range(text.GetNumberOfLines()):
password += text.GetLineText(lineno) password += text.GetLineText(lineno)
@ -241,15 +235,14 @@ class PassUi(wx.Frame):
command1 = ['/bin/echo', password.rstrip("\n")] command1 = ['/bin/echo', password.rstrip("\n")]
command2 = ['/usr/bin/pass', 'insert', '-m', path] command2 = ['/usr/bin/pass', 'insert', '-m', path]
result = run_command(command1, command2) run_command(command1, command2)
self.cur_paths = sorted([fullpath] + self.cur_paths) self.cur_paths = sorted([fullpath] + self.cur_paths)
self.cur_passwords = self.get_pass_passwords() self.cur_passwords = self.get_pass_passwords()
self.back_button_clicked(event) self.back_button_clicked()
def show_new_dialog(self, event): def show_new_dialog(self):
"""show_new_dialog. """show_new_dialog.
:param event:
""" """
self.sizer.Clear(delete_windows=True) self.sizer.Clear(delete_windows=True)
passpath = self.curdir.replace(self.topdir, '') passpath = self.curdir.replace(self.topdir, '')
@ -257,7 +250,7 @@ class PassUi(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, path=self.curdir: self.path_button_clicked( lambda event, path=self.curdir: self.path_button_clicked(
event, path), path),
btn) btn)
name_sizer = wx.BoxSizer(orient=wx.VERTICAL) # pylint: disable=no-member name_sizer = wx.BoxSizer(orient=wx.VERTICAL) # pylint: disable=no-member
@ -275,7 +268,7 @@ class PassUi(wx.Frame):
self.sizer.Add(sbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(sbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, path=passpath, mtext=text, mname=name: self. lambda event, path=passpath, mtext=text, mname=name: self.
save_to_pass(event, path, mtext, mname), save_to_pass(path, mtext, mname),
sbtn) sbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout() self.sizer.Layout()
@ -297,7 +290,7 @@ class PassUi(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind( self.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, path=cpath: self.path_button_clicked(event, path), lambda event, path=cpath: self.path_button_clicked(path),
btn) btn)
sbtn = wx.Button(self.pnl, label="Show/edit password") sbtn = wx.Button(self.pnl, label="Show/edit password")
@ -307,23 +300,22 @@ class PassUi(wx.Frame):
self.sizer.Add(cbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(cbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.sizer.Add(dbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(dbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, text=password: copy_to_clipboard(event, text), lambda event, text=password: copy_to_clipboard(text),
cbtn) cbtn)
self.Bind( self.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, mindex=index: self.show_password(event, mindex), lambda event, mindex=index: self.show_password(mindex),
sbtn) sbtn)
self.Bind( self.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, mindex=index: self.delete_password(event, mindex), lambda event, mindex=index: self.delete_password(mindex),
dbtn) dbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout() self.sizer.Layout()
def show_password(self, event, index): def show_password(self, index):
"""show_password. """show_password.
:param event:
:param index: :param index:
""" """
self.sizer.Clear(delete_windows=True) self.sizer.Clear(delete_windows=True)
@ -335,7 +327,7 @@ class PassUi(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind( self.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, path=cpath: self.path_button_clicked(event, path), lambda event, path=cpath: self.path_button_clicked(path),
btn) btn)
text = wx.TextCtrl(self.pnl, text = wx.TextCtrl(self.pnl,
@ -347,19 +339,18 @@ class PassUi(wx.Frame):
self.sizer.Add(cbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(cbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.sizer.Add(sbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(sbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, text=password: copy_to_clipboard(event, text), lambda event, mtext=password: copy_to_clipboard(mtext),
cbtn) cbtn)
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, path=passpath, text=text: self.save_to_pass( lambda event, path=passpath, mtext=text: self.save_to_pass(
event, path, text), path, mtext),
sbtn) sbtn)
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout() self.sizer.Layout()
def show_tools(self, event, index=None): def show_tools(self, index=None):
"""show_tools. """show_tools.
:param event:
:param index: :param index:
""" """
self.sizer.Clear(delete_windows=True) self.sizer.Clear(delete_windows=True)
@ -369,23 +360,22 @@ class PassUi(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind( self.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, index=index: self.back_button_clicked(event, index), lambda event, mindex=index: self.back_button_clicked(mindex),
btn) btn)
nbtn = wx.Button(self.pnl, label="Add new password") nbtn = wx.Button(self.pnl, label="Add new password")
font = nbtn.GetFont().MakeBold() font = nbtn.GetFont().MakeBold()
nbtn.SetFont(font) nbtn.SetFont(font)
self.sizer.Add(nbtn, 0, wx.EXPAND) # pylint: disable=no-member self.sizer.Add(nbtn, 0, wx.EXPAND) # pylint: disable=no-member
self.Bind(wx.EVT_BUTTON, lambda event: self.show_new_dialog(event), self.Bind(wx.EVT_BUTTON, lambda event: self.show_new_dialog(),
nbtn) nbtn)
self.add_push_pull() self.add_push_pull()
self.pnl.SetupScrolling() self.pnl.SetupScrolling()
self.sizer.Layout() self.sizer.Layout()
def copy_to_clipboard(event, text): def copy_to_clipboard(text):
"""copy_to_clipboard. """copy_to_clipboard.
:param event:
:param text: :param text:
""" """
password = text.split('\n')[0] password = text.split('\n')[0]
@ -405,20 +395,18 @@ def get_password_from_path(passpath):
return password return password
def pass_pull(event): def pass_pull():
"""pass_pull. """pass_pull.
:param event:
""" """
result = run_command(['/usr/bin/pass', 'git', 'pull']) run_command(['/usr/bin/pass', 'git', 'pull'])
def pass_push(event): def pass_push():
"""pass_push. """pass_push.
:param event:
""" """
result = run_command(['/usr/bin/pass', 'git', 'push']) run_command(['/usr/bin/pass', 'git', 'push'])
def run_command(command1, command2=None): def run_command(command1, command2=None):
@ -433,11 +421,11 @@ def run_command(command1, command2=None):
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
# If there is a second command it is taken to be a pipline # If there is a second command it is taken to be a pipline
if command2: if command2:
process2 = subprocess.Popen(command2, subprocess.Popen(command2,
shell=False, shell=False,
stdin=process1.stdout, stdin=process1.stdout,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
process1.stdout.close() process1.stdout.close()
return process1.communicate() return process1.communicate()

Loading…
Cancel
Save