password-store

Simple password manager using gpg and ordinary unix directories
git clone https://git.zx2c4.com/password-store
Log | Files | Refs | README | LICENSE

pwsafe2pass.py (1158B)


      1 #!/usr/bin/env python3
      2 
      3 # Copyright (C) 2017 Sam Mason <sam@samason.uk>. All Rights Reserved.
      4 # This file is licensed under the GPLv2+. Please see COPYING for more information.
      5 
      6 import sys
      7 import subprocess
      8 
      9 import pandas as pd
     10 
     11 # assumes STDIN is generated via File=>Export from the Mac version of
     12 # pwsafe, available from https://pwsafe.info/
     13 df = pd.read_table(sys.stdin)
     14 df.sort_values(['Group/Title','Username'], inplace=True)
     15 
     16 tr = {
     17     ord('.'): '/',
     18     ord('ยป'): '.'
     19 }
     20 
     21 for i,row in df.iterrows():
     22     na = row.notnull()
     23 
     24     path = 'pwsafe/{}'.format(row['Group/Title'].strip().translate(tr))
     25     value = '{}\n'.format(row['Password'])
     26 
     27     if na['Username']:
     28         path = '{}/{}'.format(path,row['Username'].strip())
     29 
     30     if na['e-mail']:
     31         value = 'email: {}\n'.format(value,row['e-mail'].strip())
     32 
     33     if na['Notes']:
     34         value = '\n{}\n'.format(value, row['Notes'].strip())
     35 
     36     with subprocess.Popen(['pass','add','-m',path],stdin=subprocess.PIPE) as proc:
     37         proc.communicate(value.encode('utf8'))
     38         if proc.returncode:
     39             print('failure with {}, returned {}'.format(
     40                 path, proc.returncode))