Created
February 10, 2021 14:14
-
-
Save mrkeuz/b200dc626531de60d98f625b2aff63c1 to your computer and use it in GitHub Desktop.
Check gogs app.ini that keys not DEPRECATED/renamed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import configparser | |
from urllib.request import urlopen | |
def compare(): | |
print("Check configs...") | |
# Upstream App ini | |
response = urlopen('https://raw.githubusercontent.com/gogs/gogs/main/conf/app.ini') | |
upstream_app_ini = response.read().decode('utf-8') | |
upstream_app_ini = "[dummy_section]\n" + upstream_app_ini # Workaround for configparser | |
# App ini | |
with open("app.ini") as f: | |
app_ini = '[dummy_section]\n' + f.read() | |
local_config = read_config(app_ini) | |
upstream_config = read_config(upstream_app_ini) | |
sect_diff = set(sections(local_config)) - set(sections(upstream_config)) | |
if len(sect_diff) > 0: | |
print() | |
print("WARNING: Next sections exist in your app.ini but DEPRECATED/renamed/unused in upstream :") | |
print(sect_diff) | |
keys_diff = set(keys(local_config)) - set(keys(upstream_config)) | |
if len(keys_diff) > 0: | |
print() | |
print("WARNING: Next keys {section,parameter} exist in your app.ini but DEPRECATED/renamed/unused in upstream:") | |
print(keys_diff) | |
if len(keys_diff) == 0 and len(keys_diff) == 0: | |
print("Config ... ok") | |
def sections(config): | |
return config.sections() | |
def keys(config): | |
tuples = [] | |
for sec in config.sections(): | |
for par in config[sec]: | |
tuples.append((sec, par)) | |
return tuples | |
def read_config(ini_str): | |
config = configparser.RawConfigParser() | |
config.optionxform = str | |
config.read_string(ini_str) | |
return config | |
if __name__ == '__main__': | |
compare() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment