def clear_cache(force = False):
"""
If the folder exists, and has more than 5MB of icons in the cache, delete
it to clear all the icons then recreate it.
"""
from os.path import getsize, join, isfile, exists
from os import makedirs, listdir
from sublime import cache_path
from shutil import rmtree
# The icon cache path
icon_path = join(cache_path(), "GutterColor")
# The maximum amount of space to take up
limit = 5242880 # 5 MB
if exists(icon_path):
size = sum(getsize(join(icon_path, f)) for f in listdir(icon_path) if isfile(join(icon_path, f)))
if force or (size > limit): rmtree(icon_path)
if not exists(icon_path): makedirs(icon_path)
python类cache_path()的实例源码
def icon_path(self):
"""Returns the absolute path to the icons"""
return join(cache_path(), 'GutterColor', '%s.png' % self.color())
def _get_cache_path(cls):
"""
"""
return os.path.join(sublime.cache_path(), "SwiftKitten")
def _save_framework_cache(cls):
"""
"""
cache_path = cls._get_cache_path()
if not os.path.exists(cache_path):
os.mkdir(cache_path)
framework_cache_path = os.path.join(cache_path, "frameworks.cache")
with open(framework_cache_path, "wb") as f:
pickle.dump(cls.framework_cache, f)
def getDocphpPath():
return sublime.cache_path() + '/' + package_name + '/'
def get_cache_dir():
path = os.path.join(sublime.cache_path(), 'GotoUsage')
if not os.path.exists(path):
os.mkdir(path)
return path
def get_report_file():
path = os.path.join(sublime.cache_path(), 'PyTest')
if not os.path.isdir(path):
os.makedirs(path)
return os.path.join(path, 'last-run.xml')
def panel_file():
plugin_dir = ''
if hasattr(sublime, 'cache_path'):
plugin_dir = sublime.cache_path()
else:
plugin_dir = 'cache'
plugin_dir = os.path.join(os.getcwd(), plugin_dir)
data_dir = path.join(plugin_dir, panel_name)
if not path.exists(data_dir):
os.makedirs(data_dir)
return path.join(data_dir, panel_name)
# -----------------
def plugin_dir():
return os.path.join(sublime.cache_path(), 'RemoteCpp')