-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (37 loc) · 1.55 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import os
folders = []
for root, dirs, files in os.walk('.'):
if 'manifest.json' in files:
folders.append(root)
print('These folders have a manifest.json file:')
for i, folder in enumerate(folders, 1):
print(f'{i}. {folder}')
choice = int(input('Enter the number of the folder you want to update: '))
if 1 <= choice <= len(folders):
folder = folders[choice - 1]
with open(f'{folder}/manifest.json', 'r+') as json_file:
data = json.load(json_file)
mod_versions = {}
for item in data['dependencies']:
author_name, mod_name, version = item.split('-')
mod_versions[author_name + '-' + mod_name] = version
with open('dependency.txt', 'r') as txt_file:
for line in txt_file:
line = line.strip()
author_name, mod_name, version = line.split('-')
fullname = author_name + '-' + mod_name
if fullname in mod_versions:
old_version = mod_versions[fullname]
if version > old_version:
index = data['dependencies'].index(fullname + '-' + old_version)
data['dependencies'][index] = line
print(f'updated {mod_name} {old_version} -> {version}')
else:
data['dependencies'].append(line)
print(f'added {mod_name}')
json_file.seek(0)
json.dump(data, json_file, indent=4)
json_file.truncate()
else:
print(f'Invalid folder number: {choice}')