Browse Source

🔨 Misc. config py updates

Scott Lahteine 2 years ago
parent
commit
b8bd331efd
1 changed files with 17 additions and 21 deletions
  1. 17
    21
      buildroot/share/PlatformIO/scripts/configuration.py

+ 17
- 21
buildroot/share/PlatformIO/scripts/configuration.py View File

83
 
83
 
84
 # Fetch configuration files from GitHub given the path.
84
 # Fetch configuration files from GitHub given the path.
85
 # Return True if any files were fetched.
85
 # Return True if any files were fetched.
86
-def fetch_example(path):
87
-	if path.endswith("/"):
88
-		path = path[:-1]
89
-
90
-	if '@' in path:
91
-		path, brch = map(strip, path.split('@'))
92
-
93
-	url = path.replace("%", "%25").replace(" ", "%20")
94
-	if not path.startswith('http'):
95
-		url = "https://raw.githubusercontent.com/MarlinFirmware/Configurations/bugfix-2.1.x/config/%s" % url
86
+def fetch_example(url):
87
+	if url.endswith("/"): url = url[:-1]
88
+	if url.startswith('http'):
89
+		url = url.replace("%", "%25").replace(" ", "%20")
90
+	else:
91
+		brch = "bugfix-2.1.x"
92
+		if '@' in path: path, brch = map(str.strip, path.split('@'))
93
+		url = f"https://raw.githubusercontent.com/MarlinFirmware/Configurations/{brch}/config/{url}"
96
 
94
 
97
 	# Find a suitable fetch command
95
 	# Find a suitable fetch command
98
 	if shutil.which("curl") is not None:
96
 	if shutil.which("curl") is not None:
108
 	# Reset configurations to default
106
 	# Reset configurations to default
109
 	os.system("git reset --hard HEAD")
107
 	os.system("git reset --hard HEAD")
110
 
108
 
111
-	gotfile = False
112
-
113
 	# Try to fetch the remote files
109
 	# Try to fetch the remote files
110
+	gotfile = False
114
 	for fn in ("Configuration.h", "Configuration_adv.h", "_Bootscreen.h", "_Statusscreen.h"):
111
 	for fn in ("Configuration.h", "Configuration_adv.h", "_Bootscreen.h", "_Statusscreen.h"):
115
-		if os.system("%s wgot %s/%s >/dev/null 2>&1" % (fetch, url, fn)) == 0:
112
+		if os.system(f"{fetch} wgot {url}/{fn} >/dev/null 2>&1") == 0:
116
 			shutil.move('wgot', config_path(fn))
113
 			shutil.move('wgot', config_path(fn))
117
 			gotfile = True
114
 			gotfile = True
118
 
115
 
119
-	if Path('wgot').exists():
120
-		shutil.rmtree('wgot')
116
+	if Path('wgot').exists(): shutil.rmtree('wgot')
121
 
117
 
122
 	return gotfile
118
 	return gotfile
123
 
119
 
144
 			apply_ini_by_name(cp, sect)
140
 			apply_ini_by_name(cp, sect)
145
 
141
 
146
 # Apply certain config sections from a parsed file
142
 # Apply certain config sections from a parsed file
147
-def apply_sections(cp, ckey='all', addbase=False):
148
-	blab("[config] apply section key: %s" % ckey)
143
+def apply_sections(cp, ckey='all'):
144
+	blab(f"Apply section key: {ckey}")
149
 	if ckey == 'all':
145
 	if ckey == 'all':
150
 		apply_all_sections(cp)
146
 		apply_all_sections(cp)
151
 	else:
147
 	else:
152
 		# Apply the base/root config.ini settings after external files are done
148
 		# Apply the base/root config.ini settings after external files are done
153
-		if addbase or ckey in ('base', 'root'):
149
+		if ckey in ('base', 'root'):
154
 			apply_ini_by_name(cp, 'config:base')
150
 			apply_ini_by_name(cp, 'config:base')
155
 
151
 
156
 		# Apply historically 'Configuration.h' settings everywhere
152
 		# Apply historically 'Configuration.h' settings everywhere
175
 	config_keys = ['base']
171
 	config_keys = ['base']
176
 	for ikey, ival in base_items:
172
 	for ikey, ival in base_items:
177
 		if ikey == 'ini_use_config':
173
 		if ikey == 'ini_use_config':
178
-			config_keys = [ x.strip() for x in ival.split(',') ]
174
+			config_keys = map(str.strip, ival.split(','))
179
 
175
 
180
 	# For each ini_use_config item perform an action
176
 	# For each ini_use_config item perform an action
181
 	for ckey in config_keys:
177
 	for ckey in config_keys:
196
 		# For 'examples/<path>' fetch an example set from GitHub.
192
 		# For 'examples/<path>' fetch an example set from GitHub.
197
 		# For https?:// do a direct fetch of the URL.
193
 		# For https?:// do a direct fetch of the URL.
198
 		elif ckey.startswith('examples/') or ckey.startswith('http'):
194
 		elif ckey.startswith('examples/') or ckey.startswith('http'):
199
-			addbase = True
200
 			fetch_example(ckey)
195
 			fetch_example(ckey)
196
+			ckey = 'base'
201
 
197
 
202
 		# Apply keyed sections after external files are done
198
 		# Apply keyed sections after external files are done
203
-		apply_sections(cp, 'config:' + ckey, addbase)
199
+		apply_sections(cp, 'config:' + ckey)
204
 
200
 
205
 if __name__ == "__main__":
201
 if __name__ == "__main__":
206
 	#
202
 	#

Loading…
Cancel
Save