View source with formatted comments or as raw
    1/*  Part of SWISH
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2017-2018, VU University Amsterdam
    7			      CWI Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(swish_paths, []).   37:- use_module(library(http/http_path), []).   38
   39/** <module> Setup SWISH search paths
   40*/
   41
   42:- initialization initialize_paths.   43
   44:- multifile
   45    user:file_search_path/2,
   46    http:location/3.   47
   48user:file_search_path(data,           data).
   49user:file_search_path(config_enabled, 'config-enabled').
   50user:file_search_path(config_enabled, swish('config-enabled')).
   51user:file_search_path(config,         config_enabled(.)).
   52user:file_search_path(config,         swish('config-available')).
   53user:file_search_path(swish_web,      swish(web)).
   54user:file_search_path(swish_pack,     swish(pack)).
   55user:file_search_path(js,             config('web/js')).
   56user:file_search_path(js,             swish_web(js)).
   57user:file_search_path(css,            swish_web(css)).
   58user:file_search_path(icons,          config('web/icons')).
   59user:file_search_path(icons,          swish_web(icons)).
   60user:file_search_path(plugin,         config('web/plugin')).
   61
   62%!  set_swish_path
   63%
   64%   Setup the `swish` search path.
   65
   66set_swish_path :-
   67    absolute_file_name(swish('swish.pl'), _,
   68                       [file_errors(fail), access(read)]), !.
   69set_swish_path :-
   70    prolog_load_context(directory, Dir),
   71    !,
   72    asserta(user:file_search_path(swish, Dir)).
   73set_swish_path :-
   74    current_prolog_flag(saved_program, true).
   75
   76%!  attach_local_packs
   77%
   78%   Attach pack submodules from swish(pack)
   79
   80attach_local_packs :-
   81    (   current_prolog_flag(swish_ide, true)
   82    ->  Duplicate = keep
   83    ;   Duplicate = replace
   84    ),
   85    attach_packs(swish_pack(.), [duplicate(Duplicate), search(first)]).
   86
   87%!  set_data_path
   88%
   89%   Setup and possibly create a directory for storing dynamic data.
   90
   91set_data_path :-
   92    absolute_file_name(data(.), _,
   93                       [ file_type(directory),
   94                         access(write),
   95                         file_errors(fail)
   96                       ]), !.
   97set_data_path :-
   98    absolute_file_name(data(.), Dir,
   99                       [ solutions(all)
  100                       ]),
  101    \+ exists_directory(Dir),
  102    catch(make_directory(Dir),
  103          error(permission_error(create,directory,Dir), _),
  104          fail), !,
  105    print_message(informational, swish(created_data_dir(Dir))).
  106set_data_path :-
  107    print_message(error, swish(no_data_dir)),
  108    halt(1).
  109
  110initialize_paths :-
  111    set_swish_path,
  112    attach_local_packs,
  113    set_data_path.
  114
  115% HTTP paths
  116
  117http:location(swish, root(.), [priority(-100)])