You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
input-remapper/keymapper/paths.py

71 lines
2.2 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# key-mapper - GUI for device specific keyboard mappings
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
#
# This file is part of key-mapper.
#
# key-mapper 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 3 of the License, or
# (at your option) any later version.
#
# key-mapper 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 key-mapper. If not, see <https://www.gnu.org/licenses/>.
"""Path constants to be used."""
import os
# the path in home, is symlinked with USERS_SYMBOLS.
# getlogin gets the user who ran sudo
HOME_PATH = os.path.join('/home', os.getlogin(), '.config/key-mapper')
# the path that contains ALL symbols, not just ours
X11_SYMBOLS = '/usr/share/X11/xkb/symbols'
# should not contain spaces
USERS_SYMBOLS = os.path.join(
'/usr/share/X11/xkb/symbols/key-mapper',
os.getlogin().replace(' ', '_')
)
# those are the same for every preset and user
KEYCODES_PATH = '/usr/share/X11/xkb/keycodes/key-mapper'
def get_home_path(device, preset=None):
"""Get the path to the config file in /usr."""
device = device.strip()
if preset is not None:
preset = preset.strip()
return os.path.join(HOME_PATH, device, preset).replace(' ', '_')
else:
return os.path.join(HOME_PATH, device.replace(' ', '_'))
DEFAULT_SYMBOLS = get_home_path('default')
def get_usr_path(device, preset=None):
"""Get the path to the config file in /usr.
This folder is a symlink and the files are in ~/.config/key-mapper
If preset is omitted, returns the folder for the device.
"""
device = device.strip()
if preset is not None:
preset = preset.strip()
return os.path.join(USERS_SYMBOLS, device, preset).replace(' ', '_')
else:
return os.path.join(USERS_SYMBOLS, device.replace(' ', '_'))