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