4
4
import logging
5
5
import errno
6
6
import constants
7
+ import pytablewriter
8
+ import re
7
9
8
10
print (constants .CURL_CHECK )
9
11
16
18
"pacman" : "$PACMAN" ,
17
19
"git" : "$GIT"
18
20
}
21
+ def update_readme (summary ):
22
+ writer = pytablewriter .MarkdownTableWriter ()
23
+ writer .headers = ["Tool" , "Apt" , "Yum" , "Packman" , "APK" , "DNF" , "CURL" , "URL" ]
24
+ value_matrix = []
25
+ for tool_shortname in summary :
26
+ tool = summary [tool_shortname ]
27
+ name = tool ['name' ]
28
+ installers = tool ['installers' ]
29
+ apt = "Yes" if "apt" in installers else "No"
30
+ yum = "Yes" if "yum" in installers else "No"
31
+ pacman = "Yes" if "pacman" in installers else "No"
32
+ apk = "Yes" if "apk" in installers else "No"
33
+ dnf = "Yes" if "dnf" in installers else "No"
34
+ curl = "Yes" if "curl" in installers else "No"
35
+ url = "https://installer.to/" + tool_shortname
36
+ value_matrix .append ([name , apt , yum , pacman , apk , dnf , curl , url ])
37
+ print (value_matrix )
38
+ writer .value_matrix = value_matrix
39
+ table_md = writer .dumps ()
40
+ try :
41
+ with open ("./README.md" , "r+" ) as readme_md :
42
+ readme = readme_md .read ()
43
+ beggining = "<!-- beginning of tools list -->"
44
+ end = "<!-- end of tools list -->"
45
+ regex = r"" + beggining + "\n (.*)\n " + end
46
+ readme = re .sub (regex , beggining + "\n " + table_md + "\n " + end , readme , flags = re .S )
47
+ readme_md .seek (0 ) # sets point at the beginning of the file
48
+ readme_md .truncate () # Clear previous content
49
+ readme_md .write (readme )
50
+ readme_md .close ()
51
+ except Error as e :
52
+ print (e )
53
+
54
+
55
+ def update_summary (name , shortname , description , installers ):
56
+ try :
57
+ with open ("./installers.toml" , "r+" ) as installer_summary :
58
+ summaary = installer_summary .read ()
59
+ print (summaary )
60
+ parsed_summary_toml = toml .loads (summaary )
61
+ print (parsed_summary_toml )
62
+ if shortname not in parsed_summary_toml :
63
+ parsed_summary_toml [shortname ] = {}
64
+ parsed_summary_toml [shortname ]['name' ] = name
65
+ parsed_summary_toml [shortname ]['name' ] = name
66
+ parsed_summary_toml [shortname ]['description' ] = description
67
+ parsed_summary_toml [shortname ]['installers' ] = "," .join (installers )
68
+ print (parsed_summary_toml )
69
+ installer_summary .seek (0 ) # sets point at the beginning of the file
70
+ installer_summary .truncate () # Clear previous content
71
+ installer_summary .write (toml .dumps (parsed_summary_toml ))
72
+ installer_summary .close ()
73
+
74
+ update_readme (parsed_summary_toml )
75
+ except IOError as e :
76
+ print ("Error" , e )
77
+ pass
19
78
20
79
def get_method_case (method ):
21
80
if method in methods :
@@ -34,7 +93,7 @@ def parse_line(line):
34
93
return line
35
94
36
95
def generate (path ):
37
-
96
+ installer_methods = [ ]
38
97
installer_toml_path = path + "/installer.toml"
39
98
installer_sh_path = path + "/installer.sh"
40
99
@@ -90,6 +149,11 @@ def generate(path):
90
149
seperator = "if"
91
150
92
151
for section in parsed_toml :
152
+ if not isinstance (parsed_toml [section ], dict ):
153
+ continue
154
+ if parsed_toml [section ]['sh' ] is "" :
155
+ continue
156
+ installer_methods .append (section )
93
157
lines = parsed_toml [section ]['sh' ]
94
158
installer_sh .write (seperator + " " + get_method_case (section ))
95
159
for line in lines .split ("\n " ):
@@ -105,6 +169,8 @@ def generate(path):
105
169
""" .strip ())
106
170
107
171
installer_sh .close ()
172
+ update_summary (parsed_toml ['name' ], parsed_toml ['shortname' ], parsed_toml ['description' ], installer_methods )
173
+ print ("installer_methods" ,installer_methods )
108
174
109
175
except IOError as x :
110
176
if x .errno == errno .EACCES :
0 commit comments