From b3abe67b53b025af918bee297fa3727fb00664e5 Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 1 Oct 2023 20:31:55 +0200 Subject: [PATCH] Added class for the pass interaction. --- gtkpass.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/gtkpass.py b/gtkpass.py index f38eee7..3609e9a 100755 --- a/gtkpass.py +++ b/gtkpass.py @@ -10,9 +10,60 @@ from gi.repository import Gtk class GTKPass(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="GTKPass") + + self.passs = PassStore() + self.passs.gather_pass_tree() + def make_ui(self): self.show_all() +class PassStore: + """Password store GUI app""" + def __init__(self): + self.store_path = self._get_store_path() + self.data = Tree() + self.conf = {} + + def _get_store_path(self): + path = os.environ.get('$PASSWORD_STORE_DIR') + if path: + _check_pass_store(path) + return path + + path = os.path.expanduser('~/.password-store') + _check_pass_store(path) + return path + + def gather_pass_tree(self): + self._gather_pass_tree(self.data, self.store_path, '') + + def _gather_pass_tree(self, model, root, dirname): + fullpath = os.path.join(root, dirname) + ps_path = fullpath[len(self.store_path)+1:] + + root, dirs, files = next(os.walk(fullpath)) + for fname in files: + if (fname in ['.gitattributes', '.gpg-id'] or + not fname.lower().endswith('.gpg')): + continue + fname = fname[:-4] # chop off extension + model.children.append(Leaf(fname, os.path.join(ps_path, fname))) + + for dname in dirs: + if dname == '.git': + continue + t = Tree(dname, os.path.join(ps_path, dname)) + model.children.append(t) + self._gather_pass_tree(t, root, dname) + + + +def _check_pass_store(path): + if not os.path.exists(path) or not os.path.isdir(path): + raise IOError("Path for password store `%s' either doesn't exists or " + "is not a directory", path) + + def main(): app = GTKPass() app.connect("delete-event", Gtk.main_quit)