summaryrefslogtreecommitdiff
path: root/lib/api/install.py
blob: f379f1421cf8ff833f209b4b97924a8e271b6c8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()