def get_log_path(subfolder=None, filename=None, create=True): """ Returns the default log path for the platform. This will be: - macOS: "~/Library/Logs/SUBFOLDER/FILENAME" - Linux: "$XDG_CACHE_HOME/SUBFOLDER/FILENAME" - fallback: "~/.cache/SUBFOLDER/FILENAME" :param str subfolder: The subfolder for the app. :param str filename: The filename to append for the app. :param bool create: If ``True``, the folder "<subfolder>" will be created on-demand. """ # if-defs for different platforms if platform.system() == "Darwin": log_path = osp.join(get_home_dir(), "Library", "Logs") else: fallback = osp.join(get_home_dir(), ".cache") log_path = os.environ.get("XDG_CACHE_HOME", fallback) # attach subfolder if subfolder: log_path = osp.join(log_path, subfolder) # create dir if create: os.makedirs(log_path, exist_ok=True) # attach filename if filename: log_path = osp.join(log_path, filename) return log_path
def rel_path(path): """ Returns the path relative to the users directory, or the absolute path if not in a user directory. """ usr = osp.abspath(osp.join(get_home_dir(), osp.pardir)) if osp.commonprefix([path, usr]) == usr: return osp.relpath(path, usr) else: return path
def get_log_path(subfolder=None, filename=None, create=True): """ Returns the default log path for the platform. This will be: - macOS: '~/Library/Logs/SUBFOLDER/FILENAME' - Linux: 'XDG_CACHE_HOME/SUBFOLDER/FILENAME' - other: '~/.cache/SUBFOLDER/FILENAME' :param str subfolder: The subfolder for the app. :param str filename: The filename to append for the app. :param bool create: If ``True``, the folder '<subfolder>' will be created on-demand. """ # Define log_dir if platform.system() == 'Linux': # This makes us follow the XDG standard to save our settings # on Linux xdg_cache_home = os.environ.get('XDG_CACHE_HOME', '') if not xdg_cache_home: xdg_cache_home = osp.join(get_home_dir(), '.cache') if create and not osp.isdir(xdg_cache_home): os.makedirs(xdg_cache_home) log_dir = osp.join(xdg_cache_home, subfolder) elif platform.system() == 'Darwin': log_dir = osp.join(get_home_dir(), 'Library', 'Logs', subfolder) else: log_dir = osp.join(get_home_dir(), '.cache', subfolder) # Create conf_dir if create and not osp.isdir(log_dir): os.mkdir(log_dir) if filename is None: return log_dir else: return osp.join(log_dir, filename)
def get_autostart_path(filename=None, create=True): """ Returns the default cache path for the platform. This will be: - macOS: '~/Library/LaunchAgents/FILENAME' - Linux: 'XDG_CONFIG_HOME/autostart/FILENAME' - other: '~/.config/autostart/FILENAME' :param str filename: The filename to append for the app. :param bool create: If ``True``, the folder '<subfolder>' will be created on-demand. """ if platform.system() == 'Darwin': return osp.join(get_home_dir(), "Library", "LaunchAgents", filename) else: return get_log_path("autostart", filename, create)
def filename(self): """Create a .ini filename. This .ini files stores the global preferences. """ if self.subfolder is None: config_file = osp.join(get_home_dir(), '.%s.ini' % self.name) return config_file else: folder = get_conf_path(self.subfolder) # Save defaults in a "defaults" dir of .spyder2 to not pollute it if 'defaults' in self.name: folder = osp.join(folder, 'defaults') if not osp.isdir(folder): os.mkdir(folder) config_file = osp.join(folder, '%s.ini' % self.name) return config_file
def get_autostart_path(filename=None, create=True): """ Returns the default cache path for the platform. This will be: - macOS: "~/Library/LaunchAgents/FILENAME" - Linux: "$XDG_CONFIG_HOME/autostart/FILENAME" - fallback: "~/.config/autostart/FILENAME" :param str filename: The filename to append for the app. :param bool create: If ``True``, the folder "<subfolder>" will be created on-demand. """ if platform.system() == "Darwin": autostart_path = osp.join(get_home_dir(), "Library", "LaunchAgents") else: autostart_path = get_conf_path("autostart", create=create) # attach filename if filename: autostart_path = osp.join(autostart_path, filename) return autostart_path
Attribution-NonCommercial-NoDerivs 2.0 UK: England & Wales License. """ import os import os.path as osp import platform import tempfile from maestral.config.base import get_home_dir, get_conf_path, get_data_path, _to_full_path __all__ = [ 'get_home_dir', 'get_conf_path', 'get_data_path', 'get_log_path', 'get_cache_path', 'get_autostart_path', 'get_runtime_path' ] _home_dir = get_home_dir() def get_cache_path(subfolder=None, filename=None, create=True): """ Returns the default cache path for the platform. This will be: - macOS: "~/Library/Application Support/SUBFOLDER/FILENAME" - Linux: "$XDG_CACHE_HOME/SUBFOLDER/FILENAME" - fallback: "$HOME/.cache/SUBFOLDER/FILENAME" :param str subfolder: The subfolder for the app. :param str filename: The filename to append for the app. :param bool create: If ``True``, the folder "<subfolder>" will be created on-demand. """ if platform.system() == "Darwin":
def __init__(self, pending_link=True, parent=None): super(self.__class__, self).__init__(parent=parent) # load user interface layout from .ui file uic.loadUi(SETUP_DIALOG_PATH, self) self.app_icon = QtGui.QIcon(APP_ICON_PATH) self.labelIcon_0.setPixmap(icon_to_pixmap(self.app_icon, 170)) self.labelIcon_1.setPixmap(icon_to_pixmap(self.app_icon, 70)) self.labelIcon_2.setPixmap(icon_to_pixmap(self.app_icon, 70)) self.labelIcon_3.setPixmap(icon_to_pixmap(self.app_icon, 100)) self.mdbx = None self.folder_items = [] # resize dialog buttons width = self.pushButtonAuthPageCancel.width() * 1.1 for b in (self.pushButtonAuthPageLink, self.pussButtonDropboxPathUnlink, self.pussButtonDropboxPathSelect, self.pushButtonFolderSelectionBack, self.pushButtonFolderSelectionSelect, self.pushButtonAuthPageCancel, self.pussButtonDropboxPathCalcel, self.pushButtonClose): b.setMinimumWidth(width) b.setMaximumWidth(width) # set up combobox self.dropbox_location = osp.dirname(CONF.get( "main", "path")) or get_home_dir() relative_path = self.rel_path(self.dropbox_location) folder_icon = get_native_item_icon(self.dropbox_location) self.comboBoxDropboxPath.addItem(folder_icon, relative_path) self.comboBoxDropboxPath.insertSeparator(1) self.comboBoxDropboxPath.addItem(QtGui.QIcon(), "Other...") self.comboBoxDropboxPath.currentIndexChanged.connect(self.on_combobox) self.dropbox_folder_dialog = QtWidgets.QFileDialog(self) self.dropbox_folder_dialog.setAcceptMode( QtWidgets.QFileDialog.AcceptOpen) self.dropbox_folder_dialog.setFileMode(QtWidgets.QFileDialog.Directory) self.dropbox_folder_dialog.setOption( QtWidgets.QFileDialog.ShowDirsOnly, True) self.dropbox_folder_dialog.fileSelected.connect(self.on_new_dbx_folder) self.dropbox_folder_dialog.rejected.connect( lambda: self.comboBoxDropboxPath.setCurrentIndex(0)) # connect buttons to callbacks self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.pushButtonLink.clicked.connect(self.on_link) self.pushButtonAuthPageCancel.clicked.connect(self.abort) self.pushButtonAuthPageLink.clicked.connect(self.on_auth_clicked) self.pussButtonDropboxPathCalcel.clicked.connect(self.abort) self.pussButtonDropboxPathSelect.clicked.connect( self.on_dropbox_location_selected) self.pussButtonDropboxPathUnlink.clicked.connect( self.unlink_and_go_to_start) self.pushButtonFolderSelectionBack.clicked.connect( self.stackedWidget.slideInPrev) self.pushButtonFolderSelectionSelect.clicked.connect( self.on_folders_selected) self.pushButtonClose.clicked.connect(self.accept) self.listWidgetFolders.itemChanged.connect( self.update_select_all_checkbox) self.selectAllCheckBox.clicked.connect(self.on_select_all_clicked) self.labelDropboxPath.setText(self.labelDropboxPath.text().format( CONF.get("main", "default_dir_name"))) # check if we are already authenticated, skip authentication if yes if not pending_link: self.labelDropboxPath.setText(""" <html><head/><body> <p align="left"> Your Dropbox folder has been moved or deleted from its original location. Maestral will not work properly until you move it back. It used to be located at: </p><p align="left">{0}</p> <p align="left"> To move it back, click "Quit" below, move the Dropbox folder back to its original location, and launch Maestral again. </p> <p align="left"> To re-download your Dropbox, please select a location for your Dropbox folder below. Maestral will create a new folder named "{1}" in the selected location.</p> <p align="left"> To unlink your Dropbox account from Maestral, click "Unlink" below.</p> </body></html> """.format(CONF.get("main", "path"), CONF.get("main", "default_dir_name"))) self.pussButtonDropboxPathCalcel.setText("Quit") self.stackedWidget.setCurrentIndex(2) self.stackedWidgetButtons.setCurrentIndex(2) self.mdbx = Maestral(run=False) self.mdbx.client.get_account_info() else: self.stackedWidget.setCurrentIndex(0) self.stackedWidgetButtons.setCurrentIndex(0)