3
3
import os
4
4
import logging
5
5
import errno
6
+ import pytablewriter
7
+ import re
6
8
7
9
methods = {
8
10
"curl" : "$CURL" ,
13
15
"pacman" : "$PACMAN" ,
14
16
"git" : "$GIT"
15
17
}
18
+ def update_readme (summary ):
19
+ writer = pytablewriter .MarkdownTableWriter ()
20
+ writer .headers = ["Tool" , "Apt" , "Yum" , "Packman" , "APK" , "DNF" , "CURL" , "URL" ]
21
+ value_matrix = []
22
+ for tool_shortname in summary :
23
+ tool = summary [tool_shortname ]
24
+ name = tool ['name' ]
25
+ installers = tool ['installers' ]
26
+ apt = "Yes" if "apt" in installers else "No"
27
+ yum = "Yes" if "yum" in installers else "No"
28
+ pacman = "Yes" if "pacman" in installers else "No"
29
+ apk = "Yes" if "apk" in installers else "No"
30
+ dnf = "Yes" if "dnf" in installers else "No"
31
+ curl = "Yes" if "curl" in installers else "No"
32
+ url = "https://installer.to/" + tool_shortname
33
+ value_matrix .append ([name , apt , yum , pacman , apk , dnf , curl , url ])
34
+ print (value_matrix )
35
+ writer .value_matrix = value_matrix
36
+ table_md = writer .dumps ()
37
+ try :
38
+ with open ("./README.md" , "r+" ) as readme_md :
39
+ readme = readme_md .read ()
40
+ beggining = "<!-- beginning of tools list -->"
41
+ end = "<!-- end of tools list -->"
42
+ regex = r"" + beggining + "\n (.*)\n " + end
43
+ readme = re .sub (regex , beggining + "\n " + table_md + "\n " + end , readme , flags = re .S )
44
+ readme_md .seek (0 ) # sets point at the beginning of the file
45
+ readme_md .truncate () # Clear previous content
46
+ readme_md .write (readme )
47
+ readme_md .close ()
48
+ except Error as e :
49
+ print (e )
50
+
51
+
52
+ def update_summary (name , shortname , description , installers ):
53
+ try :
54
+ with open ("./installers.toml" , "r+" ) as installer_summary :
55
+ summaary = installer_summary .read ()
56
+ print (summaary )
57
+ parsed_summary_toml = toml .loads (summaary )
58
+ print (parsed_summary_toml )
59
+ if shortname not in parsed_summary_toml :
60
+ parsed_summary_toml [shortname ] = {}
61
+ parsed_summary_toml [shortname ]['name' ] = name
62
+ parsed_summary_toml [shortname ]['name' ] = name
63
+ parsed_summary_toml [shortname ]['description' ] = description
64
+ parsed_summary_toml [shortname ]['installers' ] = "," .join (installers )
65
+ print (parsed_summary_toml )
66
+ installer_summary .seek (0 ) # sets point at the beginning of the file
67
+ installer_summary .truncate () # Clear previous content
68
+ installer_summary .write (toml .dumps (parsed_summary_toml ))
69
+ installer_summary .close ()
70
+
71
+ update_readme (parsed_summary_toml )
72
+ except IOError as e :
73
+ print ("Error" , e )
74
+ pass
16
75
17
76
def get_method_case (method ):
18
77
if method in methods :
@@ -22,11 +81,16 @@ def get_method_case(method):
22
81
exit (1 )
23
82
24
83
def parse_line (line ):
25
- line = line .replace ('@sudo' , '$SUDO' )
84
+ line = line \
85
+ .replace ('@sudo' , '$SUDO' )\
86
+ .replace ('@log' , 'info' )\
87
+ .replace ('@info' , 'info' )\
88
+ .replace ('@warn' , 'warn' )\
89
+ .replace ('@error' , 'error' )
26
90
return line
27
91
28
92
def generate (path ):
29
-
93
+ installer_methods = [ ]
30
94
installer_toml_path = path + "/installer.toml"
31
95
installer_sh_path = path + "/installer.sh"
32
96
@@ -37,14 +101,14 @@ def generate(path):
37
101
38
102
installer_sh .write ("""#!/bin/sh
39
103
40
- CURL_CMD=$(which curl) # curl tool
41
- YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
42
- DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
43
- APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
44
- PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
45
- APK_CMD=$(which apk) # apk package manager for Alpine
46
- GIT_CMD=$(which git) # to build from source pulling from git
47
- SUDO_CMD=$(which sudo) # check if sudo command is there
104
+ CURL_CMD=$(which curl)
105
+ YUM_CMD=$(which yum)
106
+ DNF_CMD=$(which dnf)
107
+ APT_GET_CMD=$(which apt-get)
108
+ PACMAN_CMD=$(which pacman)
109
+ APK_CMD=$(which apk)
110
+ GIT_CMD=$(which git)
111
+ SUDO_CMD=$(which sudo)
48
112
49
113
USER="$(id -un 2>/dev/null || true)"
50
114
SUDO=''
@@ -60,11 +124,33 @@ def generate(path):
60
124
fi
61
125
fi
62
126
127
+ RESET='\033 [0m'
128
+ RED='\033 [0;31m'
129
+ GREEN='\033 [0;32m'
130
+ YELLOW='\033 [0;33m'
131
+ log () {
132
+ echo "[`date "+%Y.%m.%d-%H:%M:%S%Z"`]$1 $2"
133
+ }
134
+ info () {
135
+ log "$GREEN INFO$RESET $1"
136
+ }
137
+ warn () {
138
+ log "$YELLOW WARN$RESET $1"
139
+ }
140
+ error () {
141
+ log "$RED ERROR$RESET $1"
142
+ }
143
+
63
144
""" )
64
145
65
146
seperator = "if"
66
147
67
148
for section in parsed_toml :
149
+ if not isinstance (parsed_toml [section ], dict ):
150
+ continue
151
+ if parsed_toml [section ]['sh' ] is "" :
152
+ continue
153
+ installer_methods .append (section )
68
154
lines = parsed_toml [section ]['sh' ]
69
155
installer_sh .write (seperator + " " + get_method_case (section ))
70
156
for line in lines .split ("\n " ):
@@ -80,6 +166,8 @@ def generate(path):
80
166
""" .strip ())
81
167
82
168
installer_sh .close ()
169
+ update_summary (parsed_toml ['name' ], parsed_toml ['shortname' ], parsed_toml ['description' ], installer_methods )
170
+ print ("installer_methods" ,installer_methods )
83
171
84
172
except IOError as x :
85
173
if x .errno == errno .EACCES :
0 commit comments