mirror of
https://github.com/fergalmoran/picard.git
synced 2026-05-10 21:16:18 +00:00
Move macos-specific functions to new picard.util.macos
This commit is contained in:
@@ -36,7 +36,6 @@ import os
|
||||
from PyQt6 import QtCore
|
||||
from PyQt6.QtCore import QStandardPaths
|
||||
|
||||
from picard import log
|
||||
from picard.const import (
|
||||
CACHE_SIZE_DISPLAY_UNIT,
|
||||
RELEASE_PRIMARY_GROUPS,
|
||||
@@ -79,26 +78,8 @@ DEFAULT_LOCAL_COVER_ART_REGEX = r'^(?:cover|folder|albumart)(.*)\.(?:jpe?g|png|g
|
||||
|
||||
DEFAULT_CURRENT_BROWSER_PATH = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.HomeLocation)
|
||||
if IS_MACOS:
|
||||
def _macos_extend_root_volume_path(path):
|
||||
|
||||
def _macos_find_root_volume():
|
||||
try:
|
||||
for entry in os.scandir("/Volumes/"):
|
||||
if entry.is_symlink() and os.path.realpath(entry.path) == "/":
|
||||
return entry.path
|
||||
except OSError:
|
||||
log.warning("Could not detect macOS boot volume", exc_info=True)
|
||||
return None
|
||||
|
||||
if not path.startswith("/Volumes/"):
|
||||
root_volume = _macos_find_root_volume()
|
||||
if root_volume:
|
||||
if path.startswith("/"):
|
||||
path = path[1:]
|
||||
path = os.path.join(root_volume, path)
|
||||
return path
|
||||
|
||||
DEFAULT_CURRENT_BROWSER_PATH = _macos_extend_root_volume_path(DEFAULT_CURRENT_BROWSER_PATH)
|
||||
from picard.util.macos import extend_root_volume_path
|
||||
DEFAULT_CURRENT_BROWSER_PATH = extend_root_volume_path(DEFAULT_CURRENT_BROWSER_PATH)
|
||||
|
||||
# Default query limit
|
||||
DEFAULT_QUERY_LIMIT = 50
|
||||
|
||||
43
picard/util/macos.py
Normal file
43
picard/util/macos.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Picard, the next-generation MusicBrainz tagger
|
||||
#
|
||||
# Copyright (C) 2024 Laurent Monin
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
import os
|
||||
|
||||
from picard import log
|
||||
|
||||
|
||||
def _find_root_volume():
|
||||
try:
|
||||
for entry in os.scandir("/Volumes/"):
|
||||
if entry.is_symlink() and os.path.realpath(entry.path) == "/":
|
||||
return entry.path
|
||||
except OSError:
|
||||
log.warning("Could not detect macOS boot volume", exc_info=True)
|
||||
return None
|
||||
|
||||
|
||||
def extend_root_volume_path(path):
|
||||
if not path.startswith("/Volumes/"):
|
||||
root_volume = _find_root_volume()
|
||||
if root_volume:
|
||||
if path.startswith("/"):
|
||||
path = path[1:]
|
||||
path = os.path.join(root_volume, path)
|
||||
return path
|
||||
Reference in New Issue
Block a user