3 function res
= tcomp
(fn
)
5 %% imports components and rearranges them.
11 data
= dlmread(fn
, 3, 0);
17 cnty = repmat(x(:,1)(:), 10, 1);
26 yrs = repmat(2000:2009, 39, 1)(:);
28 res = [yrs, cnty, pop, bir, dth, imig, dmig, gq];
32 ## Copyright (C) 2005, 2006, 2007, 2008, 2009 S�ren Hauberg
34 ## This file is part of Octave.
36 ## Octave is free software; you can redistribute it and/or modify it
37 ## under the terms of the GNU General Public License as published by
38 ## the Free Software Foundation; either version 3 of the License, or (at
39 ## your option) any later version.
41 ## Octave is distributed in the hope that it will be useful, but
42 ## WITHOUT ANY WARRANTY; without even the implied warranty of
43 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 ## General Public License for more details.
46 ## You should have received a copy of the GNU General Public License
47 ## along with Octave; see the file COPYING. If not, see
48 ## <http://www.gnu.org/licenses/>.
51 ## @deftypefn {Command} pkg @var{command} @var{pkg_name}
52 ## @deftypefnx {Command} pkg @var{command} @var{option} @var{pkg_name}
53 ## This command interacts with the package manager. Different actions will
54 ## be taken depending on the value of @var{command}.
58 ## Install named packages. For example,
60 ## pkg install image-1.0.0.tar.gz
63 ## installs the package found in the file @file{image-1.0.0.tar.gz}.
65 ## The @var{option} variable can contain options that affect the manner
66 ## in which a package is installed. These options can be one or more of
70 ## The package manager will disable the dependency checking. That way it
71 ## is possible to install a package even if it depends on another package
72 ## that's not installed on the system. @strong
{Use this option with care.
}
75 ## The package manager will not automatically
load the installed package
76 ## when starting Octave
, even
if the package requests that it is.
79 ## The package manager will automatically
load the installed package when
80 ## starting Octave
, even
if the package requests that it isn
't.
83 ## A local installation is forced, even if the user has system privileges.
86 ## A global installation is forced, even if the user doesn't normally have
90 ## The package manager will
print the output of
all of the commands that are
95 ## Uninstall named packages.
For example
,
97 ## pkg uninstall
image
100 ## removes the @code
{image} package from the system.
If another installed
101 ## package depends on the @code
{image} package an
error will be issued.
102 ## The package can be uninstalled anyway by using the @code
{-nodeps
} option.
104 ## Add named packages to the
path. After loading a package it is
105 ## possible to use the functions provided by the package.
For example
,
110 ## adds the @code
{image} package to the
path. It is possible to
load all
111 ## installed packages at once with the command
116 ## Removes named packages from the
path. After unloading a package it is
117 ## no longer possible to use the functions provided by the package.
118 ## This command behaves like the @code
{load} command.
120 ## Show a list of the currently installed packages. By requesting one or two
121 ## output argument it is possible to
get a list of the currently installed
122 ## packages.
For example
,
124 ## installed_packages
= pkg list
;
127 ## returns a
cell array containing a structure
for each installed package.
130 ##
[@var
{user_packages
}, @var
{system_packages
}] = pkg list
133 ## splits the list of installed packages into those
who are installed by
134 ## the current user
, and those installed by the system administrator.
136 ## Show a short description of the named installed packages
, with the option
137 ##
'-verbose' also list functions provided by the package
, e.g.
:
139 ## pkg describe
-verbose
all
142 ## will describe
all installed packages and the functions they provide.
143 ##
If one output is requested a
cell of structure containing the
144 ## description and list of functions of each package is returned as
145 ## output rather than printed on screen
:
147 ## desc
= pkg
("describe"
, "secs1d"
, "
image"
)
150 ##
If any of the requested packages is not installed
, pkg returns an
151 ##
error, unless a second output is requested
:
153 ##
[ desc
, flag] = pkg
("describe"
, "secs1d"
, "
image"
)
156 ## @var
{flag} will take one of the values "Not installed"
, "Loaded" or
157 ## "Not loaded"
for each of the named packages.
159 ##
Set the installation prefix directory.
For example
,
161 ## pkg prefix ~
/my_octave_packages
164 ## sets the installation prefix to @file
{~
/my_octave_packages
}.
165 ## Packages will be installed in this directory.
167 ## It is possible to
get the current installation prefix by requesting an
168 ## output argument.
For example
,
173 ## The location in
which to install the architecture dependent files can be
174 ## independent specified with an addition argument.
For example
177 ## pkg prefix ~
/my_octave_packages ~
/my_arch_dep_pkgs
180 ##
Set the file in
which to look
for information on the locally
181 ## installed packages. Locally installed packages are those that are
182 ## typically available only to the current user.
For example
184 ## pkg local_list ~
/.octave_packages
186 ## It is possible to
get the current value of local_list with the following
191 ##
Set the file in
which to look
for, for information on the globally
192 ## installed packages. Globally installed packages are those that are
193 ## typically available to
all users.
For example
195 ## pkg global_list
/usr
/share
/octave
/octave_packages
197 ## It is possible to
get the current value of global_list with the following
202 ## Rebuilds the package database from the installed directories. This can
203 ## be used in cases where
for some reason the package database is corrupted.
204 ## It can also take the @code
{-auto
} and @code
{-noauto
} options to allow the
205 ## autoloading state of a package to be changed.
For example
208 ## pkg rebuild
-noauto
image
211 ## will remove the autoloading status of the
image package.
213 ## Builds a binary form of a package or packages. The binary file produced
214 ## will itself be an Octave package that can be installed normally with
215 ## @code
{pkg
}. The form of the command to build a binary package is
218 ## pkg build builddir
image-1.0.0.tar.gz @dots
{}
222 ## where @code
{builddir
} is the name of a directory where the temporary
223 ## installation will be produced and the binary packages will be found.
224 ## The options @code
{-verbose
} and @code
{-nodeps
} are respected
, while
225 ## the other options are ignored.
229 function [local_packages
, global_packages
] = pkg
(varargin)
230 ## Installation prefix
(FIXME
: what should these be on windows?
)
231 persistent user_prefix
= false
;
232 persistent prefix
= -1;
233 persistent archprefix
= -1;
234 persistent local_list
= tilde_expand
(fullfile ("~"
, ".octave_packages"
));
235 persistent global_list
= fullfile (OCTAVE_HOME
(), "share"
, "octave"
,
239 global_install
= issuperuser
();
243 prefix
= fullfile (OCTAVE_HOME
(), "share"
, "octave"
, "packages"
);
244 archprefix
= fullfile (octave_config_info
("libexecdir"
),
245 "octave"
, "packages"
);
247 prefix
= fullfile ("~"
, "octave"
);
250 prefix
= tilde_expand
(prefix
);
251 archprefix
= tilde_expand
(archprefix
);
254 available_actions
= {"list"
, "install"
, "uninstall"
, "
load"
, ...
255 "unload"
, "prefix"
, "local_list"
, ...
256 "global_list"
, "rebuild"
, "build"
,"describe"
};
258 if (length (varargin) == 0 ||
! iscellstr
(varargin))
266 for i
= 1:length (varargin)
277 global_install
= false
;
279 prefix
= tilde_expand
(fullfile ("~"
, "octave"
));
283 global_install
= true
;
285 prefix
= fullfile (OCTAVE_HOME
(), "share"
, "octave"
, "packages"
);
286 archprefix
= fullfile (octave_config_info
("libexecdir"
),
287 "octave"
, "packages"
);
289 case available_actions
290 if (strcmp (action
, "none"
))
291 action
= varargin{i
};
293 error ("
more than one action specified"
);
296 files
{end+1} = varargin{i
};
304 installed_packages
(local_list
, global_list
);
305 elseif (nargout == 1)
306 local_packages
= installed_packages
(local_list
, global_list
);
307 elseif (nargout == 2)
308 [local_packages
, global_packages
] = installed_packages
(local_list
,
311 error ("too many output arguments requested"
);
315 if (length (files
) == 0)
316 error ("you must specify at least one filename when calling
'pkg install'"
);
318 install
(files
, deps
, auto
, prefix
, archprefix
, verbose
, local_list
,
319 global_list
, global_install
);
322 if (length (files
) == 0)
323 error ("you must specify at least one package when calling
'pkg uninstall'"
);
325 uninstall
(files
, deps
, verbose
, local_list
,
326 global_list
, global_install
);
329 if (length (files
) == 0)
330 error ("you must specify at least one package
, 'all' or
'auto' when calling
'pkg load'"
);
332 load_packages
(files
, deps
, local_list
, global_list
);
335 if (length (files
) == 0)
336 error ("you must specify at least one package or
'all' when calling
'pkg unload'"
);
338 unload_packages
(files
, deps
, local_list
, global_list
);
341 if (length (files
) == 0 && nargout == 0)
342 printf
("Installation prefix
: %s\n", prefix);
343 printf
("Architecture dependent prefix
: %s\n", archprefix);
344 elseif (length (files
) == 0 && nargout >= 1)
345 local_packages
= prefix
;
346 global_packages
= archprefix
;
347 elseif (length (files
) >= 1 && nargout <= 2 && ischar (files
{1}))
349 prefix
= absolute_pathname
(prefix
);
350 local_packages
= prefix
;
352 if (length (files
) >= 2 && ischar (files
{2}))
353 archprefix
= files
{2};
355 archprefix
= absolute_pathname
(archprefix
);
358 warning
("creating the directory
%s\n", archprefix);
359 archprefix
= absolute_pathname
(archprefix
);
361 global_packages
= archprefix
;
364 error ("you must specify a prefix directory
, or request an output argument"
);
368 if (length (files
) == 0 && nargout == 0)
370 elseif (length (files
) == 0 && nargout == 1)
371 local_packages
= local_list
;
372 elseif (length (files
) == 1 && nargout == 0 && ischar (files
{1}))
374 local_list
= absolute_pathname
(files
{1});
376 ## Force file to be created
377 fclose (fopen (files
{1}, "wt"
));
378 local_list
= absolute_pathname
(files
{1});
381 error ("you must specify a local_list file
, or request an output argument"
);
385 if (length (files
) == 0 && nargout == 0)
387 elseif (length (files
) == 0 && nargout == 1)
388 local_packages
= global_list
;
389 elseif (length (files
) == 1 && nargout == 0 && ischar (files
{1}))
391 global_list
= absolute_pathname
(files
{1});
393 ## Force file to be created
394 fclose (fopen (files
{1}, "wt"
));
395 global_list
= absolute_pathname
(files
{1});
398 error ("you must specify a global_list file
, or request an output argument"
);
403 global_packages
= rebuild
(prefix
, archprefix
, global_list
, files
,
405 global_packages
= save_order
(global_packages
);
406 save (global_list
, "global_packages"
);
408 local_packages
= global_packages
;
411 local_packages
= rebuild
(prefix
, archprefix
, local_list
, files
, auto
,
413 local_packages
= save_order
(local_packages
);
414 save (local_list
, "local_packages"
);
416 clear ("local_packages"
);
421 if (length (files
) < 2)
422 error ("you must specify at least the build directory and one filename
\nwhen calling
'pkg build'"
);
424 build
(files
, deps
, auto
, verbose
);
427 if (length (files
) == 0)
428 error ("you must specify at least one package or
'all' when calling
'pkg describe'"
);
430 ## FIXME
: the name of the output variables is inconsistent
431 ## with their content
434 describe
(files
, verbose
, local_list
, global_list
);
436 pkg_desc_list
= describe
(files
, verbose
, local_list
, ...
438 local_packages
= pkg_desc_list
;
440 [pkg_desc_list
, flag] = describe
(files
, verbose
, local_list
, ...
442 local_packages
= pkg_desc_list
;
443 global_packages
= flag;
445 error ("you can request at most two outputs when calling
'pkg describe'"
);
449 error ("you must specify a valid action
for 'pkg'. See
'help pkg' for details"
);
453 function descriptions
= rebuild
(prefix
, archprefix
, list
, files
, auto
, verbose
)
455 [dirlist
, err
, msg
] = readdir
(prefix
);
457 error ("couldn
't read directory %s: %s", prefix, msg);
459 ## the two first entries of dirlist are "." and ".."
462 old_descriptions = installed_packages (list, list);
466 dirlist = glob (cellfun(@(x) cstrcat(x, '-*'), files, 'UniformOutput
', 0));
467 unwind_protect_cleanup
472 for k = 1:length (dirlist)
473 descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION");
475 printf ("recreating package description from %s\n", dirlist{k});
477 if (exist (descfile, "file"))
478 desc = get_description (descfile);
479 desc.dir = fullfile (prefix, dirlist{k});
480 desc.archprefix = fullfile (archprefix, cstrcat (desc.name, "-",
483 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file"))
484 unlink (fullfile (desc.dir, "packinfo", ".autoload"));
490 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt"));
493 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file"))
499 descriptions{end + 1} = desc;
501 warning ("directory %s is not a valid package", dirlist{k});
505 if (! isempty (files))
506 ## We are rebuilding for a particular package(s) so we should take
507 ## care to keep the other untouched packages in the descriptions
508 descriptions = {descriptions{:}, old_descriptions{:}};
511 for i = 1:length (descriptions)
515 for j = (i+1):length (descriptions)
519 if (strcmp (descriptions{i}.name, descriptions{j}.name))
525 descriptions (dup) = [];
530 function build (files, handle_deps, autoload, verbose)
531 if (length (files) < 1)
532 error ("insufficient number of files");
535 if (! exist (builddir, "dir"))
536 warning ("creating build directory %s", builddir);
537 [status, msg] = mkdir (builddir);
539 error ("could not create installation directory: %s", msg);
542 builddir = absolute_pathname (builddir);
543 installdir = fullfile (builddir, "install");
544 if (! exist (installdir, "dir"))
545 [status, msg] = mkdir (installdir);
547 error ("could not create installation directory: %s", msg);
551 buildlist = fullfile (builddir, "octave_packages");
552 install (files, handle_deps, autoload, installdir, installdir, verbose,
553 buildlist, "", false);
555 repackage (builddir, buildlist);
556 unwind_protect_cleanup
557 unload_packages ({"all"}, handle_deps, buildlist, "");
558 if (exist (installdir, "dir"))
561 if (exist (buildlist, "file"))
567 function install (files, handle_deps, autoload, prefix, archprefix, verbose,
568 local_list, global_list, global_install)
570 ## Check that the directory in prefix exist. If it doesn't
: create it
!
571 if (! exist (prefix
, "
dir"
))
572 warning
("creating installation directory
%s", prefix);
573 [status
, msg
] = mkdir
(prefix
);
575 error ("could not create installation directory
: %s", msg);
579 ##
Get the list of installed packages.
580 [local_packages
, global_packages
] = installed_packages
(local_list
,
583 installed_pkgs_lst
= {local_packages
{:}, global_packages
{:}};
586 packages
= global_packages
;
588 packages
= local_packages
;
591 ## Uncompress the packages and read the DESCRIPTION files.
592 tmpdirs
= packdirs
= descriptions
= {};
594 ## Warn about non existent files.
595 for i
= 1:length (files
)
596 if (isempty (glob
(files
{i
})))
597 warning
("file
%s does not exist", files{i});
601 ## Unpack the package files and read the DESCRIPTION files.
602 files
= glob
(files
);
603 packages_to_uninstall
= [];
604 for i
= 1:length (files
)
607 if (exist (tgz
, "file"
))
608 ## Create a temporary directory.
610 tmpdirs
{end+1} = tmpdir
;
612 printf
("mkdir
(%s)\n", tmpdir);
614 [status
, msg
] = mkdir
(tmpdir
);
616 error ("couldn
't create temporary directory: %s", msg);
619 ## Uncompress the package.
621 printf ("untar (%s, %s)\n", tgz, tmpdir);
625 ## Get the name of the directories produced by tar.
626 [dirlist, err, msg] = readdir (tmpdir);
628 error ("couldn't read directory produced by tar
: %s", msg);
631 if (length (dirlist
) > 3)
632 error ("bundles of packages are not allowed"
)
636 ## The filename pointed to an uncompressed package to begin with.
637 if (exist (tgz
, "
dir"
))
638 dirlist
= {"."
, ".."
, tgz
};
641 if (exist (tgz
, "file"
) ||
exist (tgz
, "
dir"
))
642 ## The two first entries of dirlist are "." and "..".
643 if (exist (tgz
, "file"
))
644 packdir
= fullfile (tmpdir
, dirlist
{3});
646 packdir
= fullfile (pwd(), dirlist
{3});
648 packdirs
{end+1} = packdir
;
650 ## Make sure the package contains necessary files.
651 verify_directory
(packdir
);
653 ## Read the DESCRIPTION file.
654 filename
= fullfile (packdir
, "DESCRIPTION"
);
655 desc
= get_description
(filename
);
657 ## Verify that package name corresponds with filename.
658 [dummy
, nm
] = fileparts (tgz
);
659 if ((length (nm
) >= length (desc.name
))
660 && ! strcmp (desc.name
, nm
(1:length(desc.name
))))
661 error ("package name
'%s' doesn
't correspond to its filename '%s'",
665 ##
Set default installation directory.
666 desc.
dir = fullfile (prefix
, cstrcat
(desc.name
, "
-"
, desc.
version));
668 ##
Set default architectire dependent installation directory.
669 desc.archprefix
= fullfile (archprefix
, cstrcat
(desc.name
, "
-"
,
673 descriptions
{end+1} = desc
;
675 ## Are
any of the new packages already installed?
676 ##
If so we
'll remove the old version.
677 for j = 1:length (packages)
678 if (strcmp (packages{j}.name, desc.name))
679 packages_to_uninstall(end+1) = j;
685 ## Something went wrong, delete tmpdirs.
686 for i = 1:length (tmpdirs)
689 rethrow (lasterror ());
692 ## Check dependencies.
696 for i = 1:length (descriptions)
697 desc = descriptions{i};
698 idx2 = complement (i, 1:length(descriptions));
700 ## Global installation is not allowed to have dependencies on locally
701 ## installed packages.
702 idx1 = complement (packages_to_uninstall,
703 1:length(global_packages));
704 pseudo_installed_packages = {global_packages{idx1}, ...
707 idx1 = complement (packages_to_uninstall,
708 1:length(local_packages));
709 pseudo_installed_packages = {local_packages{idx1}, ...
710 global_packages{:}, ...
713 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages);
714 ## Are there any unsatisfied dependencies?
715 if (! isempty (bad_deps))
717 for i = 1:length (bad_deps)
719 error_text = cstrcat (error_text, " ", desc.name, " needs ",
720 dep.package, " ", dep.operator, " ",
726 ## Did we find any unsatisfied dependencies?
728 error ("the following dependencies where unsatisfied:\n %s", error_text);
732 ## Prepare each package for installation.
734 for i = 1:length (descriptions)
735 desc = descriptions{i};
737 prepare_installation (desc, pdir);
738 configure_make (desc, pdir, verbose);
741 ## Something went wrong, delete tmpdirs.
742 for i = 1:length (tmpdirs)
745 rethrow (lasterror ());
748 ## Uninstall the packages that will be replaced.
750 for i = packages_to_uninstall
752 uninstall ({global_packages{i}.name}, false, verbose, local_list,
753 global_list, global_install);
755 uninstall ({local_packages{i}.name}, false, verbose, local_list,
756 global_list, global_install);
760 ## Something went wrong, delete tmpdirs.
761 for i = 1:length (tmpdirs)
764 rethrow (lasterror ());
767 ## Install each package.
769 for i = 1:length (descriptions)
770 desc = descriptions{i};
772 copy_files (desc, pdir, global_install);
773 create_pkgadddel (desc, pdir, "PKG_ADD", global_install);
774 create_pkgadddel (desc, pdir, "PKG_DEL", global_install);
775 finish_installation (desc, pdir, global_install);
776 generate_lookfor_cache (desc);
779 ## Something went wrong, delete tmpdirs.
780 for i = 1:length (tmpdirs)
783 for i = 1:length (descriptions)
784 rm_rf (descriptions{i}.dir);
785 rm_rf (getarchdir (descriptions{i}));
787 rethrow (lasterror ());
790 ## Check if the installed directory is empty. If it is remove it
792 for i = length (descriptions):-1:1
793 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) &&
794 dirempty (getarchdir (descriptions{i})))
795 warning ("package %s is empty\n", descriptions{i}.name);
796 rm_rf (descriptions{i}.dir);
797 rm_rf (getarchdir (descriptions{i}));
798 descriptions(i) = [];
802 ## If the package requested that it is autoloaded, or the installer
803 ## requested that it is, then mark the package as autoloaded.
804 for i = length (descriptions):-1:1
805 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i))))
806 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo",
807 ".autoload"), "wt"));
808 descriptions{i}.autoload = 1;
812 ## Add the packages to the package list.
815 idx = complement (packages_to_uninstall, 1:length(global_packages));
816 global_packages = save_order ({global_packages{idx}, descriptions{:}});
817 save (global_list, "global_packages");
818 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
820 idx = complement (packages_to_uninstall, 1:length(local_packages));
821 local_packages = save_order ({local_packages{idx}, descriptions{:}});
822 save (local_list, "local_packages");
823 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
826 ## Something went wrong, delete tmpdirs.
827 for i = 1:length (tmpdirs)
830 for i = 1:length (descriptions)
831 rm_rf (descriptions{i}.dir);
834 printf ("error: couldn't append to
%s\n", global_list);
836 printf
("
error: couldn
't append to %s\n", local_list);
838 rethrow (lasterror ());
841 ## All is well, let's clean up.
842 for i
= 1:length (tmpdirs
)
843 [status
, msg
] = rm_rf
(tmpdirs
{i
});
845 warning
("couldn
't clean up after my self: %s\n", msg);
849 ## Add the newly installed packages to the path, so the user
850 ## can begin using them. Only load them if they are marked autoload.
851 if (length (descriptions) > 0)
853 for i = 1:length (descriptions)
854 if (isautoload (descriptions(i)))
855 nm = descriptions{i}.name;
856 for j = 1:length (installed_pkgs_lst)
857 if (strcmp (nm, installed_pkgs_lst{j}.name))
864 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst,
869 function uninstall (pkgnames, handle_deps, verbose, local_list,
870 global_list, global_install)
871 ## Get the list of installed packages.
872 [local_packages, global_packages] = installed_packages(local_list,
875 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
877 installed_pkgs_lst = local_packages;
880 num_packages = length (installed_pkgs_lst);
882 for i = 1:num_packages
883 cur_name = installed_pkgs_lst{i}.name;
884 if (any (strcmp (cur_name, pkgnames)))
885 delete_idx(end+1) = i;
889 ## Are all the packages that should be uninstalled already installed?
890 if (length (delete_idx) != length (pkgnames))
892 ## Try again for a locally installed package.
893 installed_pkgs_lst = local_packages;
895 num_packages = length (installed_pkgs_lst);
897 for i = 1:num_packages
898 cur_name = installed_pkgs_lst{i}.name;
899 if (any (strcmp (cur_name, pkgnames)))
900 delete_idx(end+1) = i;
903 if (length (delete_idx) != length (pkgnames))
904 ## FIXME: We should have a better error message.
905 warning ("some of the packages you want to uninstall are not installed");
908 ## FIXME: We should have a better error message.
909 warning ("some of the packages you want to uninstall are not installed");
913 ## Compute the packages that will remain installed.
914 idx = complement (delete_idx, 1:num_packages);
915 remaining_packages = {installed_pkgs_lst{idx}};
917 ## Check dependencies.
920 for i = 1:length (remaining_packages)
921 desc = remaining_packages{i};
922 bad_deps = get_unsatisfied_deps (desc, remaining_packages);
924 ## Will the uninstallation break any dependencies?
925 if (! isempty (bad_deps))
926 for i = 1:length (bad_deps)
928 error_text = cstrcat (error_text, " ", desc.name, " needs ",
929 dep.package, " ", dep.operator, " ",
935 if (! isempty (error_text))
936 error ("the following dependencies where unsatisfied:\n %s", error_text);
940 ## Delete the directories containing the packages.
942 desc = installed_pkgs_lst{i};
943 ## If an 'on_uninstall.m
' exist, call it!
944 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file"))
946 cd (fullfile (desc.dir, "packinfo"));
950 ## Do the actual deletion.
953 if (exist (getarchdir (desc)))
954 rmpath (getarchdir (desc));
957 if (exist (desc.dir, "dir"))
958 [status, msg] = rm_rf (desc.dir);
960 error ("couldn't
delete directory
%s: %s", desc.dir, msg);
962 [status
, msg
] = rm_rf
(getarchdir
(desc
));
964 error ("couldn
't delete directory %s: %s", getarchdir (desc), msg);
966 if (dirempty (desc.archprefix))
967 rm_rf (desc.archprefix);
970 warning ("directory %s previously lost", desc.dir);
974 ## Write a new ~/.octave_packages.
976 if (length (remaining_packages) == 0)
977 unlink (global_list);
979 global_packages = save_order (remaining_packages);
980 save (global_list, "global_packages");
983 if (length (remaining_packages) == 0)
986 local_packages = save_order (remaining_packages);
987 save (local_list, "local_packages");
993 function [pkg_desc_list, flag] = describe (pkgnames, verbose,
994 local_list, global_list)
996 ## Get the list of installed packages.
997 installed_pkgs_lst = installed_packages(local_list, global_list);
998 num_packages = length (installed_pkgs_lst);
1001 describe_all = false;
1002 if (any (strcmp ("all", pkgnames)))
1003 describe_all = true;
1004 flag(1:num_packages) = {"Not Loaded"};
1005 num_pkgnames = num_packages;
1007 num_pkgnames = length (pkgnames);
1008 flag(1:num_pkgnames) = {"Not installed"};
1011 for i = 1:num_packages
1012 curr_name = installed_pkgs_lst{i}.name;
1016 name_pos = find(strcmp (curr_name, pkgnames));
1019 if (! isempty (name_pos))
1020 if (installed_pkgs_lst{i}.loaded)
1021 flag{name_pos} = "Loaded";
1023 flag{name_pos} = "Not loaded";
1026 pkg_desc_list{name_pos}.name = installed_pkgs_lst{i}.name;
1027 pkg_desc_list{name_pos}.version = installed_pkgs_lst{i}.version;
1028 pkg_desc_list{name_pos}.description = installed_pkgs_lst{i}.description;
1029 pkg_desc_list{name_pos}.provides = parse_pkg_idx (installed_pkgs_lst{i}.dir);
1034 non_inst = find (strcmp (flag, "Not installed"));
1035 if (! isempty (non_inst))
1037 non_inst_str = sprintf (" %s ", pkgnames{non_inst});
1038 error ("some packages are not installed: %s", non_inst_str);
1040 pkg_desc_list{non_inst} = struct ("name", {}, "description",
1041 {}, "provides", {});
1046 for i = 1:num_pkgnames
1047 print_package_description (pkg_desc_list{i}.name,
1048 pkg_desc_list{i}.version,
1049 pkg_desc_list{i}.provides,
1050 pkg_desc_list{i}.description,
1057 ## AUXILIARY FUNCTIONS
1059 ## Read an INDEX file.
1060 function [pkg_idx_struct] = parse_pkg_idx (packdir)
1062 index_file = fullfile (packdir, "packinfo", "INDEX");
1064 if (! exist (index_file, "file"))
1065 error ("could not find any INDEX file in directory %s, try 'pkg rebuild
all' to generate missing INDEX files", packdir);
1069 [fid, msg] = fopen (index_file, "r");
1071 error ("the INDEX file %s could not be read: %s",
1076 pkg_idx_struct{1}.category = "Uncategorized";
1077 pkg_idx_struct{1}.functions = {};
1080 while (isempty (strfind (line, ">>")) && ! feof (fid))
1084 while (! feof (fid) || line != -1)
1085 if (! any (! isspace (line)) || line(1) == "#" || any (line == "="))
1086 ## Comments, blank lines or comments about unimplemented
1087 ## functions: do nothing
1088 ## FIXME: probably comments and pointers to external functions
1089 ## could be treated better when printing to screen?
1090 elseif (! isempty (strfind (line, ">>")))
1091 ## Skip package name and description as they are in DESCRIPTION
1093 elseif (! isspace (line(1)))
1095 if (! isempty (pkg_idx_struct{cat_num}.functions))
1096 pkg_idx_struct{++cat_num}.functions = {};
1098 pkg_idx_struct{cat_num}.category = deblank (line);
1101 while (any (! isspace (line)))
1102 [fun_name, line] = strtok (line);
1103 pkg_idx_struct{cat_num}.functions{end+1} = deblank (fun_name);
1111 function print_package_description (pkg_name, pkg_ver, pkg_idx_struct,
1112 pkg_desc, status, verbose)
1114 printf ("---\nPackage name:\n\t%s\n", pkg_name);
1115 printf ("Version:\n\t%s\n", pkg_ver);
1116 printf ("Short description:\n\t%s\n", pkg_desc);
1117 printf ("Status:\n\t%s\n", status);
1119 printf ("---\nProvides:\n");
1120 for i = 1:length(pkg_idx_struct)
1121 if (! isempty (pkg_idx_struct{i}.functions))
1122 printf ("%s\n", pkg_idx_struct{i}.category);
1123 for j = 1:length(pkg_idx_struct{i}.functions)
1124 printf ("\t%s\n", pkg_idx_struct{i}.functions{j});
1133 function pth = absolute_pathname (pth)
1134 [status, msg, msgid] = fileattrib (pth);
1136 error ("could not find the file or path %s", pth);
1142 function repackage (builddir, buildlist)
1143 packages = installed_packages (buildlist, buildlist);
1146 for i = 1 : length(packages)
1151 mkdir (fullfile (pack.name, "inst"));
1152 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst"));
1153 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name);
1154 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file"))
1155 unlink (fullfile (pack.name, "inst","packinfo", ".autoload"));
1157 rmdir (fullfile (pack.name, "inst", "packinfo"));
1158 if (exist (fullfile (pack.name, "inst", "doc"), "dir"))
1159 movefile (fullfile (pack.name, "inst", "doc"), pack.name);
1161 if (exist (fullfile (pack.name, "inst", "bin"), "dir"))
1162 movefile (fullfile (pack.name, "inst", "bin"), pack.name);
1164 archdir = fullfile (pack.archprefix, cstrcat (pack.name, "-",
1165 pack.version), getarch ());
1166 if (exist (archdir, "dir"))
1167 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file"))
1168 unlink (fullfile (pack.name, "inst", "PKG_ADD"));
1170 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file"))
1171 unlink (fullfile (pack.name, "inst", "PKG_DEL"));
1173 if (exist (fullfile (archdir, "PKG_ADD"), "file"))
1174 movefile (fullfile (archdir, "PKG_ADD"),
1175 fullfile (pack.name, "PKG_ADD"));
1177 if (exist (fullfile (archdir, "PKG_DEL"), "file"))
1178 movefile (fullfile (archdir, "PKG_DEL"),
1179 fullfile (pack.name, "PKG_DEL"));
1182 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file"))
1183 movefile (fullfile (pack.name, "inst", "PKG_ADD"),
1184 fullfile (pack.name, "PKG_ADD"));
1186 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file"))
1187 movefile (fullfile (pack.name, "inst", "PKG_DEL"),
1188 fullfile (pack.name, "PKG_DEL"));
1191 tfile = cstrcat (pack.name, "-", pack.version, ".tar");
1192 tar (tfile, pack.name);
1197 warning ("failed to compress %s", tfile);
1199 unwind_protect_cleanup
1200 if (exist (pack.name, "dir"))
1208 function auto = isautoload (desc)
1210 if (isfield (desc{1}, "autoload"))
1211 a = desc{1}.autoload;
1212 if ((isnumeric (a) && a > 0)
1213 || (ischar (a) && (strcmpi (a, "true")
1214 || strcmpi (a, "on")
1215 || strcmpi (a, "yes")
1216 || strcmpi (a, "1"))))
1222 function prepare_installation (desc, packdir)
1223 ## Is there a pre_install to call?
1224 if (exist (fullfile (packdir, "pre_install.m"), "file"))
1232 rethrow (lasterror ());
1236 ## If the directory "inst" doesn't
exist, we create it.
1237 inst_dir
= fullfile (packdir
, "inst"
);
1238 if (! exist (inst_dir
, "
dir"
))
1239 [status
, msg
] = mkdir
(inst_dir
);
1242 error ("the
'inst' directory did not
exist and could not be created
: %s",
1248 function configure_make
(desc
, packdir
, verbose
)
1249 ## Perform .
/configure
, make
, make install in "src".
1250 if (exist (fullfile (packdir
, "src"
), "
dir"
))
1251 src
= fullfile (packdir
, "src"
);
1253 if (exist (fullfile (src
, "configure"
), "file"
))
1255 if (isempty (getenv ("CC"
)))
1256 flags
= cstrcat
(flags
, " CC
=\""
, octave_config_info
("CC"
), "
\""
);
1258 if (isempty (getenv ("CXX"
)))
1259 flags
= cstrcat
(flags
, " CXX
=\""
, octave_config_info
("CXX"
), "
\""
);
1261 if (isempty (getenv ("AR"
)))
1262 flags
= cstrcat
(flags
, " AR
=\""
, octave_config_info
("AR"
), "
\""
);
1264 if (isempty (getenv ("RANLIB"
)))
1265 flags
= cstrcat
(flags
, " RANLIB
=\""
, octave_config_info
("RANLIB"
), "
\""
);
1267 [status
, output
] = shell
(strcat
("
cd '", src, "'; .
/configure
--prefix
=\""
,
1268 desc.
dir, "
\""
, flags
));
1271 error ("the configure
script returned the following
error: %s", output);
1273 printf
("
%s", output);
1279 if (exist (fullfile (src
, "Makefile"
), "file"
))
1280 [status
, output
] = shell
(cstrcat
("export INSTALLDIR
=\""
, desc.
dir,
1281 "
\"; make
-C
'", src, "'"
));
1284 error ("
'make' returned the following
error: %s", output);
1286 printf
("
%s", output);
1290 ## Copy files to "inst" and "inst
/arch"
(this is instead of
'make
1292 files
= fullfile (src
, "FILES"
);
1293 instdir
= fullfile (packdir
, "inst"
);
1294 archdir
= fullfile (packdir
, "inst"
, getarch
());
1297 if (exist (files
, "file"
))
1298 [fid
, msg
] = fopen (files
, "r"
);
1300 error ("couldn
't open %s: %s", files, msg);
1302 filenames = char (fread (fid))';
1304 if (filenames
(end) == "
\n"
)
1305 filenames
(end) = [];
1307 filenames
= split_by
(filenames
, "
\n"
);
1309 for i
= 1:length (filenames
)
1310 if (! all (isspace (filenames
{i
})))
1311 filenames
{i
} = fullfile (src
, filenames
{i
});
1313 delete_idx
(end+1) = i
;
1316 filenames
(delete_idx
) = [];
1318 m
= dir (fullfile (src
, "
*.m"
));
1319 oct
= dir (fullfile (src
, "
*.oct"
));
1320 mex
= dir (fullfile (src
, "
*.mex"
));
1322 filenames
= cellfun
(@
(x
) fullfile (src
, x
),
1323 {m.name
, oct.name
, mex.name
},
1324 "UniformOutput"
, false
);
1327 ## Split into architecture dependent and independent files.
1328 if (isempty (filenames
))
1331 idx
= cellfun
(@is_architecture_dependent
, filenames
);
1333 archdependent
= filenames
(idx
);
1334 archindependent
= filenames
(!idx
);
1337 if (! all (isspace ([filenames
{:}])))
1338 if (! exist (instdir
, "
dir"
)) # fixindent
1341 if (! all (isspace ([archindependent
{:}])))
1343 printf
("copyfile"
);
1344 printf
("
%s", archindependent{:});
1345 printf
("
%s\n", instdir);
1347 [status
, output
] = copyfile
(archindependent
, instdir
);
1350 error ("Couldn
't copy files from 'src
' to 'inst
': %s", output);
1353 if (! all (isspace ([archdependent{:}])))
1355 printf ("copyfile");
1356 printf (" %s", archdependent{:});
1357 printf (" %s\n", archdir);
1359 if (! exist (archdir, "dir"))
1362 [status, output] = copyfile (archdependent, archdir);
1365 error ("Couldn't copy files from
'src' to
'inst': %s", output);
1372 function pkg
= extract_pkg
(nm
, pat
)
1373 fid
= fopen (nm
, "rt"
);
1376 while (! feof (fid
))
1379 t
= regexp
(ln
, pat
, "tokens"
);
1381 pkg
= cstrcat
(pkg
, "
\n"
, t
{1}{1});
1385 if (! isempty (pkg
))
1386 pkg
= cstrcat
(pkg
, "
\n"
);
1392 function create_pkgadddel
(desc
, packdir
, nm
, global_install
)
1393 instpkg
= fullfile (desc.
dir, nm
);
1394 instfid
= fopen (instpkg
, "wt"
);
1395 ##
If it is exists
, most of the PKG_
* file should go into the
1396 ## architecture dependent directory so that the autoload
/mfilename
1397 ## commands work as expected. The only part that doesn
't is the
1398 ## part in the main directory.
1399 archdir = fullfile (getarchprefix (desc), cstrcat (desc.name, "-",
1400 desc.version), getarch ());
1401 if (exist (getarchdir (desc, global_install), "dir"))
1402 archpkg = fullfile (getarchdir (desc, global_install), nm);
1403 archfid = fopen (archpkg, "at");
1409 if (archfid >= 0 && instfid >= 0)
1410 ## Search all dot-m files for PKG commands.
1411 lst = dir (fullfile (packdir, "inst", "*.m"));
1412 for i = 1:length (lst)
1413 nam = fullfile (packdir, "inst", lst(i).name);
1414 fwrite (instfid, extract_pkg (nam, ['^
[#
%][#%]* *' nm ': *(.*)$']));
1417 ## Search
all C
++ source files
for PKG commands.
1418 lst
= dir (fullfile (packdir
, "src"
, "
*.cc"
));
1419 for i
= 1:length (lst
)
1420 nam
= fullfile (packdir
, "src"
, lst
(i
).name
);
1421 fwrite (archfid
, extract_pkg
(nam
, ['^//* *' nm
': *(.*)$']));
1422 fwrite (archfid
, extract_pkg
(nam
, ['^/\** *' nm
': *(.*) *\*/$']));
1425 ## Add developer included PKG commands.
1426 packdirnm
= fullfile (packdir
, nm
);
1427 if (exist (packdirnm
, "file"
))
1428 fid
= fopen (packdirnm
, "rt"
);
1430 while (! feof (fid
))
1433 fwrite (archfid
, ln
);
1440 ##
If the files is empty remove it.
1447 if (instfid
!= archfid
)
1457 function copy_files
(desc
, packdir
, global_install
)
1458 ## Create the installation directory.
1459 if (! exist (desc.
dir, "
dir"
))
1460 [status
, output
] = mkdir
(desc.
dir);
1462 error ("couldn
't create installation directory %s : %s",
1467 octfiledir = getarchdir (desc);
1469 ## Copy the files from "inst" to installdir.
1470 instdir = fullfile (packdir, "inst");
1471 if (! dirempty (instdir))
1472 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir);
1475 error ("couldn't copy files to the installation directory"
);
1477 if (exist (fullfile (desc.
dir, getarch
()), "
dir"
) &&
1478 ! strcmp (fullfile (desc.
dir, getarch
()), octfiledir
))
1479 if (! exist (octfiledir
, "
dir"
))
1480 ## Can be required to create upto three levels of dirs.
1481 octm1
= fileparts (octfiledir
);
1482 if (! exist (octm1
, "
dir"
))
1483 octm2
= fileparts (octm1
);
1484 if (! exist (octm2
, "
dir"
))
1485 octm3
= fileparts (octm2
);
1486 if (! exist (octm3
, "
dir"
))
1487 [status
, output
] = mkdir
(octm3
);
1490 error ("couldn
't create installation directory %s : %s",
1494 [status, output] = mkdir (octm2);
1497 error ("couldn't create installation directory
%s : %s",
1501 [status
, output
] = mkdir
(octm1
);
1504 error ("couldn
't create installation directory %s : %s",
1508 [status, output] = mkdir (octfiledir);
1511 error ("couldn't create installation directory
%s : %s",
1512 octfiledir
, output
);
1515 [status
, output
] = movefile
(fullfile (desc.
dir, getarch
(), "
*"
),
1517 rm_rf
(fullfile (desc.
dir, getarch
()));
1522 error ("couldn
't copy files to the installation directory");
1528 ## Create the "packinfo" directory.
1529 packinfo = fullfile (desc.dir, "packinfo");
1530 [status, msg] = mkdir (packinfo);
1534 error ("couldn't create packinfo directory
: %s", msg);
1537 ## Copy DESCRIPTION.
1538 [status
, output
] = copyfile
(fullfile (packdir
, "DESCRIPTION"
), packinfo
);
1542 error ("couldn
't copy DESCRIPTION: %s", output);
1546 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo);
1550 error ("couldn't copy COPYING
: %s", output);
1553 ##
If the file ChangeLog exists
, copy it.
1554 changelog_file
= fullfile (packdir
, "ChangeLog"
);
1555 if (exist (changelog_file
, "file"
))
1556 [status
, output
] = copyfile
(changelog_file
, packinfo
);
1560 error ("couldn
't copy ChangeLog file: %s", output);
1564 ## Is there an INDEX file to copy or should we generate one?
1565 index_file = fullfile (packdir, "INDEX");
1566 if (exist(index_file, "file"))
1567 [status, output] = copyfile (index_file, packinfo);
1571 error ("couldn't copy INDEX file
: %s", output);
1575 write_index
(desc
, fullfile (packdir
, "inst"
),
1576 fullfile (packinfo
, "INDEX"
), global_install
);
1580 rethrow
(lasterror
());
1584 ## Is there an
'on_uninstall.m' to install?
1585 fon_uninstall
= fullfile (packdir
, "on_uninstall.m"
);
1586 if (exist (fon_uninstall
, "file"
))
1587 [status
, output
] = copyfile
(fon_uninstall
, packinfo
);
1591 error ("couldn
't copy on_uninstall.m: %s", output);
1595 ## Is there a doc/ directory that needs to be installed?
1596 docdir = fullfile (packdir, "doc");
1597 if (exist (docdir, "dir") && ! dirempty (docdir))
1598 [status, output] = copyfile (docdir, desc.dir);
1601 ## Is there a bin/ directory that needs to be installed?
1602 ## FIXME: Need to treat architecture dependent files in bin/
1603 bindir = fullfile (packdir, "bin");
1604 if (exist (bindir, "dir") && ! dirempty (bindir))
1605 [status, output] = copyfile (bindir, desc.dir);
1609 function finish_installation (desc, packdir, global_install)
1610 ## Is there a post-install to call?
1611 if (exist (fullfile (packdir, "post_install.m"), "file"))
1615 post_install (desc);
1620 rm_rf (getarchdir (desc), global_install);
1621 rethrow (lasterror ());
1626 function generate_lookfor_cache (desc)
1627 dirs = split_by (genpath (desc.dir), pathsep ());
1628 for i = 1 : length (dirs)
1629 gen_doc_cache (fullfile (dirs{i}, "doc-cache"), dirs{i});
1633 ## Make sure the package contains the essential files.
1634 function verify_directory (dir)
1635 needed_files = {"COPYING", "DESCRIPTION"};
1636 for f = needed_files
1637 if (! exist (fullfile (dir, f{1}), "file"))
1638 error ("package is missing file: %s", f{1});
1643 ## Parse the DESCRIPTION file.
1644 function desc = get_description (filename)
1645 [fid, msg] = fopen (filename, "r");
1647 error ("the DESCRIPTION file %s could not be read: %s", filename, msg);
1655 ## Comments, do nothing.
1656 elseif (isspace(line(1)))
1657 ## Continuation lines
1658 if (exist ("keyword", "var") && isfield (desc, keyword))
1659 desc.(keyword) = cstrcat (desc.(keyword), " ", rstrip(line));
1662 ## Keyword/value pair
1663 colon = find (line == ":");
1664 if (length (colon) == 0)
1665 disp ("skipping line");
1668 keyword = tolower (strip (line(1:colon-1)));
1669 value = strip (line (colon+1:end));
1670 if (length (value) == 0)
1672 error ("the keyword %s has an empty value", desc.keywords{end});
1674 desc.(keyword) = value;
1681 ## Make sure all is okay.
1682 needed_fields = {"name", "version", "date", "title", ...
1683 "author", "maintainer", "description"};
1684 for f = needed_fields
1685 if (! isfield (desc, f{1}))
1686 error ("description is missing needed field %s", f{1});
1689 desc.version = fix_version (desc.version);
1690 if (isfield (desc, "depends"))
1691 desc.depends = fix_depends (desc.depends);
1695 desc.name = tolower (desc.name);
1698 ## Make sure the version string v is a valid x.y.z version string
1699 ## Examples: "0.1" => "0.1.0", "monkey" => error(...).
1700 function out = fix_version (v)
1701 dots = find (v == ".");
1702 if (length (dots) == 1)
1703 major = str2num (v(1:dots-1));
1704 minor = str2num (v(dots+1:end));
1705 if (length (major) != 0 && length (minor) != 0)
1706 out = sprintf ("%d.%d.0", major, minor);
1709 elseif (length (dots) == 2)
1710 major = str2num (v(1:dots(1)-1));
1711 minor = str2num (v(dots(1)+1:dots(2)-1));
1712 rev = str2num (v(dots(2)+1:end));
1713 if (length (major) != 0 && length (minor) != 0 && length (rev) != 0)
1714 out = sprintf ("%d.%d.%d", major, minor, rev);
1718 error ("bad version string: %s", v);
1721 ## Make sure the depends field is of the right format.
1722 ## This function returns a cell of structures with the following fields:
1723 ## package, version, operator
1724 function deps_cell = fix_depends (depends)
1725 deps = split_by (tolower (depends), ",");
1726 deps_cell = cell (1, length (deps));
1728 ## For each dependency.
1729 for i = 1:length (deps)
1731 lpar = find (dep == "(");
1732 rpar = find (dep == ")");
1733 ## Does the dependency specify a version
1734 ## Example: package(>= version).
1735 if (length (lpar) == 1 && length (rpar) == 1)
1736 package = tolower (strip (dep(1:lpar-1)));
1737 sub = dep(lpar(1)+1:rpar(1)-1);
1738 parts = strsplit (sub, " ", true);
1739 if (length (parts) != 2)
1740 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file
\n"
,
1743 operator
= parts
{1};
1744 if (! any (strcmp (operator
, {"
>"
, "
>="
, "
<="
, "
<"
, "
=="
})))
1745 error ("unsupported operator
: %s", operator);
1747 version = fix_version
(parts
{2});
1749 ##
If no
version is specified
for the dependency
1750 ## we say that the
version should be greater than
1751 ## or equal to "
0.0.0".
1753 package
= tolower
(strip
(dep
));
1757 deps_cell
{i
} = struct ("package"
, package
, "operator"
, operator
,
1758 "
version"
, version);
1762 ## Strip the
text of spaces from the right
1763 ## Example
: " hello world "
=> " hello world"
1764 ## FIXME
-- is this the same as
deblank?
1765 function text = rstrip
(text)
1766 chars
= find (! isspace (text));
1767 if (length (chars
) > 0)
1768 ## FIXME
: shouldn
't it be text = text(1:chars(end));
1769 text = text (chars(1):end);
1775 ## Strip the text of spaces from the left and the right.
1776 ## Example: " hello world " => "hello world"
1777 function text = strip (text)
1778 chars = find (! isspace (text));
1779 if (length (chars) > 0)
1780 text = text(chars(1):chars(end));
1786 ## Split the text into a cell array of strings by sep.
1787 ## Example: "A, B" => {"A", "B"} (with sep = ",")
1788 function out = split_by (text, sep)
1789 out = strtrim (strsplit (text, sep));
1792 ## Create an INDEX file for a package that doesn't provide one.
1793 ##
'desc' describes the package.
1794 ##
'dir' is the
'inst' directory in temporary directory.
1795 ##
'index_file' is the name
(including
path) of resulting INDEX file.
1796 function write_index
(desc
, dir, index_file
, global_install
)
1797 ##
Get names of functions in
dir
1798 [files
, err
, msg
] = readdir
(dir);
1800 error ("couldn
't read directory %s: %s", dir, msg);
1803 ## Check for architecture dependent files.
1804 tmpdir = getarchdir (desc);
1805 if (exist (tmpdir, "dir"))
1806 [files2, err, msg] = readdir (tmpdir);
1808 error ("couldn't read directory
%s: %s", tmpdir, msg);
1810 files
= [files
; files2
];
1814 for i
= 1:length (files
)
1817 if (lf
> 2 && strcmp (file
(end-1:end), ".m"
))
1818 functions
{end+1} = file
(1:end-2);
1819 elseif (lf
> 4 && strcmp (file
(end-3:end), ".oct"
))
1820 functions
{end+1} = file
(1:end-4);
1824 ## Does desc have a categories field?
1825 if (! isfield (desc
, "categories"
))
1826 error ("the DESCRIPTION file must have a Categories field
, when no INDEX file is given"
);
1828 categories
= split_by
(desc.categories
, "
,"
);
1829 if (length (categories
) < 1)
1830 error ("the Category field is empty"
);
1834 fid
= fopen (index_file
, "w"
);
1836 error ("couldn
't open %s for writing.", index_file);
1838 fprintf (fid, "%s >> %s\n", desc.name, desc.title);
1839 fprintf (fid, "%s\n", categories{1});
1840 fprintf (fid, " %s\n", functions{:});
1844 function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst)
1847 ## For each dependency.
1848 for i = 1:length (desc.depends)
1849 dep = desc.depends{i};
1851 ## Is the current dependency Octave?
1852 if (strcmp (dep.package, "octave"))
1853 if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator))
1854 bad_deps{end+1} = dep;
1856 ## Is the current dependency not Octave?
1859 for i = 1:length (installed_pkgs_lst)
1860 cur_name = installed_pkgs_lst{i}.name;
1861 cur_version = installed_pkgs_lst{i}.version;
1862 if (strcmp (dep.package, cur_name)
1863 && compare_versions (cur_version, dep.version, dep.operator))
1869 bad_deps{end+1} = dep;
1875 function [out1, out2] = installed_packages (local_list, global_list)
1876 ## Get the list of installed packages.
1878 local_packages = load (local_list).local_packages;
1880 local_packages = {};
1883 global_packages = load (global_list).global_packages;
1885 global_packages = {};
1887 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
1889 ## Eliminate duplicates in the installed package list.
1890 ## Locally installed packages take precedence.
1892 for i = 1:length (installed_pkgs_lst)
1896 for j = (i+1):length (installed_pkgs_lst)
1900 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name))
1906 installed_pkgs_lst(dup) = [];
1909 ## Now check if the package is loaded.
1910 tmppath = strrep (path(), "\\", "/");
1911 for i = 1:length (installed_pkgs_lst)
1912 if (findstr (tmppath, strrep (installed_pkgs_lst{i}.dir, "\\", "/")))
1913 installed_pkgs_lst{i}.loaded = true;
1915 installed_pkgs_lst{i}.loaded = false;
1918 for i = 1:length (local_packages)
1919 if (findstr (tmppath, strrep (local_packages{i}.dir, "\\", "/")))
1920 local_packages{i}.loaded = true;
1922 local_packages{i}.loaded = false;
1925 for i = 1:length (global_packages)
1926 if (findstr (tmppath, strrep (global_packages{i}.dir, "\\", "/")))
1927 global_packages{i}.loaded = true;
1929 global_packages{i}.loaded = false;
1933 ## Should we return something?
1935 out1 = local_packages;
1936 out2 = global_packages;
1938 elseif (nargout == 1)
1939 out1 = installed_pkgs_lst;
1943 ## We shouldn't
return something
, so we
'll print something.
1944 num_packages = length (installed_pkgs_lst);
1945 if (num_packages == 0)
1946 printf ("no packages installed.\n");
1950 ## Compute the maximal lengths of name, version, and dir.
1951 h1 = "Package Name";
1953 h3 = "Installation directory";
1954 max_name_length = length (h1);
1955 max_version_length = length (h2);
1956 names = cell (num_packages, 1);
1957 for i = 1:num_packages
1958 max_name_length = max (max_name_length,
1959 length (installed_pkgs_lst{i}.name));
1960 max_version_length = max (max_version_length,
1961 length (installed_pkgs_lst{i}.version));
1962 names{i} = installed_pkgs_lst{i}.name;
1964 max_dir_length = terminal_size()(2) - max_name_length - ...
1965 max_version_length - 7;
1966 if (max_dir_length < 20)
1967 max_dir_length = Inf;
1970 h1 = postpad (h1, max_name_length + 1, " ");
1971 h2 = postpad (h2, max_version_length, " ");;
1974 header = sprintf("%s | %s | %s\n", h1, h2, h3);
1976 tmp = sprintf (repmat ("-", 1, length(header)-1));
1977 tmp(length(h1)+2) = "+";
1978 tmp(length(h1)+length(h2)+5) = "+";
1979 printf ("%s\n", tmp);
1981 ## Print the packages.
1982 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length,
1983 max_version_length);
1984 [dummy, idx] = sort (names);
1985 for i = 1:num_packages
1986 cur_name = installed_pkgs_lst{idx(i)}.name;
1987 cur_version = installed_pkgs_lst{idx(i)}.version;
1988 cur_dir = installed_pkgs_lst{idx(i)}.dir;
1989 if (length (cur_dir) > max_dir_length)
1990 first_char = length (cur_dir) - max_dir_length + 4;
1991 first_filesep = strfind (cur_dir(first_char:end), filesep());
1992 if (! isempty (first_filesep))
1993 cur_dir = cstrcat ("...",
1994 cur_dir((first_char + first_filesep(1) - 1):end));
1996 cur_dir = cstrcat ("...", cur_dir(first_char:end));
1999 if (installed_pkgs_lst{idx(i)}.loaded)
2004 printf (format, cur_name, cur_loaded, cur_version, cur_dir);
2008 function load_packages (files, handle_deps, local_list, global_list)
2009 installed_pkgs_lst = installed_packages (local_list, global_list);
2010 num_packages = length (installed_pkgs_lst);
2012 ## Read package names and installdirs into a more convenient format.
2013 pnames = pdirs = cell (1, num_packages);
2014 for i = 1:num_packages
2015 pnames{i} = installed_pkgs_lst{i}.name;
2016 pdirs{i} = installed_pkgs_lst{i}.dir;
2020 if (length (files) == 1 && strcmp (files{1}, "all"))
2021 idx = [1:length(installed_pkgs_lst)];
2023 elseif (length (files) == 1 && strcmp (files{1}, "auto"))
2025 for i = 1:length (installed_pkgs_lst)
2026 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file"))
2030 ## Load package_name1 ...
2033 for i = 1:length (files)
2034 idx2 = find (strcmp (pnames, files{i}));
2036 error ("package %s is not installed", files{i});
2038 idx (end + 1) = idx2;
2042 ## Load the packages, but take care of the ordering of dependencies.
2043 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true);
2046 function unload_packages (files, handle_deps, local_list, global_list)
2047 installed_pkgs_lst = installed_packages (local_list, global_list);
2048 num_packages = length (installed_pkgs_lst);
2050 ## Read package names and installdirs into a more convenient format.
2051 pnames = pdirs = cell (1, num_packages);
2052 for i = 1:num_packages
2053 pnames{i} = installed_pkgs_lst{i}.name;
2054 pdirs{i} = installed_pkgs_lst{i}.dir;
2055 pdeps{i} = installed_pkgs_lst{i}.depends;
2058 ## Get the current octave path.
2059 p = split_by (path(), pathsep ());
2061 if (length (files) == 1 && strcmp (files{1}, "all"))
2064 desc = installed_pkgs_lst;
2066 ## Unload package_name1 ...
2069 for i = 1:length (files)
2070 idx = strcmp (pnames, files{i});
2072 error ("package %s is not installed", files{i});
2074 dirs{end+1} = pdirs{idx};
2075 desc{end+1} = installed_pkgs_lst{idx};
2079 ## Check for architecture dependent directories.
2081 for i = 1:length (dirs)
2082 tmpdir = getarchdir (desc{i});
2083 if (exist (tmpdir, "dir"))
2084 archdirs{end+1} = dirs{i};
2085 archdirs{end+1} = tmpdir;
2087 archdirs{end+1} = dirs{i};
2091 ## Unload the packages.
2092 for i = 1:length (archdirs)
2094 idx = strcmp (p, d);
2097 ## FIXME: We should also check if we need to remove items from
2103 function [status_out, msg_out] = rm_rf (dir)
2105 crr = confirm_recursive_rmdir ();
2107 confirm_recursive_rmdir (false);
2108 [status, msg] = rmdir (dir, "s");
2109 unwind_protect_cleanup
2110 confirm_recursive_rmdir (crr);
2117 status_out = status;
2124 function emp = dirempty (nm, ign)
2125 if (exist (nm, "dir"))
2129 ign = [{".", ".."}, ign];
2132 for i = 1:length (l)
2134 for j = 1:length (ign)
2135 if (strcmp (l(i).name, ign{j}))
2151 function arch = getarch ()
2152 persistent _arch = cstrcat (octave_config_info("canonical_host_type"), ...
2153 "-", octave_config_info("api_version"));
2157 function archprefix = getarchprefix (desc, global_install)
2158 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ()))
2159 archprefix = fullfile (octave_config_info ("libexecdir"), "octave",
2160 "packages", cstrcat(desc.name, "-", desc.version));
2162 archprefix = desc.dir;
2166 function archdir = getarchdir (desc)
2167 archdir = fullfile (desc.archprefix, getarch());
2170 function s = issuperuser ()
2171 if ((ispc () && ! isunix ()) || (geteuid() == 0))
2178 function [status, output] = shell (cmd)
2181 cmd = strrep (cmd, "\\", "/");
2182 if (ispc () && ! isunix ())
2183 if (isempty(have_sh))
2184 if (system("sh.exe -c \"exit\""))
2191 [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\""));
2193 error ("Can not find the command shell")
2196 [status, output] = system (cmd);
2200 function newdesc = save_order (desc)
2202 for i = 1 : length(desc)
2203 deps = desc{i}.depends;
2204 if (isempty (deps) || (length (deps) == 1 &&
2205 strcmp(deps{1}.package, "octave")))
2206 newdesc {end + 1} = desc{i};
2209 for k = 1 : length (deps)
2210 for j = 1 : length (desc)
2211 if (strcmp (desc{j}.name, deps{k}.package))
2212 tmpdesc{end+1} = desc{j};
2217 if (! isempty (tmpdesc))
2218 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}};
2220 newdesc{end+1} = desc{i};
2224 ## Eliminate the duplicates.
2226 for i = 1 : length (newdesc)
2227 for j = (i + 1) : length (newdesc)
2228 if (strcmp (newdesc{i}.name, newdesc{j}.name))
2236 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst,
2238 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst);
2240 execpath = EXEC_PATH ();
2242 ndir = installed_pkgs_lst{i}.dir;
2244 if (exist (fullfile (dirs{end}, "bin"), "dir"))
2245 execpath = cstrcat (fullfile (dirs{end}, "bin"), ":", execpath);
2247 tmpdir = getarchdir (installed_pkgs_lst{i});
2248 if (exist (tmpdir, "dir"))
2249 dirs{end + 1} = tmpdir;
2250 if (exist (fullfile (dirs{end}, "bin"), "dir"))
2251 execpath = cstrcat (fullfile (dirs{end}, "bin"), ":", execpath);
2256 ## Load the packages.
2257 if (length (dirs) > 0)
2261 ## Add the binaries to exec_path.
2262 if (! strcmp (EXEC_PATH, execpath))
2263 EXEC_PATH (execpath);
2267 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst)
2269 if (isfield (installed_pkgs_lst{i}, "loaded") &&
2270 installed_pkgs_lst{i}.loaded)
2274 deps = installed_pkgs_lst{i}.depends;
2275 if ((length (deps) > 1) || (length (deps) == 1 &&
2276 ! strcmp(deps{1}.package, "octave")))
2278 for k = 1 : length (deps)
2279 for j = 1 : length (installed_pkgs_lst)
2280 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package))
2281 tmplidx (end + 1) = j;
2286 idx = load_package_dirs (tmplidx, idx, handle_deps,
2287 installed_pkgs_lst);
2290 if (isempty (find(idx == i)))
2297 function dep = is_architecture_dependent (nm)
2298 persistent archdepsuffix = {".oct",".mex",".a",".lib",".so",".so.*",".dll","dylib"};
2301 for i = 1 : length (archdepsuffix)
2302 ext = archdepsuffix{i};
2303 if (ext(end) == "*")
2309 pos = findstr (nm, ext);
2311 if (! isglob && (length(nm) - pos(end) != length(ext) - 1))