1616
1717from __future__ import annotations
1818from argparse import ArgumentParser , Namespace
19- from configparser import ConfigParser
2019from functools import cache
2120from hashlib import sha256
2221from itertools import count
2322import json
2423import os
24+ from pathlib import Path
2525import re
2626import subprocess
2727import sys
3030
3131import requests
3232
33+ from utils import read_wrap , wrap_path
34+
3335WRAP_URL_TEMPLATE = (
3436 'https://github.com/mesonbuild/wrapdb/blob/master/subprojects/{0}.wrap'
3537)
@@ -127,18 +129,11 @@ def get_wrap_versions() -> dict[str, str]:
127129 }
128130
129131
130- def get_wrap_contents (name : str ) -> ConfigParser :
131- '''Return a ConfigParser loaded with the specified wrap.'''
132- wrap = ConfigParser (interpolation = None )
133- wrap .read (f'subprojects/{ name } .wrap' , encoding = 'utf-8' )
134- return wrap
135-
136-
137132def get_port_wraps () -> set [str ]:
138133 '''Return the names of wraps that have a patch directory.'''
139134 ports = set ()
140135 for name , info in get_releases ().items ():
141- wrap = get_wrap_contents (name )
136+ wrap = read_wrap (name )
142137 if wrap .has_option ('wrap-file' , 'patch_directory' ):
143138 ports .add (name )
144139 return ports
@@ -148,8 +143,8 @@ def update_wrap(name: str, old_ver: str, new_ver: str) -> None:
148143 '''Try to update the specified wrap file from old_ver to new_ver.'''
149144
150145 # read wrap file
151- filename = f'subprojects/ { name } .wrap'
152- with open (filename ) as f :
146+ path = wrap_path ( name )
147+ with path . open (encoding = 'utf-8' ) as f :
153148 lines = f .readlines ()
154149
155150 # update versions
@@ -191,7 +186,7 @@ def update_wrap(name: str, old_ver: str, new_ver: str) -> None:
191186 break
192187
193188 # write
194- with open (filename , 'w ' ) as f :
189+ with path . open ('w' , encoding = 'utf-8 ' ) as f :
195190 f .write ('' .join (lines ))
196191
197192
@@ -298,20 +293,21 @@ def do_commit(args: Namespace) -> None:
298293 else :
299294 raise ValueError ("Can't autogenerate commit message; specify -m" )
300295
301- commit_files = [
302- 'ci_config.json' , 'releases.json' , f'subprojects/ { name } .wrap'
296+ commit_files : list [ str | Path ] = [
297+ 'ci_config.json' , 'releases.json' , wrap_path ( name )
303298 ]
304- patch_dir = get_wrap_contents (name ).get (
299+ patch_dir = read_wrap (name ).get (
305300 'wrap-file' , 'patch_directory' , fallback = None
306301 )
307302 if patch_dir :
308303 commit_files .append (f'subprojects/packagefiles/{ patch_dir } ' )
309304
310305 # suppress Git summary output and recreate it ourselves so we can also
311306 # show the diffstat, to confirm we've committed the right files
312- subprocess .check_call (
313- ['git' , 'commit' , '-m' , f'{ name } : { args .message } ' , '-q' ] + commit_files
314- )
307+ cmd : list [str | Path ] = [
308+ 'git' , 'commit' , '-m' , f'{ name } : { args .message } ' , '-q'
309+ ]
310+ subprocess .check_call (cmd + commit_files )
315311 subprocess .check_call (['git' , 'log' , '-1' , '--format=[%h] %s' ])
316312 subprocess .check_call (['git' , 'diff' , '--stat' , 'HEAD^..HEAD' ])
317313
@@ -381,7 +377,7 @@ def do_list(args: Namespace) -> None:
381377 'wrapdb' : cur_vers [name ],
382378 'upstream' : upstream_vers .get (name ),
383379 'port' : name in ports ,
384- 'source' : get_wrap_contents (name ).get (
380+ 'source' : read_wrap (name ).get (
385381 'wrap-file' , 'source_url'
386382 )
387383 } for name in wraps
0 commit comments