|
|
eb47f5 |
From bf0fb387cef89bb0dc51cf1740ab73abf549c38e Mon Sep 17 00:00:00 2001
|
|
|
eb47f5 |
From: Taylor Jakobson <tjakobs@us.ibm.com>
|
|
|
eb47f5 |
Date: Mon, 23 Oct 2017 14:26:03 -0500
|
|
|
eb47f5 |
Subject: [PATCH] Read number of backup files to keep from file
|
|
|
eb47f5 |
|
|
|
eb47f5 |
Use /etc/target/targetcli.conf file to store universal configurations
|
|
|
eb47f5 |
that are the same for all users.
|
|
|
eb47f5 |
Configuration file has format of:
|
|
|
eb47f5 |
key = value
|
|
|
eb47f5 |
---
|
|
|
eb47f5 |
targetcli/ui_root.py | 11 ++++++++++-
|
|
|
eb47f5 |
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
eb47f5 |
|
|
|
eb47f5 |
diff --git a/targetcli/ui_root.py b/targetcli/ui_root.py
|
|
|
eb47f5 |
index c3a8483..8bc8521 100644
|
|
|
eb47f5 |
--- a/targetcli/ui_root.py
|
|
|
eb47f5 |
+++ b/targetcli/ui_root.py
|
|
|
eb47f5 |
@@ -20,6 +20,7 @@ under the License.
|
|
|
eb47f5 |
from datetime import datetime
|
|
|
eb47f5 |
from glob import glob
|
|
|
eb47f5 |
import os
|
|
|
eb47f5 |
+import re
|
|
|
eb47f5 |
import shutil
|
|
|
eb47f5 |
import stat
|
|
|
eb47f5 |
|
|
|
eb47f5 |
@@ -32,7 +33,8 @@ from .ui_node import UINode
|
|
|
eb47f5 |
from .ui_target import UIFabricModule
|
|
|
eb47f5 |
|
|
|
eb47f5 |
default_save_file = "/etc/target/saveconfig.json"
|
|
|
eb47f5 |
-kept_backups = 10
|
|
|
eb47f5 |
+universal_prefs_file = "/etc/target/targetcli.conf"
|
|
|
eb47f5 |
+default_kept_backups = 10
|
|
|
eb47f5 |
|
|
|
eb47f5 |
class UIRoot(UINode):
|
|
|
eb47f5 |
'''
|
|
|
eb47f5 |
@@ -83,6 +85,13 @@ class UIRoot(UINode):
|
|
|
eb47f5 |
|
|
|
eb47f5 |
if backup_error == None:
|
|
|
eb47f5 |
# Kill excess backups
|
|
|
eb47f5 |
+ try:
|
|
|
eb47f5 |
+ with open(universal_prefs_file) as prefs:
|
|
|
eb47f5 |
+ backups = [line for line in prefs.read().splitlines() if re.match('^kept_backups\s*=', line)]
|
|
|
eb47f5 |
+ kept_backups = int(backups[0].split('=')[1].strip())
|
|
|
eb47f5 |
+ except:
|
|
|
eb47f5 |
+ kept_backups = default_kept_backups
|
|
|
eb47f5 |
+
|
|
|
eb47f5 |
backups = sorted(glob(os.path.dirname(savefile) + "/backup/*.json"))
|
|
|
eb47f5 |
files_to_unlink = list(reversed(backups))[kept_backups:]
|
|
|
eb47f5 |
for f in files_to_unlink:
|
|
|
eb47f5 |
--
|
|
|
eb47f5 |
1.8.3.1
|
|
|
eb47f5 |
|