Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main, db_migrate: Hotfix user_directory and convert config_directory to Path #1306

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions src/tauon/t_modules/t_db_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def database_migrate(
star_store: StarStore,
a_cache_dir: str,
cache_directory: Path,
config_directory: str,
config_directory: Path,
install_directory: str,
user_directory: str,
gui: GuiVar,
Expand Down Expand Up @@ -185,8 +185,8 @@ def database_migrate(
for key, value in master_library.items():
setattr(master_library[key], "composer", "")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("global-search G Ctrl\n")
f.write("cycle-theme-reverse\n")
f.write("reload-theme F10\n")
Expand All @@ -203,8 +203,8 @@ def database_migrate(

if db_version <= 31:

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("love-selected\n")
gui.set_bar = True

Expand All @@ -225,15 +225,15 @@ def database_migrate(
if db_version <= 35:
logging.info("Updating database to version 36")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("toggle-show-art H Ctrl\n")

if db_version <= 37:
logging.info("Updating database to version 38")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("toggle-console `\n")

if db_version <= 38:
Expand All @@ -248,13 +248,13 @@ def database_migrate(
if db_version <= 39:
logging.info("Updating database to version 40")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
f = open(os.path.join(config_directory, "input.txt"), "r")
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
f = Path(config_directory / "input.txt").open("r")
text = f.read()
f.close()
lines = text.splitlines()
if "l ctrl" not in text.lower():
f = open(os.path.join(config_directory, "input.txt"), "w")
f = Path(config_directory / "input.txt").open("w")
for line in lines:
line = line.strip()
if line == "love-selected":
Expand All @@ -279,13 +279,13 @@ def database_migrate(
for key, value in gen_codes.items():
gen_codes[key] = value.replace("f\"", "p\"")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
f = open(os.path.join(config_directory, "input.txt"), "r")
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
f = Path(config_directory / "input.txt").open("r")
text = f.read()
f.close()
lines = text.splitlines()

f = open(os.path.join(config_directory, "input.txt"), "w")
f = Path(config_directory / "input.txt").open("w")
for line in lines:
line = line.strip()
if "rename-playlist" in line:
Expand Down Expand Up @@ -388,8 +388,8 @@ def database_migrate(
value.misc["replaygain_album_gain"] = value.album_gain
del value.album_gain

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("toggle-right-panel MB5\n")
f.write("toggle-gallery MB4\n")

Expand All @@ -402,8 +402,8 @@ def database_migrate(
if db_version <= 57:
logging.info("Updating database to version 58")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("\nregenerate-playlist R Alt\n")
f.write("clear-queue Q Shift Alt\n")
f.write("resize-window-16:9 F11 Alt\n")
Expand All @@ -412,8 +412,8 @@ def database_migrate(
if db_version <= 58:
logging.info("Updating database to version 59")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("\nrandom-album ; Alt\n")

if db_version <= 59:
Expand All @@ -439,8 +439,8 @@ def database_migrate(
if db_version <= 61:
logging.info("Updating database to version 62")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("\ntransfer-playtime-to P Ctrl Shift\n")

if db_version <= 62:
Expand All @@ -449,10 +449,10 @@ def database_migrate(
if item[0] == "T":
item[0] = "#"

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "r") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("r") as f:
lines = f.readlines()
with open(os.path.join(config_directory, "input.txt"), "w") as f:
with Path(config_directory / "input.txt").open("w") as f:
for line in lines:
if line == "vol-up Up Shift\n" or line == "vol-down Down Shift\n":
continue
Expand All @@ -473,16 +473,16 @@ def database_migrate(
if db_version <= 64:
logging.info("Updating database to version 65")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("\nescape Escape\n")
f.write("toggle-mute M Ctrl\n")

if db_version <= 65:
logging.info("Updating database to version 66")

if install_directory != config_directory and os.path.isfile(os.path.join(config_directory, "input.txt")):
with open(os.path.join(config_directory, "input.txt"), "a") as f:
if install_directory != config_directory and Path(config_directory / "input.txt").is_file():
with Path(config_directory / "input.txt").open("a") as f:
f.write("\ntoggle-artistinfo O Ctrl\n")
f.write("cycle-theme ] Ctrl\n")
f.write("cycle-theme-reverse [ Ctrl\n")
Expand Down
34 changes: 17 additions & 17 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@

# Set data folders (portable mode)
user_directory = install_directory
config_directory = user_directory
config_directory = Path(user_directory)
cache_directory = Path(user_directory) / "cache"
home_directory = os.path.join(os.path.expanduser("~"))

Expand Down Expand Up @@ -537,13 +537,13 @@
if (install_mode and system == "Linux") or macos or msys:

cache_directory = Path(GLib.get_user_cache_dir()) / "TauonMusicBox"
user_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
config_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
user_directory = str(Path(GLib.get_user_data_dir()) / "TauonMusicBox")
config_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"

if not Path(user_directory).is_dir():
if not user_directory.is_dir():
os.makedirs(user_directory)

if not Path(config_directory).is_dir():
if not config_directory.is_dir():
os.makedirs(config_directory)

if snap_mode:
Expand Down Expand Up @@ -576,7 +576,7 @@
logging.info("Running in portable mode")

user_directory = str(Path(install_directory) / "user-data")
config_directory = user_directory
config_directory = Path(user_directory)

if not Path(user_directory).is_dir():
os.makedirs(user_directory)
Expand All @@ -591,7 +591,7 @@
g_cache_dir = str(cache_directory / "gallery")
a_cache_dir = str(cache_directory / "artist")
r_cache_dir = str(cache_directory / "radio-thumbs")
b_cache_dir = str(Path(user_directory) / "artist-backgrounds")
b_cache_dir = str(Path(user_directory) / "artist-backgrounds")

if not os.path.isdir(n_cache_dir):
os.makedirs(n_cache_dir)
Expand Down Expand Up @@ -847,7 +847,7 @@ def asset_loader(name: str, mod: bool = False) -> WhiteModImageAsset | LoadImage
# loading_image.render(window_size[0] // 2 - loading_image.w // 2, window_size[1] // 2 - loading_image.h // 2)
# SDL_RenderPresent(renderer)

if install_directory != config_directory and not Path(Path(config_directory) / "input.txt").is_file():
if install_directory != config_directory and not Path(config_directory / "input.txt").is_file():
logging.warning("Input config file is missing, first run? Copying input.txt template from templates directory")
#logging.warning(install_directory)
#logging.warning(config_directory)
Expand Down Expand Up @@ -1390,8 +1390,8 @@ def __init__(self) -> None:
self.show_side_art = True
self.always_pin_playlists = True

self.user_directory = user_directory
self.cache_directory = cache_directory
self.user_directory: str = user_directory
self.cache_directory: Path = cache_directory

self.window_opacity = window_opacity
self.gallery_single_click = True
Expand Down Expand Up @@ -2406,8 +2406,8 @@ def __init__(self):

def load(self):

path = os.path.join(config_directory, "input.txt")
with open(path, encoding="utf_8") as f:
path = config_directory / "input.txt"
with path.open(encoding="utf_8") as f:
content = f.read().splitlines()
for p in content:
if len(p) == 0 or len(p) > 100:
Expand Down Expand Up @@ -3712,15 +3712,15 @@ def save_prefs():
cf.update_value("chart-font", prefs.chart_font)
cf.update_value("chart-sorts-top-played", prefs.topchart_sorts_played)

if os.path.isdir(config_directory):
cf.dump(os.path.join(config_directory, "tauon.conf"))
if config_directory.is_dir():
cf.dump(str(config_directory / "tauon.conf"))
else:
logging.error("Missing config directory")


def load_prefs():
cf.reset()
cf.load(os.path.join(config_directory, "tauon.conf"))
cf.load(str(config_directory / "tauon.conf"))

cf.add_comment("Tauon Music Box configuration file")
cf.br()
Expand Down Expand Up @@ -19917,7 +19917,7 @@ def reload_config_file():

def open_config_file():
save_prefs()
target = os.path.join(config_directory, "tauon.conf")
target = str(config_directory / "tauon.conf")
if system == "Windows" or msys:
os.startfile(target)
elif macos:
Expand All @@ -19931,7 +19931,7 @@ def open_config_file():


def open_keymap_file():
target = os.path.join(config_directory, "input.txt")
target = str(config_directory / "input.txt")

if not os.path.isfile(target):
show_message(_("Input file missing"))
Expand Down