[modules/vault] Update to new API
This commit is contained in:
parent
464a165c8b
commit
4b402438cc
2 changed files with 40 additions and 38 deletions
|
@ -20,11 +20,14 @@ Parameters:
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import bumblebee.util
|
|
||||||
import bumblebee.popup_v2
|
import core.module
|
||||||
import bumblebee.input
|
import core.widget
|
||||||
import bumblebee.output
|
import core.input
|
||||||
import bumblebee.engine
|
import core.event
|
||||||
|
|
||||||
|
import util.cli
|
||||||
|
import util.popup
|
||||||
|
|
||||||
def build_menu(parent, current_directory, callback):
|
def build_menu(parent, current_directory, callback):
|
||||||
with os.scandir(current_directory) as it:
|
with os.scandir(current_directory) as it:
|
||||||
|
@ -35,47 +38,46 @@ def build_menu(parent, current_directory, callback):
|
||||||
parent.add_menuitem(name, callback=lambda : callback(os.path.join(current_directory, name)))
|
parent.add_menuitem(name, callback=lambda : callback(os.path.join(current_directory, name)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
submenu = bumblebee.popup_v2.PopupMenu(parent, leave=False)
|
submenu = util.popup.menu(parent, leave=False)
|
||||||
build_menu(submenu, os.path.join(current_directory, entry.name), callback)
|
build_menu(submenu, os.path.join(current_directory, entry.name), callback)
|
||||||
parent.add_cascade(entry.name, submenu)
|
parent.add_cascade(entry.name, submenu)
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config):
|
||||||
super(Module, self).__init__(engine, config,
|
super().__init__(config, core.widget.Widget(self.text))
|
||||||
bumblebee.output.Widget(full_text=self.text)
|
|
||||||
)
|
self.__duration = int(self.parameter('duration', 30))
|
||||||
self._duration = int(self.parameter('duration', 30))
|
self.__offx = int(self.parameter('offx', 0))
|
||||||
self._offx = int(self.parameter('offx', 0))
|
self.__offy = int(self.parameter('offy', 0))
|
||||||
self._offy = int(self.parameter('offy', 0))
|
self.__path = os.path.expanduser(self.parameter('location', '~/.password-store/'))
|
||||||
self._path = os.path.expanduser(self.parameter('location', '~/.password-store/'))
|
self.__reset()
|
||||||
self._reset()
|
core.input.register(self, button=core.input.LEFT_MOUSE,
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
||||||
cmd=self.popup)
|
cmd=self.popup)
|
||||||
|
|
||||||
def popup(self, widget):
|
def popup(self, widget):
|
||||||
menu = bumblebee.popup_v2.PopupMenu(leave=False)
|
menu = util.popup.menu(leave=False)
|
||||||
|
|
||||||
build_menu(menu, self._path, self._callback)
|
build_menu(menu, self.__path, self.__callback)
|
||||||
menu.show(widget, offset_x=self._offx, offset_y=self._offy)
|
menu.show(widget, offset_x=self.__offx, offset_y=self.__offy)
|
||||||
|
|
||||||
def _reset(self):
|
def __reset(self):
|
||||||
self._timer = None
|
self.__timer = None
|
||||||
self._text = str(self.parameter('text', '<click-for-password>'))
|
self.__text = str(self.parameter('text', '<click-for-password>'))
|
||||||
|
|
||||||
def _callback(self, secret_name):
|
def __callback(self, secret_name):
|
||||||
secret_name = secret_name.replace(self._path, '') # remove common path
|
secret_name = secret_name.replace(self.__path, '') # remove common path
|
||||||
if self._timer:
|
if self.__timer:
|
||||||
self._timer.cancel()
|
self.__timer.cancel()
|
||||||
# bumblebee.util.execute hangs for some reason
|
res = util.cli.execute('pass -c {}'.format(secret_name), wait=False,
|
||||||
os.system('PASSWORD_STORE_CLIP_TIME={} pass -c {} > /dev/null 2>&1'.format(self._duration, secret_name))
|
env={ 'PASSWORD_STORE_CLIP_TIME': self.__duration })
|
||||||
self._timer = threading.Timer(self._duration, self._reset)
|
self.__timer = threading.Timer(self.__duration, self.__reset)
|
||||||
self._timer.start()
|
self.__timer.start()
|
||||||
self._start = int(time.time())
|
self.__start = int(time.time())
|
||||||
self._text = secret_name
|
self.__text = secret_name
|
||||||
|
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
if self._timer:
|
if self.__timer:
|
||||||
return '{} ({}s)'.format(self._text, self._duration - (int(time.time()) - self._start))
|
return '{} ({}s)'.format(self.__text, self.__duration - (int(time.time()) - self.__start))
|
||||||
return self._text
|
return self.__text
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -3,11 +3,11 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def execute(cmd, wait=True, ignore_errors=False):
|
def execute(cmd, wait=True, ignore_errors=False, env=None):
|
||||||
args = shlex.split(cmd)
|
args = shlex.split(cmd)
|
||||||
logging.debug(cmd)
|
logging.debug(cmd)
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
raise RuntimeError('{} not found'.format(cmd))
|
raise RuntimeError('{} not found'.format(cmd))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue