Added delete method.
This probably will be reiterate later, as password store need to be updated as well (i.e. removing changes need to be committed in git).
This commit is contained in:
29
gtkpass.py
29
gtkpass.py
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
@@ -426,6 +427,10 @@ class Tree:
|
|||||||
|
|
||||||
class PassStore:
|
class PassStore:
|
||||||
"""Password store GUI app"""
|
"""Password store GUI app"""
|
||||||
|
NON_EMPTY = 1
|
||||||
|
SUCCESS = 0
|
||||||
|
ERROR = 2
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.store_path = self._get_store_path()
|
self.store_path = self._get_store_path()
|
||||||
self.data = Tree()
|
self.data = Tree()
|
||||||
@@ -461,6 +466,30 @@ class PassStore:
|
|||||||
except IOError as exc:
|
except IOError as exc:
|
||||||
return False, str(exc)
|
return False, str(exc)
|
||||||
|
|
||||||
|
def delete(self, item, recursively=False):
|
||||||
|
path = os.path.join(self.store_path, item)
|
||||||
|
|
||||||
|
if os.path.exists(path) and os.path.isdir(path) and recursively:
|
||||||
|
try:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
except IOError as exc:
|
||||||
|
return self.ERROR, str(exc)
|
||||||
|
elif os.path.exists(path) and os.path.isdir(path):
|
||||||
|
_, files, dirs = next(os.walk(path))
|
||||||
|
if files or dirs:
|
||||||
|
return self.NON_EMPTY, ""
|
||||||
|
try:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
except IOError as exc:
|
||||||
|
return self.ERROR, str(exc)
|
||||||
|
elif not os.path.exists and os.path.isfile(path + '.gpg'):
|
||||||
|
try:
|
||||||
|
os.unlink(path + '.gpg')
|
||||||
|
except IOError as exc:
|
||||||
|
return self.ERROR, str(exc)
|
||||||
|
|
||||||
|
return self.SUCCESS, ''
|
||||||
|
|
||||||
def _gather_pass_tree(self, model, root, dirname):
|
def _gather_pass_tree(self, model, root, dirname):
|
||||||
fullpath = os.path.join(root, dirname)
|
fullpath = os.path.join(root, dirname)
|
||||||
ps_path = fullpath[len(self.store_path)+1:]
|
ps_path = fullpath[len(self.store_path)+1:]
|
||||||
|
|||||||
Reference in New Issue
Block a user