Coverage for pass_import/managers/buttercup.py: 100%
25 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
1# -*- encoding: utf-8 -*-
2# pass import - Passwords importer swiss army knife
3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>.
4#
6from pass_import.core import register_managers
7from pass_import.formats.csv import CSV
10class Buttercup(CSV):
11 """Importer for Buttercup in CSV format."""
12 name = 'buttercup'
13 url = 'https://buttercup.pw'
14 hexport = 'File > Export > Export File to CSV'
15 himport = 'pass import buttercup file.csv'
16 ignore = {'!type', '!group_name', '!group_parent', 'id'}
17 keys = {
18 'title': 'title',
19 'password': 'password',
20 'login': 'username',
21 'url': 'URL',
22 'comments': 'Notes',
23 'group': '!group_id'
24 }
26 def parse(self):
27 """Parse Buttercup CSV file."""
28 super().parse()
30 # Get group structure
31 folders = {}
32 groups = []
33 for entry in self.data:
34 if entry.get('!type', '') == 'group':
35 key = entry.get('group', '0')
36 folders[key] = {
37 'group': entry.get('!group_name', ''),
38 'parent': entry.get('!group_parent', '0')
39 }
40 groups.append(entry)
41 self._sortgroup(folders)
43 # Remove groups declaration from ``data``
44 for entry in groups:
45 self.data.remove(entry)
47 # Remove ignored key from entries
48 for entry in self.data:
49 for key in self.ignore:
50 entry.pop(key, None)
53register_managers(Buttercup)