summaryrefslogtreecommitdiff
path: root/lib/api/install.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2020-08-20 22:13:02 -0400
committerGitHub <noreply@github.com>2020-08-20 22:13:02 -0400
commiteedcd016f620e8e3fe939978becf496d77d4080c (patch)
treeb27caab4f3942b9e9f27eff7efc2bf6c468cca48 /lib/api/install.py
parent4dcb07c3d801d033df94c2a400adc7ce163d2d4e (diff)
parent6e34f5f7fc8598e564adf9b3e08e6cb4275923b5 (diff)
Merge pull request #793 from inkstitch/lexelby/install-extension-electron
migrate install extension to electron
Diffstat (limited to 'lib/api/install.py')
-rw-r--r--lib/api/install.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/api/install.py b/lib/api/install.py
new file mode 100644
index 00000000..20138973
--- /dev/null
+++ b/lib/api/install.py
@@ -0,0 +1,47 @@
+import os
+import sys
+from glob import glob
+
+from flask import Blueprint, jsonify, request
+
+from ..utils import get_bundled_dir, guess_inkscape_config_path
+
+install = Blueprint('install', __name__)
+
+
+@install.route('/palettes', methods=["POST"])
+def palettes():
+ try:
+ base_path = request.json.get('path') or guess_inkscape_config_path()
+ path = os.path.join(base_path, 'palettes')
+ src_dir = get_bundled_dir('palettes')
+ copy_files(glob(os.path.join(src_dir, "*")), path)
+ except Exception, exc:
+ return jsonify({"error": str(exc)}), 500
+
+ return jsonify({"status": "success"})
+
+
+if sys.platform == "win32":
+ # If we try to just use shutil.copy it says the operation requires elevation.
+ def copy_files(files, dest):
+ import winutils
+
+ if not os.path.exists(dest):
+ os.makedirs(dest)
+
+ winutils.copy(files, dest)
+else:
+ def copy_files(files, dest):
+ import shutil
+
+ if not os.path.exists(dest):
+ os.makedirs(dest)
+
+ for palette_file in files:
+ shutil.copy(palette_file, dest)
+
+
+@install.route('/default-path')
+def default_path():
+ return guess_inkscape_config_path()