View source with raw 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), []).

Setup SWISH search paths

*/

   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')).
 set_swish_path
Setup the swish search path.
   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).
 attach_local_packs
Attach pack submodules from swish(pack)
   80attach_local_packs :-
   81    attach_packs(swish_pack(.), [duplicate(replace), search(first)]).
 set_data_path
Setup and possibly create a directory for storing dynamic data.
   87set_data_path :-
   88    absolute_file_name(data(.), _,
   89                       [ file_type(directory),
   90                         access(write),
   91                         file_errors(fail)
   92                       ]), !.
   93set_data_path :-
   94    absolute_file_name(data(.), Dir,
   95                       [ solutions(all)
   96                       ]),
   97    \+ exists_directory(Dir),
   98    catch(make_directory(Dir),
   99          error(permission_error(create,directory,Dir), _),
  100          fail), !,
  101    print_message(informational, swish(created_data_dir(Dir))).
  102set_data_path :-
  103    print_message(error, swish(no_data_dir)),
  104    halt(1).
  105
  106initialize_paths :-
  107    set_swish_path,
  108    attach_local_packs,
  109    set_data_path.
  110
  111% HTTP paths
  112
  113http:location(swish, root(.), [priority(-100)])