Skip to content

Commit 6c8b0d1

Browse files
committed
Linting/Formatting
1 parent 65a0df4 commit 6c8b0d1

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/qip_pass_export/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'''This file intentionally left blank.'''
1+
"""This file intentionally left blank."""

src/qip_pass_export/pass2csv.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#!/usr/bin/env python
2-
'''
2+
"""
33
pass2csv: Exports passwords from pass to CSV format
44
55
This software is distributed by qualIP Software under the GNU GENERAL PUBLIC
66
LICENSE v3 in the hope that others may find it useful too.
77
88
The original source and a copy of the GPLv3 license can be found here:
99
https://github.com/qualIP/qip-pass-export
10-
'''
10+
"""
1111

12-
# flake8: noqa: E501
13-
14-
from pathlib import Path
1512
import argparse
1613
import csv
1714
import io
1815
import os
1916
import re
2017
import sys
2118
import types
19+
from pathlib import Path
2220

2321
try:
2422
from ._version import __version__
@@ -28,88 +26,93 @@
2826

2927
def main():
3028
parser = argparse.ArgumentParser(
31-
prog='pass2csv',
32-
description='Exports passwords from pass to CSV format',
29+
prog="pass2csv",
30+
description="Exports passwords from pass to CSV format",
3331
)
34-
parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
35-
parser.add_argument('passfiles', metavar="passfile", nargs='+', type=Path, help='Password file(s) (*.gpg) to export')
32+
parser.add_argument("-V", "--version",
33+
action="version", version="%(prog)s " + __version__)
34+
parser.add_argument("passfiles",
35+
metavar="passfile", nargs=argparse.ONE_ORMORE, type=Path,
36+
help="Password file(s) (*.gpg) to export")
3637
args = parser.parse_args()
3738

3839
try:
3940
import gnupg
4041
except ImportError as err:
4142
print(err, file=sys.stderr)
42-
print('The python-gnupg module is required to run this software.', file=sys.stderr)
43+
print("The python-gnupg module is required to run this software.", file=sys.stderr)
4344
sys.exit(1)
4445
gpg = gnupg.GPG()
45-
gpg.encoding = 'utf-8'
46+
gpg.encoding = "utf-8"
4647

4748
# https://help.passbolt.com/faq/start/import-passwords
4849
# Using Csv (BitWarden) format
4950
csv_fields = (
50-
'description', # YES
51-
'folder', # YES
52-
'favorite', # no
53-
'type', # no
54-
'name', # YES
55-
'notes', # YES
56-
'fields', # no
57-
'reprompt', # no
58-
'login_uri', # YES
59-
'login_username', # YES
60-
'login_password', # YES
61-
'login_totp', # no
51+
"description",
52+
"folder",
53+
"favorite", # unused
54+
"type", # unused
55+
"name",
56+
"notes",
57+
"fields", # unused
58+
"reprompt", # unused
59+
"login_uri",
60+
"login_username",
61+
"login_password",
62+
"login_totp", # unused
6263
)
6364
csvwriter = csv.DictWriter(sys.stdout, fieldnames=csv_fields)
6465
csvwriter.writeheader()
6566

6667
for passfile in args.passfiles:
6768
relfile = passfile
6869
try:
69-
relfile = relfile.absolute().relative_to(Path.home() / '.password-store')
70+
relfile = relfile.absolute().relative_to(Path.home() / ".password-store")
7071
except ValueError:
7172
try:
7273
relfile = relfile.absolute().relative_to(Path.home())
7374
except ValueError:
7475
pass
75-
if passfile.suffix == '.gpg':
76-
with open(passfile, 'rb') as fp:
76+
if passfile.suffix == ".gpg":
77+
with open(passfile, "rb") as fp:
7778
indata = gpg.decrypt_file(fp)
7879
assert indata.ok
7980
indata = str(indata)
8081
indata = io.StringIO(indata)
81-
csvrow = types.SimpleNamespace(**{k: '' for k in csv_fields})
82+
csvrow = types.SimpleNamespace(**{k: "" for k in csv_fields})
8283
csvrow.notes = []
8384
for iline, line in enumerate(indata, start=1):
84-
line = line.rstrip('\r\n')
85+
line = line.rstrip("\r\n")
8586
if iline == 1:
8687
csvrow.login_password = line
8788
continue
88-
m = not csvrow.login_uri \
89-
and re.match(r'(?i)^(?:URL|URI)(?: *1)? *: *(?P<content>.*)$', line)
89+
m = not csvrow.login_uri and re.match(
90+
r"(?i)^(?:URL|URI)(?: *1)? *: *(?P<content>.*)$", line
91+
)
9092
if m:
91-
content = m.group('content').strip()
93+
content = m.group("content").strip()
9294
if content:
93-
if not re.match(r'(?i)^[a-z]+://', content):
94-
content = 'https://' + content
95+
if not re.match(r"(?i)^[a-z]+://", content):
96+
content = "https://" + content
9597
csvrow.login_uri = content
9698
continue
97-
m = not csvrow.login_username \
98-
and re.match(r'(?i)^(?:Login|Username) *: *(?P<content>.*)$', line)
99+
m = not csvrow.login_username and re.match(
100+
r"(?i)^(?:Login|Username) *: *(?P<content>.*)$", line
101+
)
99102
if m:
100-
content = m.group('content').strip()
103+
content = m.group("content").strip()
101104
if content:
102105
csvrow.login_username = content
103106
continue
104107
csvrow.notes.append(line)
105108
csvrow.name = relfile.stem
106109
csvrow.folder = os.fspath(relfile.parent)
107-
csvrow.notes = '\n'.join(csvrow.notes)
110+
csvrow.notes = "\n".join(csvrow.notes)
108111
csvwriter.writerow(csvrow.__dict__)
109112
csvrow = None
110113
else:
111114
raise NotImplementedError(os.fspath(passfile))
112115

113116

114-
if __name__ == '__main__':
117+
if __name__ == "__main__":
115118
main()

0 commit comments

Comments
 (0)