#!/usr/bin/env python3# Copyright (C) 2017 Sam Mason <sam@samason.uk>. All Rights Reserved.# This file is licensed under the GPLv2+. Please see COPYING for more information.importsysimportsubprocessimportpandasaspd# assumes STDIN is generated via File=>Export from the Mac version of# pwsafe, available from https://pwsafe.info/df=pd.read_table(sys.stdin)df.sort_values(['Group/Title','Username'],inplace=True)tr={ord('.'):'/',ord('»'):'.'}fori,rowindf.iterrows():na=row.notnull()path='pwsafe/{}'.format(row['Group/Title'].strip().translate(tr))value='{}\n'.format(row['Password'])ifna['Username']:path='{}/{}'.format(path,row['Username'].strip())ifna['e-mail']:value='email: {}\n'.format(value,row['e-mail'].strip())ifna['Notes']:value='\n{}\n'.format(value,row['Notes'].strip())withsubprocess.Popen(['pass','add','-m',path],stdin=subprocess.PIPE)asproc:proc.communicate(value.encode('utf8'))ifproc.returncode:print('failure with {}, returned {}'.format(path,proc.returncode))