mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-14 00:34:03 +00:00
3eb93acc18
This commit re-organizes all the source distribution contents to present users with the simple script, while moving the rest in extras. Also autoconf/automake scripts were removed, back to minimalism. The rationale of this change is that Tomb really only consists of a script and users with no extra needs should just be presented with it with no need for anything else. Any other thing on top of the Tomb script is an extra and can be even distributed separately or integrated in distributions.
80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
import subprocess
|
|
from tempfile import NamedTemporaryFile
|
|
|
|
import parser
|
|
|
|
class Undertaker(object):
|
|
'''
|
|
This is similar to Tomb class, and provides a wrapper on undertaker.
|
|
|
|
TODO:
|
|
* methods for automagical scan
|
|
* output parsing, giving meaningful output
|
|
|
|
Due to the non-interactive nature of undertaker, it's simpler than Tomb
|
|
'''
|
|
undertakerexec = 'undertaker'
|
|
@classmethod
|
|
def check(cls, paths):
|
|
'''Will check if there are keys available there, as in --path
|
|
|
|
paths can be a string (one address), or a list of
|
|
'''
|
|
#TODO: more solid check: something like
|
|
if type(paths) is not str:
|
|
out = []
|
|
for p in paths:
|
|
try:
|
|
res = cls.check(p)
|
|
except:
|
|
continue
|
|
else:
|
|
if res:
|
|
out.extend(res)
|
|
return out
|
|
|
|
buf = NamedTemporaryFile()
|
|
try:
|
|
subprocess.check_call([cls.undertakerexec, paths, '--batch',
|
|
'--path'], stderr=buf)
|
|
except subprocess.CalledProcessError as exc:
|
|
return False
|
|
|
|
out = []
|
|
buf.seek(0)
|
|
for line in buf:
|
|
ret = parser.parse_line(line)
|
|
if ret and ret['type'] == 'found':
|
|
out.append(ret['content'])
|
|
return out
|
|
|
|
|
|
@classmethod
|
|
def get(cls, paths):
|
|
'''
|
|
Similar to check, but truly get the key content.
|
|
If paths is iterable, stop at the first successful path
|
|
'''
|
|
if type(paths) is not str:
|
|
for p in paths:
|
|
try:
|
|
res = cls.get(p)
|
|
except:
|
|
continue
|
|
else:
|
|
if res:
|
|
return res
|
|
buf = NamedTemporaryFile()
|
|
try:
|
|
subprocess.check_call([cls.undertakerexec, paths, '--batch'],
|
|
stdout=buf)
|
|
except subprocess.CalledProcessError:
|
|
return False
|
|
buf.seek(0)
|
|
return buf.read()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
Undertaker.undertakerexec = '/home/davide/coding/projects/tomb/src/undertaker'
|
|
print Undertaker.get('near:///home/davide/Desktop/testing.tomb')
|