Also, only checks against the installed packages are performed.. What I
see as an extention is to create a complete dependency table of all of
the installed packages, with a function like
function dependency_table = installed_dependencies (prefix,
installed_packages)
count = 0;
for i = 1:length(installed_packages.name)
desc = get_description ([prefix, installed_packages.name{i}]);
verify_description (desc);
for j = 1:length(desc.keywords)
if (strcmp(desc.keywords{j}, "DEPENDS"))
deps = parse_dependencies ( desc.values{i});
if (iscell (deps))
for k = 1:length(deps)
count++;
dependency_table.name{count} = installed_packages.name{i};
dependency_table.version{count} =
installed_packages.version{i};
dependency_table.package{count} = deps.package{k};
dependency_table.operator{count} = deps.operator{k};
dependency_table.dversion{count} = deps.version{k};
endif
endif
endfor
endfor
endfunction
function pdep = parse_dependencies (deps)
deps = split_by(tolower(deps), ",");
if (length(deps) < 1)
pdeps = false;
return;
endif
## For each dependency
for i = 1:length(deps)
dep = deps{i};
lpar = find(dep == "(");
rpar = find(dep == ")");
## Does the dependency specify a version
## Example: package(>= version)
if (length(lpar) == 1 && length(rpar) == 1)
package = tolower(strip(dep(1:lpar-1)));
sub = dep( lpar(1)+1:rpar(1)-1 );
parts = split_by(sub, " ");
idx = [];
for r = 1:size(parts,1)
if (length(parts{r}) > 0)
idx(end+1) = r;
endif
endfor
if (length(idx) != 2)
error(["There's something wrong with the DESCRIPTION
file. " ...
"The dependency %s has the wrong syntax.\n"], dep);
endif
operator = parts{idx(1)};
version = fix_version(parts{idx(2)});
## If no version is specified for the dependcy
## we say that the version should be greater than
## or equal to 0.0.0
else
pdep.package{i} = tolower(strip(dep));
pdep.operator{i} = ">=";
pdep.version{i} = "0.0.0";
endif
endfor
endfunction
then have three other function, one to remove a package, one to add a
package to the table and another to validate the dependency table, like
function new_table = delete_dependency (table, name)
count = 0;
for i = 1:length(table.name)
if (table.name{i} != name)
count++;
new_table.name{count} = table.name{i};
new_table.version{count} = table.version{i};
new_table.package{count} = table.package{i};
new_table.operator{count} = table.operator{i};
new_table.dversion{count} = table.dversion{i};
endif
endfor
if (count == 0)
new_table = false;
endif
endfunction
function table = add_dependency (table, name, version, desc)
count = length (table.name);
for j = 1:length(desc.keywords)
if (strcmp(desc.keywords{j}, "DEPENDS"))
deps = parse_dependencies ( desc.values{i});
if (iscell (deps))
for k = 1:length(deps)
count++;
table.name{count} = name;
table.version{count} = version;
table.package{count} = deps.package{k};
table.operator{count} = deps.operator{k};
table.dversion{count} = deps.version{k};
endfor
endif
endif
endfor
endfunction
function ret = check_dependency_table (table, packages)
for i = 1:length(table.name)
name = table.name{i};
version = table.version{i};
package = table.package{i};
operator = table.operator{i};
dversion = table.dversion{i};
found = false;
for j = 1:length(packages.name)
if (strcmp (packages.name{j}, package) &&
(compare_versions(packages.version{j}, dversion, operator)))
found = true;
break; endif
endfor
if (! found)
error ("missing dependency");
endif
endfor
endfunction
where packages in the function check_dependency_table is the list of
packages that will be installed after the current operation is finished,
and has the same form as installed_packages in the existing code.
Ok, none of the above code is checked as I wrote it straight into my
e-mail client, but at least it gives an idea of what I'm thinking
about.. Including allowing cell-arrays to install/uninstall, it
addresses the issues of circular dependencies and dependencies on
uninstalling...
Cheers
D.