|
@@ -83,16 +83,14 @@ def apply_opt(name, val, conf=None):
|
83
|
83
|
|
84
|
84
|
# Fetch configuration files from GitHub given the path.
|
85
|
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
|
95
|
# Find a suitable fetch command
|
98
|
96
|
if shutil.which("curl") is not None:
|
|
@@ -108,16 +106,14 @@ def fetch_example(path):
|
108
|
106
|
# Reset configurations to default
|
109
|
107
|
os.system("git reset --hard HEAD")
|
110
|
108
|
|
111
|
|
- gotfile = False
|
112
|
|
-
|
113
|
109
|
# Try to fetch the remote files
|
|
110
|
+ gotfile = False
|
114
|
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
|
113
|
shutil.move('wgot', config_path(fn))
|
117
|
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
|
118
|
return gotfile
|
123
|
119
|
|
|
@@ -144,13 +140,13 @@ def apply_all_sections(cp):
|
144
|
140
|
apply_ini_by_name(cp, sect)
|
145
|
141
|
|
146
|
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
|
145
|
if ckey == 'all':
|
150
|
146
|
apply_all_sections(cp)
|
151
|
147
|
else:
|
152
|
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
|
150
|
apply_ini_by_name(cp, 'config:base')
|
155
|
151
|
|
156
|
152
|
# Apply historically 'Configuration.h' settings everywhere
|
|
@@ -175,7 +171,7 @@ def apply_config_ini(cp):
|
175
|
171
|
config_keys = ['base']
|
176
|
172
|
for ikey, ival in base_items:
|
177
|
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
|
176
|
# For each ini_use_config item perform an action
|
181
|
177
|
for ckey in config_keys:
|
|
@@ -196,11 +192,11 @@ def apply_config_ini(cp):
|
196
|
192
|
# For 'examples/<path>' fetch an example set from GitHub.
|
197
|
193
|
# For https?:// do a direct fetch of the URL.
|
198
|
194
|
elif ckey.startswith('examples/') or ckey.startswith('http'):
|
199
|
|
- addbase = True
|
200
|
195
|
fetch_example(ckey)
|
|
196
|
+ ckey = 'base'
|
201
|
197
|
|
202
|
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
|
201
|
if __name__ == "__main__":
|
206
|
202
|
#
|