From: Sophie Brun <[email protected]>
Date: Thu, 23 Jan 2020 10:21:00 +0100
Subject: Add a script to manage configuration during upgrade
Origin: vendor
Last-Update: 2020-01-23
During a upgrade we have to install the new configuration files in
~/.config/OSRFramework:
- Update configuration.py to create the missing directory "data"
only if it doesn't exist.
- Add a script (which is called in postinst when it's an upgrade) to
remove config directories "default", "plugins", "server", "transforms",
and install the new directories and files provided by the package.
---
osrframework/utils/configuration.py | 6 ++++--
osrframework/utils/upgrade_config.py | 12 ++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 osrframework/utils/upgrade_config.py
diff --git a/osrframework/utils/configuration.py b/osrframework/utils/configuration.py
index afc8b5e..6e58096 100644
--- a/osrframework/utils/configuration.py
+++ b/osrframework/utils/configuration.py
@@ -40,8 +40,10 @@ def initialize_config_files():
for dirconf in ["default", "plugins"]:
shutil.copytree(os.path.join('/etc/osrframework',dirconf), os.path.join(LOCAL_CONFIG_DIR, dirconf))
- # Create directory data
- os.mkdir(get_config_path()["appPathData"])
+ # Create directory data if it doesn't exist (we keep it at the
+ # upgrade)
+ if not os.path.exists(get_config_path()["appPathData"]):
+ os.mkdir(get_config_path()["appPathData"])
# Create directory Transforms before copy *.py files
# os.mkdir(LOCAL_CONFIG_TRANSFORMS_DIR)
diff --git a/osrframework/utils/upgrade_config.py b/osrframework/utils/upgrade_config.py
new file mode 100644
index 0000000..ca2de05
--- /dev/null
+++ b/osrframework/utils/upgrade_config.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python3
+
+import os
+import shutil
+
+import osrframework.utils.configuration as configuration
+
+if __name__ == "__main__":
+ if os.path.exists(configuration.get_config_path()["appPath"]):
+ for confdir in ["default", "plugins", "server", "transforms"]:
+ shutil.rmtree(os.path.join(configuration.get_config_path()["appPath"], confdir), True)
+ configuration.initialize_config_files()