Skip to content

Commit c8540aa

Browse files
authored
Fixed all old config values being strings (#8273)
2 parents 2996c48 + ef9258b commit c8540aa

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

src/tribler/upgrade_script.py

+35-33
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _copy_if_not_exist(src: str, dst: str) -> None:
3636
shutil.copy(src, dst)
3737

3838

39-
def _copy_if_exists(src: ConfigObj, src_path: str, dst: TriblerConfigManager, dst_path: str) -> None:
39+
def _copy_if_exists(src: ConfigObj, src_path: str, dst: TriblerConfigManager, dst_path: str, conversion: type) -> None:
4040
"""
4141
Check if the src path is set and copy it into the dst if it is.
4242
"""
@@ -46,47 +46,49 @@ def _copy_if_exists(src: ConfigObj, src_path: str, dst: TriblerConfigManager, ds
4646
out = out.get(part)
4747
else:
4848
return
49-
dst.set(dst_path, out)
49+
dst.set(dst_path, conversion(out))
5050

5151

5252
def _import_7_14_settings(src: str, dst: TriblerConfigManager) -> None:
5353
"""
5454
Read the file at the source path and import its settings.
5555
"""
5656
old = ConfigObj(src, encoding="utf-8")
57-
_copy_if_exists(old, "api/key", dst, "api/key")
58-
_copy_if_exists(old, "api/http_enabled", dst, "api/http_enabled")
59-
_copy_if_exists(old, "api/https_enabled", dst, "api/https_enabled")
60-
_copy_if_exists(old, "ipv8/statistics", dst, "statistics")
61-
_copy_if_exists(old, "libtorrent/port", dst, "libtorrent/port")
62-
_copy_if_exists(old, "libtorrent/proxy_type", dst, "libtorrent/proxy_type")
63-
_copy_if_exists(old, "libtorrent/proxy_server", dst, "libtorrent/proxy_server")
64-
_copy_if_exists(old, "libtorrent/proxy_auth", dst, "libtorrent/proxy_auth")
65-
_copy_if_exists(old, "libtorrent/max_connections_download", dst, "libtorrent/max_connections_download")
66-
_copy_if_exists(old, "libtorrent/max_download_rate", dst, "libtorrent/max_download_rate")
67-
_copy_if_exists(old, "libtorrent/max_upload_rate", dst, "libtorrent/max_upload_rate")
68-
_copy_if_exists(old, "libtorrent/utp", dst, "libtorrent/utp")
69-
_copy_if_exists(old, "libtorrent/dht", dst, "libtorrent/dht")
70-
_copy_if_exists(old, "libtorrent/dht_readiness_timeout", dst, "libtorrent/dht_readiness_timeout")
71-
_copy_if_exists(old, "libtorrent/upnp", dst, "libtorrent/upnp")
72-
_copy_if_exists(old, "libtorrent/natpmp", dst, "libtorrent/natpmp")
73-
_copy_if_exists(old, "libtorrent/lsd", dst, "libtorrent/lsd")
74-
_copy_if_exists(old, "download_defaults/anonymity_enabled", dst, "libtorrent/download_defaults/anonymity_enabled")
75-
_copy_if_exists(old, "download_defaults/number_hops", dst, "libtorrent/download_defaults/number_hops")
57+
_copy_if_exists(old, "api/key", dst, "api/key", str)
58+
_copy_if_exists(old, "api/http_enabled", dst, "api/http_enabled", bool)
59+
_copy_if_exists(old, "api/https_enabled", dst, "api/https_enabled", bool)
60+
_copy_if_exists(old, "ipv8/statistics", dst, "statistics", bool)
61+
_copy_if_exists(old, "libtorrent/port", dst, "libtorrent/port", int)
62+
_copy_if_exists(old, "libtorrent/proxy_type", dst, "libtorrent/proxy_type", int)
63+
_copy_if_exists(old, "libtorrent/proxy_server", dst, "libtorrent/proxy_server", str)
64+
_copy_if_exists(old, "libtorrent/proxy_auth", dst, "libtorrent/proxy_auth", str)
65+
_copy_if_exists(old, "libtorrent/max_connections_download", dst, "libtorrent/max_connections_download", int)
66+
_copy_if_exists(old, "libtorrent/max_download_rate", dst, "libtorrent/max_download_rate", int)
67+
_copy_if_exists(old, "libtorrent/max_upload_rate", dst, "libtorrent/max_upload_rate", int)
68+
_copy_if_exists(old, "libtorrent/utp", dst, "libtorrent/utp", bool)
69+
_copy_if_exists(old, "libtorrent/dht", dst, "libtorrent/dht", bool)
70+
_copy_if_exists(old, "libtorrent/dht_readiness_timeout", dst, "libtorrent/dht_readiness_timeout", int)
71+
_copy_if_exists(old, "libtorrent/upnp", dst, "libtorrent/upnp", bool)
72+
_copy_if_exists(old, "libtorrent/natpmp", dst, "libtorrent/natpmp", bool)
73+
_copy_if_exists(old, "libtorrent/lsd", dst, "libtorrent/lsd", bool)
74+
_copy_if_exists(old, "download_defaults/anonymity_enabled",
75+
dst, "libtorrent/download_defaults/anonymity_enabled", bool)
76+
_copy_if_exists(old, "download_defaults/number_hops", dst, "libtorrent/download_defaults/number_hops", int)
7677
_copy_if_exists(old, "download_defaults/safeseeding_enabled",
77-
dst, "libtorrent/download_defaults/safeseeding_enabled")
78-
_copy_if_exists(old, "download_defaults/saveas", dst, "libtorrent/download_defaults/saveas")
79-
_copy_if_exists(old, "download_defaults/seeding_mode", dst, "libtorrent/download_defaults/seeding_mode")
80-
_copy_if_exists(old, "download_defaults/seeding_ratio", dst, "libtorrent/download_defaults/seeding_ratio")
81-
_copy_if_exists(old, "download_defaults/seeding_time", dst, "libtorrent/download_defaults/seeding_time")
82-
_copy_if_exists(old, "download_defaults/channel_download", dst, "libtorrent/download_defaults/channel_download")
78+
dst, "libtorrent/download_defaults/safeseeding_enabled", bool)
79+
_copy_if_exists(old, "download_defaults/saveas", dst, "libtorrent/download_defaults/saveas", str)
80+
_copy_if_exists(old, "download_defaults/seeding_mode", dst, "libtorrent/download_defaults/seeding_mode", str)
81+
_copy_if_exists(old, "download_defaults/seeding_ratio", dst, "libtorrent/download_defaults/seeding_ratio", float)
82+
_copy_if_exists(old, "download_defaults/seeding_time", dst, "libtorrent/download_defaults/seeding_time", int)
83+
_copy_if_exists(old, "download_defaults/channel_download",
84+
dst, "libtorrent/download_defaults/channel_download", bool)
8385
_copy_if_exists(old, "download_defaults/add_download_to_channel",
84-
dst, "libtorrent/download_defaults/add_download_to_channel")
85-
_copy_if_exists(old, "popularity_community/enabled", dst, "content_discovery_community/enabled")
86-
_copy_if_exists(old, "torrent_checking/enabled", dst, "torrent_checker/enabled")
87-
_copy_if_exists(old, "tunnel_community/enabled", dst, "tunnel_community/enabled")
88-
_copy_if_exists(old, "tunnel_community/min_circuits", dst, "tunnel_community/min_circuits")
89-
_copy_if_exists(old, "tunnel_community/max_circuits", dst, "tunnel_community/max_circuits")
86+
dst, "libtorrent/download_defaults/add_download_to_channel", bool)
87+
_copy_if_exists(old, "popularity_community/enabled", dst, "content_discovery_community/enabled", bool)
88+
_copy_if_exists(old, "torrent_checking/enabled", dst, "torrent_checker/enabled", bool)
89+
_copy_if_exists(old, "tunnel_community/enabled", dst, "tunnel_community/enabled", bool)
90+
_copy_if_exists(old, "tunnel_community/min_circuits", dst, "tunnel_community/min_circuits", int)
91+
_copy_if_exists(old, "tunnel_community/max_circuits", dst, "tunnel_community/max_circuits", int)
9092

9193

9294
def _inject_StatementOp(abs_src_db: str, abs_dst_db: str) -> None:

0 commit comments

Comments
 (0)