From bb706c1fe29ae3d2dcf8705970a7c0b3c5738c85 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 18 Jul 2016 16:50:27 +0200 Subject: [PATCH] browser/dashboard: use appdirs, closes #438 --- artiq/frontend/artiq_browser.py | 8 +++----- artiq/frontend/artiq_dashboard.py | 9 ++++----- artiq/tools.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/artiq/frontend/artiq_browser.py b/artiq/frontend/artiq_browser.py index 5cc0624dd..a11a39b1c 100755 --- a/artiq/frontend/artiq_browser.py +++ b/artiq/frontend/artiq_browser.py @@ -10,7 +10,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets from quamash import QEventLoop from artiq import __artiq_dir__ as artiq_dir -from artiq.tools import verbosity_args, atexit_register_coroutine +from artiq.tools import (verbosity_args, atexit_register_coroutine, + get_user_config_dir) from artiq.gui import state, applets, models, log from artiq.browser import datasets, files, experiments @@ -19,10 +20,7 @@ logger = logging.getLogger(__name__) def get_argparser(): - if os.name == "nt": - default_db_file = os.path.expanduser("~\\artiq_browser.pyon") - else: - default_db_file = os.path.expanduser("~/.artiq_browser.pyon") + default_db_file = os.path.join(get_user_config_dir(), "artiq_browser.pyon") parser = argparse.ArgumentParser(description="ARTIQ Browser") parser.add_argument("--db-file", default=default_db_file, diff --git a/artiq/frontend/artiq_dashboard.py b/artiq/frontend/artiq_dashboard.py index aabd1b6f5..3ac1c2f63 100755 --- a/artiq/frontend/artiq_dashboard.py +++ b/artiq/frontend/artiq_dashboard.py @@ -10,7 +10,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets from quamash import QEventLoop from artiq import __artiq_dir__ as artiq_dir, __version__ as artiq_version -from artiq.tools import * +from artiq.tools import (atexit_register_coroutine, verbosity_args, + get_user_config_dir) from artiq.protocols.pc_rpc import AsyncioClient from artiq.protocols.broadcast import Receiver from artiq.gui.models import ModelSubscriber @@ -20,10 +21,8 @@ from artiq.dashboard import (experiments, shortcuts, explorer, def get_argparser(): - if os.name == "nt": - default_db_file = os.path.expanduser("~\\artiq_dashboard.pyon") - else: - default_db_file = os.path.expanduser("~/.artiq_dashboard.pyon") + default_db_file = os.path.join(get_user_config_dir(), + "artiq_dashboard.pyon") parser = argparse.ArgumentParser(description="ARTIQ Dashboard") parser.add_argument( diff --git a/artiq/tools.py b/artiq/tools.py index 20ef7e892..c24c9725c 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -14,6 +14,9 @@ import numpy as np from artiq.language.environment import is_experiment from artiq.protocols import pyon +from artiq.appdirs import user_config_dir +from artiq._version import get_versions +artiq_version = get_versions()['version'] __all__ = ["parse_arguments", "elide", "short_format", "file_import", @@ -243,3 +246,10 @@ def get_windows_drives(): drives.append(letter) bitmask >>= 1 return drives + + +def get_user_config_dir(): + major = artiq_version.split(".")[0] + dir = user_config_dir("artiq", "m-labs", major) + os.makedirs(dir, exist_ok=True) + return dir