mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	Merge pull request #321 from PenitentMonke/xdg-base-dir
Adhere to XDG base dir spec on Linux
This commit is contained in:
		@@ -3,7 +3,22 @@ import os
 | 
			
		||||
import tempfile
 | 
			
		||||
 | 
			
		||||
from urllib.parse import urlparse
 | 
			
		||||
from platform import system
 | 
			
		||||
 | 
			
		||||
def get_nhentai_home() -> str:
 | 
			
		||||
    home = os.getenv('HOME', tempfile.gettempdir())
 | 
			
		||||
 | 
			
		||||
    if system() == 'Linux':
 | 
			
		||||
        xdgdat = os.getenv('XDG_DATA_HOME')
 | 
			
		||||
        if xdgdat and os.path.exists(os.path.join(xdgdat, 'nhentai')):
 | 
			
		||||
            return os.path.join(xdgdat, 'nhentai')
 | 
			
		||||
        if home and os.path.exists(os.path.join(home, '.nhentai')):
 | 
			
		||||
            return os.path.join(home, '.nhentai')
 | 
			
		||||
        if xdgdat:
 | 
			
		||||
            return os.path.join(xdgdat, 'nhentai')
 | 
			
		||||
 | 
			
		||||
    # Use old default path in other systems
 | 
			
		||||
    return os.path.join(home, '.nhentai')
 | 
			
		||||
 | 
			
		||||
DEBUG = os.getenv('DEBUG', False)
 | 
			
		||||
BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
 | 
			
		||||
@@ -21,7 +36,7 @@ FAV_URL = f'{BASE_URL}/favorites/'
 | 
			
		||||
 | 
			
		||||
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
 | 
			
		||||
 | 
			
		||||
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
 | 
			
		||||
NHENTAI_HOME = get_nhentai_home()
 | 
			
		||||
NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3')
 | 
			
		||||
NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user