How to use the appdirs.AppDirs function in appdirs

To help you get started, we’ve selected a few appdirs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github portablejim / curseDownloader / downloader.py View on Github external
def doDownload(manifest):
    manifestPath = Path(manifest)
    targetDirPath = manifestPath.parent

    manifestText = manifestPath.open().read()
    manifestText = manifestText.replace('\r', '').replace('\n', '')

    manifestJson = json.loads(manifestText)

    overridePath = Path(targetDirPath, manifestJson['overrides'])
    minecraftPath = Path(targetDirPath, "minecraft")
    if overridePath.exists():
        shutil.move(str(overridePath), str(minecraftPath))

    downloaderDirs = appdirs.AppDirs(appname="cursePackDownloader", appauthor="portablejim")
    cache_path = Path(downloaderDirs.user_cache_dir, "curseCache")

    # Attempt to set proper portable data directory if asked for
    if args.portable:
        if '__file__' in globals():
            cache_path = Path(os.path.dirname(os.path.realpath(__file__)), "CPD_data")
        else:
            print("Portable data dir not supported for interpreter environment")
            exit(2)

    if not cache_path.exists():
        cache_path.mkdir(parents=True)
    print("Cache path : %s" % (cache_path))

    if not minecraftPath.exists():
        minecraftPath.mkdir()
github GoSecure / malboxes / malboxes / malboxes.py View on Github external
import os
from pkg_resources import resource_filename, resource_stream
import re
import shutil
import signal
import subprocess
import sys
import textwrap

from appdirs import AppDirs
from jinja2 import Environment, FileSystemLoader
from jsmin import jsmin

from malboxes._version import __version__

DIRS = AppDirs("malboxes")
DEBUG = False

def initialize():
    # create appdata directories if they don't exist
    if not os.path.exists(DIRS.user_config_dir):
        os.makedirs(DIRS.user_config_dir)

    profile_dir = os.path.join(DIRS.user_config_dir, "profiles")

    if not os.path.exists(profile_dir):
        os.makedirs(profile_dir)

    if not os.path.exists(DIRS.user_cache_dir):
        os.makedirs(DIRS.user_cache_dir)

    cache_scripts_dir = os.path.join(DIRS.user_cache_dir, "scripts", "user")
github projecthamster / hamster-lib / hamster_lib / helpers / config_helpers.py View on Github external
``ConfigParser`` representation does not include those however!
"""


from __future__ import absolute_import, unicode_literals

import datetime
import os

import appdirs
import hamster_lib
from configparser import SafeConfigParser
from six import text_type


class HamsterAppDirs(appdirs.AppDirs):
    """Custom class that ensure appdirs exist."""

    def __init__(self, *args, **kwargs):
        """Add create flag value to instance."""
        super(HamsterAppDirs, self).__init__(*args, **kwargs)
        self.create = True

    @property
    def user_data_dir(self):
        """Return ``user_data_dir``."""
        directory = appdirs.user_data_dir(self.appname, self.appauthor,
                             version=self.version, roaming=self.roaming)
        if self.create:
            self._ensure_directory_exists(directory)
        return directory
github renanivo / with / withtool / config.py View on Github external
def get_config():
    app_dirs = AppDirs(appname='with', appauthor='Renan Ivo')

    config = {
        'history_dir': os.path.join(app_dirs.user_cache_dir, 'history'),
    }

    if not os.path.isdir(config['history_dir']):
        os.makedirs(config['history_dir'])

    return config
github matrix-hacks / matrix-puppet-hangouts / hangups_client.py View on Github external
def _get_parser():
    """Return ArgumentParser with any extra arguments."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    dirs = appdirs.AppDirs('hangups', 'hangups')
    default_token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')
    parser.add_argument(
        '--token-path', default=default_token_path,
        help='path used to store OAuth refresh token'
    )
    parser.add_argument(
        '--login-and-save-token', action='store_true',
        help='Perform login and save refresh token'
    )
    parser.add_argument(
        '-d', '--debug', action='store_true',
        help='log detailed debugging messages'
    )
    return parser
github IKNL / vantage / pytaskmanager / util / __init__.py View on Github external
def instance_folders(instance_type, instance_name, system_folders):
        d = appdirs.AppDirs(constants.APPNAME, "")
        if system_folders:
            return {
                "log":Path(d.site_data_dir) / instance_type,
                "data":Path(d.site_data_dir) / instance_type / instance_name,
                "config":Path(d.site_config_dir) / instance_type
            }
        else:
            return {
                "log":Path(d.user_log_dir) / instance_type,
                "data":Path(d.user_data_dir) / instance_type / instance_name,
                "config":Path(d.user_config_dir) / instance_type
            }
github tdryer / hangups / examples / common.py View on Github external
def _get_parser(extra_args):
    """Return ArgumentParser with any extra arguments."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    dirs = appdirs.AppDirs('hangups', 'hangups')
    default_token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')
    parser.add_argument(
        '--token-path', default=default_token_path,
        help='path used to store OAuth refresh token'
    )
    parser.add_argument(
        '-d', '--debug', action='store_true',
        help='log detailed debugging messages'
    )
    for extra_arg in extra_args:
        parser.add_argument(extra_arg, required=True)
    return parser
github freenet / pyFreenet / babcom.py View on Github external
def save(self):
        """Save state like the CAPTCHA solutions."""
        if self.transient:
            return # not saving anything in transient mode
        
        dirs = appdirs.AppDirs("babcom", "freenet")
        # dirs.user_data_dir 
        # dirs.user_config_dir 
        # dirs.user_cache_dir
        # dirs.user_log_dir
        identity_info_dir = os.path.join(dirs.user_data_dir, self.identity)
        if not os.path.isdir(identity_info_dir):
            os.makedirs(identity_info_dir)
        with open(os.path.join(
                identity_info_dir, "unusedcaptchasolutions.txt"), "w") as f:
            f.write("\n".join(self.captchasolutions))
        logging.debug("saved {}".format(self.captchasolutions))
github instantshare / instantshare / src / tools / dirs.py View on Github external
from appdirs import AppDirs
import os
import res as resources


appdirs = AppDirs(
    appname="instantshare",
    appauthor="instantshare",
    version=None
)


def _mk(path):
    os.makedirs(path, exist_ok=True)
    return path


logs = _mk(appdirs.user_log_dir)
configs = _mk(appdirs.user_config_dir)
cache = _mk(appdirs.user_cache_dir)
data = _mk(appdirs.user_cache_dir)
res = str(os.path.dirname(resources.__file__))
github webrecorder / simplechrome / simplechrome / launcher.py View on Github external
from ._typings import Loop, OptionalLoop
from .browser_fetcher import BrowserFetcher
from .chrome import Chrome
from .connection import Connection, createForWebSocket
from .errors import LauncherError
from .helper import Helper

__all__ = ["Launcher", "launch", "connect", "DEFAULT_ARGS"]

DEFAULT_CHROMIUM_REVISION: str = "656675"
CHROMIUM_REVISION: str = os.getenv(
    "SIMPLECHROME_CHROMIUM_REVISION", DEFAULT_CHROMIUM_REVISION
)
SIMPLECHROME_HOME: str = os.getenv(
    "SIMPLECHROME_HOME", AppDirs("simplechrome").user_data_dir
)

logger = logging.getLogger(__name__)

# https://peter.sh/experiments/chromium-command-line-switches/
# https://cs.chromium.org/chromium/src/chrome/common/chrome_switches.cc
DEFAULT_ARGS = [
    "--autoplay-policy=no-user-gesture-required",
    "--disable-background-networking",
    "--disable-background-timer-throttling",
    "--disable-backgrounding-occluded-windows",
    "--disable-backing-store-limit",
    "--disable-breakpad",
    "--disable-client-side-phishing-detection",
    "--disable-default-apps",
    "--disable-domain-reliability",

appdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".

MIT
Latest version published 4 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages