forked from roddhjav/pass-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.updatedoc.py
executable file
·113 lines (85 loc) · 3.31 KB
/
.updatedoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# pass import - Password Store Extension (https://www.passwordstore.org/)
# Copyright (C) 2017-2019 Alexandre PUJOL <[email protected]>.
#
# This script will update the readme file in this repo.
import io
import pass_import
def replace(marker_begin, marker_end, string, newcontent):
"""Replace data inside string markers."""
begin = string.find(marker_begin)
end = string.find(marker_end)
return string.replace(string[begin + len(marker_begin):end], newcontent)
def rspace(string):
"""Remove space from url in markdown string."""
if '](' in string:
begin = string.find('](')
end = string.find(')')
url_space = string[begin + 2:end]
string = string.replace(url_space, url_space.replace(' ', ''))
return string
def rmarkdown(string):
"""Remove markdown link from a string."""
guide = '[guide]('
if guide in string:
string = string.replace(guide, 'guide: \\fI')
string = string.replace(')', '\\fP')
return string
def importers_nb():
"""Return a string of the importer len."""
return "%d" % len(pass_import.importers)
def importers_nb_line():
"""Return a line of the importer len."""
return "\n%d\n" % len(pass_import.importers)
def markdown_table():
"""Generate the new supported table."""
res = ('| **Password Manager** | **How to export Data** | **Command line** |\n' # noqa
'|:--------------------:|:----------------------:|:----------------:|\n') # noqa
for importer in sorted(pass_import.importers):
doc = pass_import.getdoc(importer)
export = rspace(doc['export'])
res += "| [%s](%s) | *%s* | `%s` |\n" % (importer, doc['url'],
export, doc['import'])
return "\n%s" % res
def importers_usage():
"""Generate the new supported table."""
res = ''
for importer in sorted(pass_import.importers):
doc = pass_import.getdoc(importer)
export = rmarkdown(rspace(doc['export']))
res += ("\n.TP\n\\fB%s\\fP\n"
"Website: \\fI%s\\fP\n\n" % (importer, doc['url']))
if 'extra' in doc:
res += "%s\n\n" % doc['extra']
res += ("Export: %s\n\n"
"Command: %s\n" % (export, doc['import']))
return "\n%s" % res
def helpmessage():
"""Generate the new pass-import usage."""
string = io.StringIO()
parser = pass_import.argumentsparse()
parser.print_help(string)
return "\n```\n%s\n```\n" % string.getvalue()
UPDATE = {
'README.md': [
('<!-- NB BEGIN -->', '<!-- NB END -->', importers_nb),
('<!-- SUPPORTED LIST BEGIN -->', '<!-- SUPPORTED LIST END -->',
markdown_table),
('<!-- USAGE BEGIN -->', '<!-- USAGE END -->', helpmessage)
],
'pass-import.1': [
(r'\# NB BEGIN', r'\# NB END', importers_nb_line),
(r'\# SUPPORTED LIST BEGIN', r'\# SUPPORTED LIST END', importers_usage)
],
}
def main():
"""Update the documentation files last usage and importer list."""
for path, pattern in UPDATE.items():
with open(path, 'r') as file:
data = file.read()
for item in pattern:
data = replace(item[0], item[1], data, item[2]())
with open(path, 'w') as file:
file.write(data)
if __name__ == "__main__":
main()