24
24
}
25
25
26
26
# Current supported types on the new infrastructure
27
- types = [
28
- "openttd-nightlies" ,
29
- "openttd-releases" ,
30
- ]
31
- types_grouped_by_branch = [
32
- "openttd-pullrequests" ,
33
- ]
27
+ types = {
28
+ "openttd-nightlies" : "flatten" ,
29
+ "openttd-releases" : "stable-testing" ,
30
+ "openttd-pullrequests" : "name" ,
31
+ }
34
32
35
33
36
34
async def download (url ):
@@ -103,15 +101,6 @@ async def get_old_versions_of_folder(folder):
103
101
return versions
104
102
105
103
106
- async def get_latest (folder ):
107
- # We use the non-CDN URL here, as we want the latest; not any edge-cached version
108
- latest = await download (f"https://openttd.ams3.digitaloceanspaces.com/{ folder } /latest.txt" )
109
- latest = latest .decode ()
110
-
111
- version , _ , date = latest .partition ("," )
112
- return version
113
-
114
-
115
104
async def get_listing (folder ):
116
105
# We use the non-CDN URL here, as we want the latest; not any edge-cached version
117
106
listing = await download (f"https://openttd.ams3.digitaloceanspaces.com/{ folder } /listing.txt" )
@@ -121,8 +110,8 @@ async def get_listing(folder):
121
110
if not entry :
122
111
continue
123
112
124
- version , _ , date = entry .partition ("," )
125
- versions [version ] = date
113
+ version , date , name = entry .split ("," , 3 )
114
+ versions [version ] = ( date , name )
126
115
127
116
return versions
128
117
@@ -146,8 +135,9 @@ async def write_to_collection(type, version, manifest):
146
135
f .write ("---\n " .encode ())
147
136
148
137
149
- async def handle_version (folder , type , version , host , on_old_infrastructure = "false" , latest = None ):
150
- print (f"Adding { type } /{ version } to downloads collection .." )
138
+ async def handle_version (folder , dest_folder , version , host , on_old_infrastructure = "false" ,
139
+ latest = None , latest_filenames = None ):
140
+ print (f"Adding { dest_folder } /{ version } to downloads collection .." )
151
141
manifest = await fetch_manifest (folder , version , host , on_old_infrastructure = on_old_infrastructure )
152
142
153
143
# Insert the version into the header; otherwise we don't know
@@ -156,11 +146,15 @@ async def handle_version(folder, type, version, host, on_old_infrastructure="fal
156
146
manifest .insert (1 , f"version: { version } " )
157
147
manifest = "\n " .join (manifest )
158
148
159
- await write_to_collection (type , version , manifest )
149
+ await write_to_collection (dest_folder , version , manifest )
160
150
161
151
# If this is the current version, also copy the content to "latest"
162
152
if version == latest :
163
- await write_to_collection (type , "latest" , manifest )
153
+ if latest_filenames is None :
154
+ latest_filenames = ["latest" ]
155
+
156
+ for latest_filename in latest_filenames :
157
+ await write_to_collection (dest_folder , latest_filename , manifest )
164
158
165
159
166
160
async def main ():
@@ -191,41 +185,56 @@ async def main():
191
185
latest = latest )
192
186
193
187
# Support for new infrastructure; those are hosted on the DigitalOcean CDN (Spaces)
194
- for type in types :
195
- latest = await get_latest (type )
196
- versions = await get_listing (type )
197
- for version , data in versions .items ():
198
- os .makedirs (f"_downloads/{ type } " , exist_ok = True )
199
- await handle_version (
200
- type ,
201
- type ,
202
- version ,
203
- "https://proxy.binaries.openttd.org" ,
204
- latest = latest )
205
-
206
- for type in types_grouped_by_branch :
188
+ for type , method in types .items ():
207
189
version_grouped = defaultdict (list )
208
- latest_grouped = defaultdict (str )
190
+ latest_grouped = defaultdict (lambda : [ "" , "" ] )
209
191
versions = await get_listing (type )
210
192
211
- # Regroup the versions based on the branch (which is the second part in the name)
193
+ # Regroup the versions based on the method
212
194
for version , data in versions .items ():
213
- (date , branch , tag ) = version .split ("-" , 3 )
195
+ (date , name ) = data
196
+
197
+ if method == "flatten" :
198
+ index = None
199
+ else :
200
+ index = name
214
201
215
- version_grouped [branch ].append (( version , data ) )
216
- if latest_grouped [branch ] < date :
217
- latest_grouped [branch ] = version
202
+ version_grouped [index ].append (version )
203
+ if latest_grouped [index ][ 0 ] < date :
204
+ latest_grouped [index ] = ( date , version )
218
205
219
206
# Now, based on the group, generate the files
220
- for branch in version_grouped .keys ():
221
- for version , data in version_grouped [branch ]:
222
- os .makedirs (f"_downloads/{ type } /{ branch } " , exist_ok = True )
207
+ for index in version_grouped .keys ():
208
+ for version in version_grouped [index ]:
209
+ if method == "name" :
210
+ dest_folder = f"{ type } /{ index } "
211
+ else :
212
+ dest_folder = type
213
+
214
+ if method == "stable-testing" :
215
+ if index == "stable" :
216
+ # Force 'latest' to always point to 'stable'
217
+ latest_filenames = ["latest" ]
218
+ else :
219
+ latest_filenames = ["testing" ]
220
+
221
+ # In case testing is older than stable, stable becomes the testing
222
+ if latest_grouped ["testing" ][0 ] < latest_grouped ["stable" ][0 ]:
223
+ if index == "stable" :
224
+ latest_filenames .append ("testing" )
225
+ else :
226
+ latest_filenames = []
227
+ else :
228
+ latest_filenames = ["latest" ]
229
+
230
+ os .makedirs (f"_downloads/{ dest_folder } " , exist_ok = True )
223
231
await handle_version (
224
232
type ,
225
- f" { type } / { branch } " ,
233
+ dest_folder ,
226
234
version ,
227
235
"https://proxy.binaries.openttd.org" ,
228
- latest = latest_grouped [branch ])
236
+ latest = latest_grouped [index ][1 ],
237
+ latest_filenames = latest_filenames )
229
238
230
239
await session .close ()
231
240
0 commit comments