Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from sys import argv, exit, stdin
- from gtk import Clipboard
- from os import popen
- from pyme import core
- import getpass
- import re
- class Pillow:
- def __init__(self):
- self.tacks = list()
- def go(self, data):
- line = 1
- for i in data.split("\n"):
- if len(i) > 0 and i[0] != "#":
- reg = re.match("^([^\t]+)[\t]+([^\t]+)[\t]+(.+)$", i)
- if reg == None:
- print "Error while parsing line %d" % (line)
- else:
- t = Tack(reg.group(1), reg.group(2), reg.group(3))
- self.tacks.append(t)
- line += 1
- def filter(self, regex):
- result = list()
- for t in self.tacks:
- if t.match(regex):
- result.append(t)
- self.tacks = result
- def result(self):
- l = len(self.tacks)
- for i in self.tacks:
- print "MATCH %s" % (i)
- if l == 1:
- self._clipboard(i.password)
- break
- def _clipboard(self, to_store):
- popen('xclip', 'wb').write(to_store)
- print "Password copied to clipboard."
- class Tack:
- def __init__(self, title, user, password):
- self.title = title
- self.user = user
- self.password = password
- def __str__(self):
- return "%s (login: %s)" % (self.title, self.user)
- def match(self, regex):
- if re.search(regex, getattr(self, "title"), re.IGNORECASE) != None:
- return True
- return False
- @property
- def title():
- return self.title
- @property
- def user():
- return self.user
- @property
- def password():
- return self.password
- class GnuPG:
- def __init__(self):
- c = core.Context()
- c.set_passphrase_cb(self._password)
- c.set_armor(1)
- self.plain = core.Data()
- cipher = core.Data(file=argv[1])
- c.op_decrypt(cipher, self.plain)
- self.plain.seek(0, 0)
- def read(self):
- return self.plain.read()
- def _password(self, x, y, z, hook=None):
- p = getpass.getpass()
- return p
- def main():
- if len(argv) < 2:
- print "%s: [filename]"%(argv[0])
- exit(1)
- g = GnuPG()
- p = Pillow()
- p.go(g.read())
- for i in argv[2:]:
- p.filter(i)
- p.result()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement