From 690ee0c416635f8d6d3dc07048be90bd0da7748f Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 19 Aug 2020 14:53:01 -0400 Subject: wip: move install extension to electron --- lib/api/install.py | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/api/server.py | 8 +++++--- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 lib/api/install.py (limited to 'lib/api') diff --git a/lib/api/install.py b/lib/api/install.py new file mode 100644 index 00000000..f379f142 --- /dev/null +++ b/lib/api/install.py @@ -0,0 +1,42 @@ +import os +import sys +from glob import glob + +from flask import Blueprint, request + +from ..utils import get_bundled_dir, guess_inkscape_config_path + +install = Blueprint('install', __name__) + + +@install.route('/palettes') +def palettes(): + 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) + + +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() diff --git a/lib/api/server.py b/lib/api/server.py index c57a1785..bdfa4573 100644 --- a/lib/api/server.py +++ b/lib/api/server.py @@ -1,15 +1,16 @@ import errno import logging import socket -from threading import Thread import time +from threading import Thread -from flask import Flask, request, g import requests +from flask import Flask, g, request -from ..utils.json import InkStitchJSONEncoder +from .install import install from .simulator import simulator from .stitch_plan import stitch_plan +from ..utils.json import InkStitchJSONEncoder class APIServer(Thread): @@ -31,6 +32,7 @@ class APIServer(Thread): self.app.register_blueprint(simulator, url_prefix="/simulator") self.app.register_blueprint(stitch_plan, url_prefix="/stitch_plan") + self.app.register_blueprint(install, url_prefix="/install") @self.app.before_request def store_extension(): -- cgit v1.2.3