4
%% Copyright Ericsson AB 2009. All Rights Reserved.
4
%% Copyright Ericsson AB 2009-2010. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
19
19
-module(reltool_utils).
22
-compile([export_all]).
22
-export([root_dir/0, erl_libs/0, lib_dirs/1,
23
split_app_name/1, prim_consult/1,
24
default_rels/0, choose_default/3,
26
assign_image_list/1, get_latest_resize/1,
27
mod_conds/0, list_to_mod_cond/1, mod_cond_to_index/1,
28
incl_conds/0, list_to_incl_cond/1, incl_cond_to_index/1, elem_to_index/2,
29
app_dir_test/2, split_app_dir/1,
30
get_item/1, get_items/1, get_selected_items/3,
31
select_items/3, select_item/2,
33
safe_keysearch/5, print/4, return_first_error/2, add_warning/2,
35
create_dir/1, list_dir/1, read_file_info/1,
36
write_file_info/2, read_file/1, write_file/2,
37
recursive_delete/1, delete/2, recursive_copy_file/2, copy_file/2,
45
call/2, cast/2, reply/3]).
24
47
-include_lib("kernel/include/file.hrl").
25
48
-include_lib("wx/include/wx.hrl").
103
126
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
128
default_rels() ->
106
Kernel = #rel_app{name = kernel, incl_apps = []},
107
Stdlib = #rel_app{name = stdlib, incl_apps = []},
108
Sasl = #rel_app{name = sasl, incl_apps = []},
129
%%Kernel = #rel_app{name = kernel, incl_apps = []},
130
%%Stdlib = #rel_app{name = stdlib, incl_apps = []},
131
Sasl = #rel_app{name = sasl, incl_apps = []},
110
133
#rel{name = ?DEFAULT_REL_NAME,
112
rel_apps = [Kernel, Stdlib]},
136
%%rel_apps = [Kernel, Stdlib]},
113
137
#rel{name = "start_sasl",
115
rel_apps = [Kernel, Sasl, Stdlib]}
140
%%rel_apps = [Kernel, Sasl, Stdlib]}
143
choose_default(Tag, Profile, InclDefs)
144
when Profile =:= ?DEFAULT_PROFILE; InclDefs ->
146
incl_sys_filters -> ?DEFAULT_INCL_SYS_FILTERS;
147
excl_sys_filters -> ?DEFAULT_EXCL_SYS_FILTERS;
148
incl_app_filters -> ?DEFAULT_INCL_APP_FILTERS;
149
excl_app_filters -> ?DEFAULT_EXCL_APP_FILTERS;
150
embedded_app_type -> ?DEFAULT_EMBEDDED_APP_TYPE
152
choose_default(Tag, standalone, _InclDefs) ->
154
incl_sys_filters -> ?STANDALONE_INCL_SYS_FILTERS;
155
excl_sys_filters -> ?STANDALONE_EXCL_SYS_FILTERS;
156
incl_app_filters -> ?STANDALONE_INCL_APP_FILTERS;
157
excl_app_filters -> ?STANDALONE_EXCL_APP_FILTERS;
158
embedded_app_type -> ?DEFAULT_EMBEDDED_APP_TYPE
160
choose_default(Tag, embedded, _InclDefs) ->
162
incl_sys_filters -> ?EMBEDDED_INCL_SYS_FILTERS;
163
excl_sys_filters -> ?EMBEDDED_EXCL_SYS_FILTERS;
164
incl_app_filters -> ?EMBEDDED_INCL_APP_FILTERS;
165
excl_app_filters -> ?EMBEDDED_EXCL_APP_FILTERS;
166
embedded_app_type -> ?EMBEDDED_APP_TYPE
118
169
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
171
assign_image_list(ListCtrl) ->
121
172
Art = wxImageList:new(16,16),
122
[wxImageList:add(Art, wxArtProvider:getBitmap(Image, [{size, {16,16}}]))
173
[wxImageList:add(Art, wxArtProvider:getBitmap(Image, [{size, {16,16}}]))
123
174
|| Image <- ["wxART_ERROR",
125
176
"wxART_QUESTION",
277
328
case wxListCtrl:getItemText(ListCtrl, ItemNo) of
278
329
Text when Text =/= ?MISSING_APP_TEXT ->
279
get_selected_items(ListCtrl, ItemNo, [{ItemNo, Text} | Acc]);
330
get_selected_items(ListCtrl,
332
[{ItemNo, Text} | Acc]);
281
334
get_selected_items(ListCtrl, ItemNo, Acc)
306
359
select_item(ListCtrl, NewItems);
308
361
%% Some old selections are still valid. Select them again.
309
lists:foreach(fun(Item) -> select_item(ListCtrl, [Item]) end, ValidItems)
362
lists:foreach(fun(Item) -> select_item(ListCtrl, [Item]) end,
312
366
select_item(ListCtrl, [{ItemNo, Text} | Items]) ->
341
395
%% -define(SAFE(M,F,A), safe(M, F, A, ?MODULE, ?LINE)).
343
397
%% safe(M, F, A, Mod, Line) ->
344
398
%% case catch apply(M, F, A) of
345
399
%% {'EXIT', Reason} ->
514
569
do_decode_regexps(Key, [Regexp | Regexps], Acc) ->
515
570
case catch re:compile(Regexp, []) of
517
do_decode_regexps(Key, Regexps, [#regexp{source = Regexp, compiled = MP} | Acc]);
572
do_decode_regexps(Key,
574
[#regexp{source = Regexp, compiled = MP} | Acc]);
519
576
Text = lists:flatten(io_lib:format("~p", [{Key, Regexp}])),
520
577
throw({error, "Illegal option: " ++ Text})
533
590
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592
escript_foldl(Fun, Acc, File) ->
593
case escript:extract(File, [compile_source]) of
594
{ok, [_Shebang, _Comment, _EmuArgs, Body]} ->
596
{source, BeamCode} ->
597
GetInfo = fun() -> file:read_file_info(File) end,
598
GetBin = fun() -> BeamCode end,
599
{ok, Fun(".", GetInfo, GetBin, Acc)};
601
GetInfo = fun() -> file:read_file_info(File) end,
602
GetBin = fun() -> BeamCode end,
603
{ok, Fun(".", GetInfo, GetBin, Acc)};
604
{archive, ArchiveBin} ->
605
zip:foldl(Fun, Acc, {File, ArchiveBin})
611
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535
613
call(Name, Msg) when is_atom(Name) ->
536
call(whereis(Name), Msg);
614
case whereis(Name) of
616
{error, {noproc, Name}};
537
620
call(Pid, Msg) when is_pid(Pid) ->
538
621
Ref = erlang:monitor(process, Pid),
539
622
Pid ! {call, self(), Ref, Msg},