venv: Save cache to standard cache location.

Saving the cache inside the repository means the buildbot will clear it
automatically.
This commit is contained in:
Florian Bruhin 2015-01-23 17:47:26 +01:00
parent 409c04b6d4
commit 6ceb0a41ff
2 changed files with 15 additions and 10 deletions

1
.gitignore vendored
View File

@ -13,4 +13,3 @@ __pycache__
/doc/*.html /doc/*.html
/README.html /README.html
/qutebrowser/html/doc/ /qutebrowser/html/doc/
/.venv-cache

View File

@ -34,6 +34,8 @@ import venv
import urllib.request import urllib.request
import tempfile import tempfile
from PyQt5.QtCore import QStandardPaths
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
from scripts import utils from scripts import utils
@ -62,8 +64,8 @@ def parse_args():
parser.add_argument('--dev', help="Set up an environment suitable for " parser.add_argument('--dev', help="Set up an environment suitable for "
"developing qutebrowser.", "developing qutebrowser.",
action='store_true') action='store_true')
parser.add_argument('--cache', help="Cache the clean virtualenv in " parser.add_argument('--cache', help="Cache the clean virtualenv and "
"NAME-cache and copy it when a new one is requested.", "copy it when a new one is requested.",
action='store_true') action='store_true')
parser.add_argument('path', help="Path to the venv folder", parser.add_argument('path', help="Path to the venv folder",
default='.venv', nargs='?') default='.venv', nargs='?')
@ -186,7 +188,7 @@ def create_venv():
install_pip() install_pip()
def restore_cache(): def restore_cache(cache_path):
"""Restore a cache if one is present and --cache is given.""" """Restore a cache if one is present and --cache is given."""
utils.print_title("Restoring cache") utils.print_title("Restoring cache")
if g_args.cache: if g_args.cache:
@ -195,7 +197,7 @@ def restore_cache():
except FileNotFoundError: except FileNotFoundError:
pass pass
try: try:
shutil.copytree(g_args.path + '-cache', g_args.path, symlinks=True) shutil.copytree(cache_path, g_args.path, symlinks=True)
except FileNotFoundError: except FileNotFoundError:
print("No cache present!") print("No cache present!")
else: else:
@ -203,15 +205,15 @@ def restore_cache():
return False return False
def save_cache(): def save_cache(cache_path):
"""Save the cache if --cache is given.""" """Save the cache if --cache is given."""
utils.print_title("Saving cache") utils.print_title("Saving cache")
if g_args.cache: if g_args.cache:
try: try:
shutil.rmtree(g_args.path + '-cache') shutil.rmtree(cache_path)
except FileNotFoundError: except FileNotFoundError:
pass pass
shutil.copytree(g_args.path, g_args.path + '-cache', symlinks=True) shutil.copytree(g_args.path, cache_path, symlinks=True)
def main(): def main():
@ -229,7 +231,11 @@ def main():
"--upgrade.".format(g_path), file=sys.stderr) "--upgrade.".format(g_path), file=sys.stderr)
sys.exit(1) sys.exit(1)
restored = restore_cache() os_cache_dir = QStandardPaths.writableLocation(
QStandardPaths.CacheLocation)
cache_path = os.path.join(os_cache_dir, 'qutebrowser-venv')
restored = restore_cache(cache_path)
if not restored: if not restored:
create_venv() create_venv()
@ -241,7 +247,7 @@ def main():
install_dev_packages() install_dev_packages()
link_pyqt() link_pyqt()
test_toolchain() test_toolchain()
save_cache() save_cache(cache_path)
if __name__ == '__main__': if __name__ == '__main__':