1
1
#!/usr/bin/env python3
2
2
import argparse
3
3
import os .path
4
+ from filelock import FileLock
4
5
import yml_reftag
5
6
import json
6
7
@@ -44,14 +45,16 @@ def main(args: argparse.Namespace):
44
45
}
45
46
distro_release ['imagesuites' ].append (img_json )
46
47
for board_ref in img_yml [img_name ]['compatible' ]:
47
- with open (os .path .splitext (os .path .join (args .json_tree , board_ref .category , board_ref .resc ))[0 ] + '.json' , 'r' ) as fp :
48
- board_json = json .load (fp )
49
- if distro_name in board_json ['os' ]:
50
- board_json ['os' ][distro_name ].append (distro_release )
51
- else :
52
- board_json ['os' ][distro_name ] = [distro_release ]
53
- with open (os .path .splitext (os .path .join (args .json_tree , board_ref .category , board_ref .resc ))[0 ] + '.json' , 'w' ) as fp :
54
- json .dump (board_json , fp , indent = 2 )
48
+ board_json_file = os .path .splitext (os .path .join (args .json_tree , board_ref .category , board_ref .resc ))[0 ] + '.json'
49
+ with FileLock (board_json_file + ".lock" , timeout = - 1 ):
50
+ with open (board_json_file , 'r' ) as fp :
51
+ board_json = json .load (fp )
52
+ if distro_name in board_json ['os' ]:
53
+ board_json ['os' ][distro_name ].append (distro_release )
54
+ else :
55
+ board_json ['os' ][distro_name ] = [distro_release ]
56
+ with open (board_json_file , 'w' ) as fp :
57
+ json .dump (board_json , fp , indent = 2 )
55
58
56
59
if __name__ == "__main__" :
57
60
arg_parser = argparse .ArgumentParser ()
@@ -67,4 +70,4 @@ def main(args: argparse.Namespace):
67
70
help = "Search path for YAMLs being referenced" ,
68
71
required = False , type = str , default = ''
69
72
)
70
- main (arg_parser .parse_args ())
73
+ main (arg_parser .parse_args ())
0 commit comments