mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-14 04:39:23 +00:00
[linux] user_keyboard_dir and user_keyman_dir
factor ~/.local/share/keyman location into a function also keyman_cache_dir for the cache location
This commit is contained in:
parent
a029e4442d
commit
ea1edfd79f
5 changed files with 26 additions and 14 deletions
|
|
@ -23,11 +23,9 @@ def get_keyboard_data(keyboardid):
|
|||
api_url = "https://api.keyman.com/keyboard/" + keyboardid
|
||||
logging.debug("At URL %s", api_url)
|
||||
home = str(Path.home())
|
||||
cache_dir = os.path.join(home, ".local/share/keyman")
|
||||
cache_dir = keyman_cache_dir()
|
||||
current_dir = os.getcwd()
|
||||
expire_after = datetime.timedelta(days=1)
|
||||
if not os.path.isdir(cache_dir):
|
||||
os.makedirs(cache_dir)
|
||||
os.chdir(cache_dir)
|
||||
requests_cache.install_cache(cache_name='keyman_cache', backend='sqlite', expire_after=expire_after)
|
||||
now = time.ctime(int(time.time()))
|
||||
|
|
@ -44,6 +42,15 @@ def get_download_folder():
|
|||
"""
|
||||
Folder where downloaded files will be saved.
|
||||
|
||||
Returns:
|
||||
str: path of user keyman cache folder
|
||||
"""
|
||||
return keyman_cache_dir()
|
||||
|
||||
def keyman_cache_dir()
|
||||
"""
|
||||
User keyman cache folder
|
||||
|
||||
Returns:
|
||||
str: path of user keyman cache folder
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ from keyman_config.kvk2ldml import convert_kvk_to_ldml, output_ldml
|
|||
# /usr/local/shared/keyman/kbid and link the files
|
||||
# to dirs in uls/doc and uls/fonts
|
||||
|
||||
def user_keyman_dir():
|
||||
home = os.path.expanduser("~")
|
||||
datahome = os.environ.get("XDG_DATA_HOME", os.path.join(home, ".local", "share"))
|
||||
return os.path.join(datahome, "keyman")
|
||||
|
||||
def user_keyboard_dir(keyboardid):
|
||||
return os.path.join(user_keyman_dir(), keyboardid)
|
||||
|
||||
def list_files(directory, extension):
|
||||
return (f for f in listdir(directory) if f.endswith('.' + extension))
|
||||
|
||||
|
|
@ -212,9 +220,7 @@ def install_kmp_shared(inputfile, online=False):
|
|||
def install_kmp_user(inputfile, online=False):
|
||||
do_install_to_ibus = False
|
||||
keyboardid, ext = os.path.splitext(os.path.basename(inputfile))
|
||||
home = os.path.expanduser("~")
|
||||
datahome = os.environ.get("XDG_DATA_HOME", os.path.join(home, ".local", "share"))
|
||||
kbdir=os.path.join(datahome, "keyman", keyboardid)
|
||||
kbdir=user_keyboard_dir(keyboardid)
|
||||
if not os.path.isdir(kbdir):
|
||||
os.makedirs(kbdir)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import os
|
|||
import json
|
||||
from enum import Enum, auto
|
||||
from keyman_config.kmpmetadata import parsemetadata, parseinfdata
|
||||
from keyman_config.install_kmp import user_keyman_dir
|
||||
|
||||
class InstallArea(Enum):
|
||||
IA_OS = auto()
|
||||
|
|
@ -36,8 +37,7 @@ def get_installed_kmp(area):
|
|||
check_paths = []
|
||||
if area == InstallArea.IA_USER:
|
||||
home = os.path.expanduser("~")
|
||||
datahome = os.environ.get("XDG_DATA_HOME", os.path.join(home, ".local", "share"))
|
||||
check_paths = [ os.path.join(datahome, "keyman"), os.path.join(home, ".kmfl") ]
|
||||
check_paths = [ user_keyman_dir(), os.path.join(home, ".kmfl") ]
|
||||
elif area == InstallArea.IA_SHARED:
|
||||
check_paths = [ "/usr/local/share/keyman" ]
|
||||
elif area == InstallArea.IA_OS:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import subprocess
|
|||
import sys
|
||||
import os.path
|
||||
from shutil import rmtree
|
||||
from keyman_config.install_kmp import user_keyboard_dir
|
||||
|
||||
def uninstall_from_ibus(kmnfile):
|
||||
if sys.version_info.major == 3 and sys.version_info.minor < 6:
|
||||
|
|
@ -79,9 +80,7 @@ def uninstall_kmp_user(keyboardid):
|
|||
Args:
|
||||
keyboardid (str): Keyboard ID
|
||||
"""
|
||||
home = os.path.expanduser("~")
|
||||
datahome = os.environ.get("XDG_DATA_HOME", os.path.join(home, ".local", "share"))
|
||||
kbdir=os.path.join(datahome, "keyman", keyboardid)
|
||||
kbdir=user_keyboard_dir(keyboardid)
|
||||
if not os.path.isdir(kbdir):
|
||||
logging.error("Keyboard directory for %s does not exist. Aborting", keyboardid)
|
||||
exit(3)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from keyman_config.downloadkeyboard import DownloadKmpWindow
|
|||
from keyman_config.install_window import InstallKmpWindow, find_keyman_image
|
||||
from keyman_config.uninstall_kmp import uninstall_kmp
|
||||
from keyman_config.accelerators import bind_accelerator, init_accel
|
||||
from keyman_config.install_kmp import user_keyboard_dir
|
||||
|
||||
class KeyboardBox(Gtk.Box):
|
||||
def __init__(self, kmp, window, area):
|
||||
|
|
@ -22,9 +23,7 @@ class KeyboardBox(Gtk.Box):
|
|||
|
||||
self.kmp = kmp
|
||||
if area == InstallArea.IA_USER:
|
||||
home = os.path.expanduser("~")
|
||||
datahome = os.environ.get("XDG_DATA_HOME", os.path.join(home, ".local", "share"))
|
||||
self.kbhome = os.path.join(datahome, "keyman", self.kmp["id"])
|
||||
self.kbhome = user_keyboard_dir(self.kmp["id"])
|
||||
self.kbdoc = self.kbhome
|
||||
elif area == InstallArea.IA_SHARED:
|
||||
self.kbhome = os.path.join("/usr/local/share/keyman", self.kmp["id"])
|
||||
|
|
@ -95,6 +94,7 @@ class KeyboardBox(Gtk.Box):
|
|||
dialog.destroy()
|
||||
if response == Gtk.ResponseType.YES:
|
||||
logging.info("Uninstalling keyboard" + self.kmp["name"])
|
||||
# can only uninstall with the gui from user area
|
||||
uninstall_kmp(self.kmp["id"])
|
||||
logging.info("need to refresh window after uninstalling a keyboard")
|
||||
self.parent.refresh_installed_kmp()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue