[pass] [PATCH] Add passpack import script.
Frankie Robertson
frankie at robertson.name
Sun Jun 7 17:15:51 CEST 2015
---
contrib/importers/passpack2pass.py | 57 ++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100755 contrib/importers/passpack2pass.py
diff --git a/contrib/importers/passpack2pass.py b/contrib/importers/passpack2pass.py
new file mode 100755
index 0000000..b829f3d
--- /dev/null
+++ b/contrib/importers/passpack2pass.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015 Frankie Robertson <frankie at robertson.name>.
+# This file is licensed under the GPLv2+. Please see COPYING for more
+# information.
+
+import sys
+import csv
+import subprocess
+
+
+def insert(d):
+ name = d.pop('path').replace('/', '_')
+ content = d.pop('password') + "\n"
+ for k, v in d.items():
+ content += "%s: %s\n" % (k, v)
+ cmd = ["pass", "insert", "--force", "--multiline", name]
+ process = subprocess.Popen(
+ cmd,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = process.communicate(content.encode('utf-8'))
+ retcode = process.wait()
+ if retcode:
+ print('command "{}" failed with exit code {}: {}'.format(
+ " ".join(cmd), retcode, stdout + stderr))
+ return 1
+
+
+def main(filename):
+ reader = csv.reader(open(filename))
+ for line in reader:
+ d = {}
+ if line[0]:
+ d['path'] = line[0]
+ if line[1]:
+ d['user id'] = line[1]
+ if line[2]:
+ d['password'] = line[2]
+ if line[3]:
+ d['url'] = line[3]
+ if line[4]:
+ d['email'] = line[4]
+ if line[5]:
+ d['comment'] = line[5]
+ if line[6]:
+ d['tags'] = line[6]
+ insert(d)
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print("Usage: {} <passpack csv export file>".format(sys.argv[0]))
+ else:
+ sys.exit(main(sys.argv[1]) or 0)
--
2.1.4
More information about the Password-Store
mailing list