How to use the appdirs.user_cache_dir 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 boramalper / himawaripy / himawaripy / __main__.py View on Github external
group = parser.add_mutually_exclusive_group()

    group.add_argument("--auto-offset", action="store_true", dest="auto_offset", default=False,
                       help="determine offset automatically")
    group.add_argument("-o", "--offset", type=int, dest="offset", default=10,
                       help="UTC time offset in hours, must be less than or equal to +10")

    parser.add_argument("-l", "--level", type=int, choices=[4, 8, 16, 20], dest="level", default=4,
                        help="increases the quality (and the size) of each tile. possible values are 4, 8, 16, 20")
    parser.add_argument("-d", "--deadline", type=int, dest="deadline", default=6,
                        help="deadline in minutes to download all the tiles, set 0 to cancel")
    parser.add_argument("--save-battery", action="store_true", dest="save_battery", default=False,
                        help="stop refreshing on battery")
    parser.add_argument("--output-dir", type=str, dest="output_dir",
                        help="directory to save the temporary background image",
                        default=appdirs.user_cache_dir(appname="himawaripy", appauthor=False))
    parser.add_argument("--dont-change", action="store_true", dest="dont_change", default=False,
                        help="don't change the wallpaper (just download it)")

    args = parser.parse_args()

    if not -12 <= args.offset <= 10:
        sys.exit("OFFSET has to be between -12 and +10!\n")

    if not args.deadline >= 0:
        sys.exit("DEADLINE has to be greater than (or equal to if you want to disable) zero!\n")

    return args
github ScriptSmith / reaper / components / globals.py View on Github external
import appdirs
import sys
import os

APP_NAME = "Reaper"
APP_AUTHOR = "UQ"

DATA_DIR = appdirs.user_data_dir(APP_NAME, APP_AUTHOR)
LOG_DIR = appdirs.user_log_dir(APP_NAME, APP_AUTHOR)
CACHE_DIR = appdirs.user_cache_dir(APP_NAME, APP_AUTHOR)

def _calc_path(path):
    head, tail = os.path.split(path)
    if tail == 'reaper':
        return path
    else:
        return _calc_path(head)

BUNDLE_DIR = sys._MEIPASS if getattr(sys, "frozen", False) else \
    _calc_path(os.path.dirname(os.path.abspath(__file__)))
github Akuli / porcupine / porcupine / dirs.py View on Github external
import platform

import appdirs

from porcupine import __author__ as _author


if platform.system() in {'Windows', 'Darwin'}:
    # these platforms like path names like "Program Files" or
    # "Application Support"
    _appname = 'Porcupine'
else:
    _appname = 'porcupine'
    _author = _author.lower()

cachedir = appdirs.user_cache_dir(_appname, _author)
configdir = appdirs.user_config_dir(_appname, _author)

# this hack shouldn't be a problem because porcupine isn't distributed
# with tools like pyinstaller, and it doesn't need to be because people
# using porcupine have python installed anyway
installdir = os.path.dirname(os.path.abspath(__file__))


def makedirs():
    all_paths = [cachedir, configdir, os.path.join(configdir, 'plugins')]
    for path in all_paths:
        os.makedirs(path, exist_ok=True)
github inducer / pycuda / pycuda / compiler.py View on Github external
from pycuda.driver import CUDA_DEBUGGING
    if CUDA_DEBUGGING:
        cache_dir = False
        keep = True
        options.extend(["-g", "-G"])

    if "PYCUDA_CACHE_DIR" in os.environ and cache_dir is None:
        cache_dir = os.environ["PYCUDA_CACHE_DIR"]

    if "PYCUDA_DISABLE_CACHE" in os.environ:
        cache_dir = False

    if cache_dir is None:
        import appdirs
        cache_dir = os.path.join(appdirs.user_cache_dir("pycuda", "pycuda"),
                "compiler-cache-v1")

        from os import makedirs
        try:
            makedirs(cache_dir)
        except OSError as e:
            from errno import EEXIST
            if e.errno != EEXIST:
                raise

    if arch is not None:
        options.extend(["-arch", arch])

    if code is not None:
        options.extend(["-code", code])
github kolinger / rd-usb / app.py View on Github external
from time import sleep
from urllib import request

from appdirs import user_cache_dir
import webview
from webview.platforms.cef import settings

from utils.config import data_path, Config
from utils.version import version
from web import run

debug = "FLASK_DEBUG" in os.environ

settings.update({
    "log_file": data_path + "/cef.log",
    "cache_path": user_cache_dir("rd-usb", False),
})


class Webview:
    title = None
    width = None
    height = None

    callback = None
    window = None
    loaded = False
    sleep = 0.5

    loading_html = """
        <style>
            html { height: 100%; overflow: hidden; }</style>
github gleitz / howdoi / howdoi / howdoi.py View on Github external
BLOCK_INDICATORS = (
    'form id="captcha-form"',
    'This page appears when Google automatically detects requests coming from your computer '
    'network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service'
)

BLOCKED_QUESTION_FRAGMENTS = (
    'webcache.googleusercontent.com',
)

STAR_HEADER = u('\u2605')
ANSWER_HEADER = u('{2}  Answer from {0} {2}\n{1}')
NO_ANSWER_MSG = '&lt; no answer given &gt;'

CACHE_EMPTY_VAL = "NULL"
CACHE_DIR = appdirs.user_cache_dir('howdoi')
CACHE_ENTRY_MAX = 128

if os.getenv('HOWDOI_DISABLE_CACHE'):
    cache = NullCache()  # works like an always empty cache
else:
    cache = FileSystemCache(CACHE_DIR, CACHE_ENTRY_MAX, default_timeout=0)

howdoi_session = requests.session()


class BlockError(RuntimeError):
    pass


def _random_int(width):
    bres = os.urandom(width)</a>
github pymedusa / Medusa / lib / simpleanidb / __init__.py View on Github external
def _init_cache(self, cache_dir, refresh=False):
        if not cache_dir:
            self._cache_dir = user_cache_dir('simpleanidb', appauthor='simpleanidb')  # appauthor is requered on windows
            if not os.path.isdir(self._cache_dir):
                os.makedirs(self._cache_dir)
        else:
            if not path.exists(cache_dir):
                makedirs(cache_dir)

            self._cache_dir = cache_dir
        if not os.path.isdir(self._cache_dir):
            raise ValueError('{0} does not exist'.format(self._cache_dir))
        elif not os.access(self._cache_dir, os.W_OK):
            raise IOError('{0} is not writable'.format(self._cache_dir))
github hotdoc / hotdoc / hotdoc / extensions / git_upload / git_upload_extension.py View on Github external
def __clone_and_update_repo(self):
        cachedir = appdirs.user_cache_dir("hotdoc", "hotdoc")

        repo_url, repo_path = _split_repo_url(self.__repository)
        if repo_url is None or repo_path is None:
            warn("git-error", "%s doesn't seem to contain a repository URL" % (
                self.__repository))
            return None

        sanitize = str.maketrans('/@:', '___')
        repo = os.path.join(cachedir, 'git-upload',
                            repo_url.translate(sanitize))
        try:
            call(['git', 'rev-parse', '--show-toplevel'], cwd=repo,
                 stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError, FileNotFoundError):
            print("cloning %s" % repo_url)
            try:
github revng / llvmcpy / llvmcpy / llvm.py View on Github external
# Print enum conversion methods
        for name, values in enums.items():
            write(
"""
{} = {}
""".format(name, values))

unsigned_ints = set(("unsigned", "unsigned int", "unsigned long"))

# Add to PATH the output of llvm-config --bin-dir
search_paths = os.environ.get("PATH", os.defpath)
llvm_config = find_program("LLVM_CONFIG", ["llvm-config"])
search_paths = run_llvm_config(["--bindir"]) + (search_paths and (os.pathsep + search_paths))

cache_dir = appdirs.user_cache_dir('llvmcpy')
version = run_llvm_config(["--version"])
to_hash = llvm_config.encode("utf-8")
hasher = hashlib.sha256()
hasher.update(to_hash)
cache_dir = os.path.join(cache_dir, hasher.hexdigest() + "-" + version)
cached_module = os.path.join(cache_dir, "llvmcpyimpl.py")
if not os.path.exists(cached_module):
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    generate_wrapper()
sys.path.insert(0, cache_dir)
from llvmcpyimpl import *
del sys.path[0]

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