Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cf_remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
exit_success,
expand_list_from_file,
is_file_string,
migrate_config_paths,
)
from cf_remote.utils import strip_user, read_json, is_package_url, cache
from cf_remote.packages import Releases
Expand Down Expand Up @@ -685,6 +686,8 @@ def main() -> int:

The only thing we want to do here is call _main() and handle exceptions (errors).
"""
migrate_config_paths()

if os.getenv("CFBACKTRACE") == "1":
r = _main()
assert type(r) is int
Expand Down
10 changes: 5 additions & 5 deletions cf_remote/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def path_append(dir, subdir):
return dir if not subdir else os.path.join(dir, subdir)


def cfengine_dir(subdir=None):
def cfengine_dir(subdir=None, in_cache=False):
override_dir = os.getenv("CF_REMOTE_DIR")

if override_dir:
Expand All @@ -23,19 +23,19 @@ def cfengine_dir(subdir=None):

return path_append(override_dir, subdir)

return path_append("~/.cfengine/", subdir)
return path_append("~/.%s/cfengine/" % ("cache" if in_cache else "config"), subdir)


def cf_remote_dir(subdir=None):
return path_append(cfengine_dir("cf-remote"), subdir)
def cf_remote_dir(subdir=None, in_cache=False):
return path_append(cfengine_dir("cf-remote", in_cache=in_cache), subdir)


def cf_remote_file(fname=None):
return path_append(cfengine_dir("cf-remote"), fname)


def cf_remote_packages_dir(subdir=None):
return path_append(cf_remote_dir("packages"), subdir)
return path_append(cf_remote_dir("packages", in_cache=True), subdir)


CLOUD_CONFIG_FNAME = "cloud_config.json"
Expand Down
2 changes: 1 addition & 1 deletion cf_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def install_host(
trust_keys=None,
insecure=False,
demo_salt=None,
demo_sha=None,
demo_sha=None
):
data = get_info(host, connection=connection)
if show_info:
Expand Down
2 changes: 1 addition & 1 deletion cf_remote/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def spawn_vm_in_vagrant(
vagrantdir = cf_remote_dir(os.path.join("vagrant", name))
os.makedirs(vagrantdir, exist_ok=True)

# Copy Vagrantfile to .cfengine/cf-remote/vagrant
# Copy Vagrantfile to ~/.config/cfengine/cf-remote/vagrant
vagrantfile = join(dirname(__file__), "Vagrantfile")
copy_file(vagrantfile, os.path.join(vagrantdir, "Vagrantfile"))

Expand Down
34 changes: 34 additions & 0 deletions cf_remote/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,37 @@ def has_unescaped_character(string, char):
return True
previous = current
return False


def migrate_config_paths():
old_dir = os.path.expanduser("~/.cfengine/cf-remote/")
conf_dir = os.path.expanduser("~/.config/cfengine/cf-remote/")
cache_dir = os.path.expanduser("~/.cache/cfengine/cf-remote/")
if not os.path.exists(os.path.dirname(old_dir)):
return # nothing to migrate
if os.path.exists(conf_dir) and os.path.exists(cache_dir):
pass # Migration has already occured
else:
shutil.copytree(
old_dir,
conf_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns("json", "packages"),
)
print("MIGRATION: config files have been moved to '%s'" % conf_dir)

shutil.copytree(
os.path.join(old_dir, "json"),
os.path.join(cache_dir, "json"),
dirs_exist_ok=True,
)
shutil.copytree(
os.path.join(old_dir, "packages"),
os.path.join(cache_dir, "packages"),
dirs_exist_ok=True,
)
print("MIGRATION: cache files have been moved to '%s'" % cache_dir)

shutil.rmtree(old_dir)
print("REMOVED: %s" % old_dir)
print("CREATED: %s and %s " % (cache_dir, conf_dir))
2 changes: 1 addition & 1 deletion cf_remote/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_json(url):
data = json.loads(r.read().decode(), object_pairs_hook=OrderedDict)

filename = os.path.basename(url)
dir = cf_remote_dir("json")
dir = cf_remote_dir("json", in_cache=True)
path = os.path.join(dir, filename)
log.debug("Saving '{}' to '{}'".format(url, path))
write_json(path, data)
Expand Down
Loading