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
36 changes: 21 additions & 15 deletions providers/base/bin/wifi_nmcli_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import shutil
import subprocess as sp
import sys
import glob
from pathlib import Path

from packaging import version as version_parser

Expand Down Expand Up @@ -62,37 +64,41 @@ def reload_nm_connections():


def save_connections(keyfile_list):
if not os.path.exists(SAVE_DIR):
os.makedirs(SAVE_DIR)
if len(keyfile_list) == 0:
os.makedirs(SAVE_DIR, exist_ok=True)

if not keyfile_list:
print("No stored 802.11 connections to save")
return

for f in keyfile_list:
print("Save connection {}".format(f))

if not os.path.exists(f):
print(" No stored connection fount at {}".format(f))
print(" No stored connection found at {}".format(f))
continue

print(" Found file {}".format(f))
save_f = shutil.copy(f, SAVE_DIR)
basedir = Path(f).parent
backup_loc = SAVE_DIR / basedir

os.makedirs(backup_loc, exist_ok=True)
save_f = shutil.copy(f, backup_loc)
print(" Saved copy at {}".format(save_f))


def restore_connections():
saved_list = [
f
for f in os.listdir(SAVE_DIR)
if os.path.isfile(os.path.join(SAVE_DIR, f))
]
saved_list = glob.glob(
"{}/**/*.nmconnection".format(SAVE_DIR), recursive=True
)
if len(saved_list) == 0:
print("No stored 802.11 connections found")
return
for f in saved_list:
save_f = os.path.join(SAVE_DIR, f)
f_path = Path(f)
save_f = f_path.relative_to(SAVE_DIR)
dest_path = Path("/") / save_f
print("Restore connection {}".format(save_f))
restore_f = shutil.copy(save_f, NM_CON_DIR)
print(" Restored file at {}".format(restore_f))
os.remove(save_f)
print(" Removed copy from {}".format(save_f))
shutil.move(f, dest_path)


if __name__ == "__main__":
Expand Down
Loading