apm_get_package_repository (public)

 apm_get_package_repository [ -repository_url repository_url ] \
    -array array

Defined in packages/acs-tcl/tcl/apm-install-procs.tcl

Gets a list of packages available for install from either a remote package repository or the local filesystem.

Switches:
-repository_url (optional)
The URL for the repository channel to get from, or the empty string to search the local filesystem instead.
-array (required)
Name of an array where you want the repository stored. It will be keyed by package-key, and each entry will be an array list returned by apm_read_package_info_file.
Author:
Lars Pind <lars@collaboraid.biz>
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-admin/www/apm/packages-install-2.tcl packages/acs-admin/ www/apm/packages-install-2.tcl apm_get_package_repository apm_get_package_repository packages/acs-admin/www/apm/packages-install-2.tcl->apm_get_package_repository packages/acs-admin/www/install/install-2.tcl packages/acs-admin/ www/install/install-2.tcl packages/acs-admin/www/install/install-2.tcl->apm_get_package_repository packages/acs-admin/www/install/install-3.tcl packages/acs-admin/ www/install/install-3.tcl packages/acs-admin/www/install/install-3.tcl->apm_get_package_repository packages/acs-admin/www/install/install.tcl packages/acs-admin/ www/install/install.tcl packages/acs-admin/www/install/install.tcl->apm_get_package_repository ad_get_client_property ad_get_client_property (public) apm_get_package_repository->ad_get_client_property ad_set_client_property ad_set_client_property (public) apm_get_package_repository->ad_set_client_property ad_try ad_try (public) apm_get_package_repository->ad_try apm::package_version::attributes::parse_xml apm::package_version::attributes::parse_xml (private) apm_get_package_repository->apm::package_version::attributes::parse_xml apm_attribute_value apm_attribute_value (public) apm_get_package_repository->apm_attribute_value

Testcases:
No testcase defined.
Source code:
    # This will be a list of array-lists of packages available for install
    upvar 1 $array repository

    #ns_log notice "apm_get_package_repository repository_url=$repository_url"

    apm_get_installed_versions -array installed_version

    if { $repository_url ne "" } {
        set manifest_url "${repository_url}manifest.xml"

        #ns_log notice "apm_get_package_repository manifest_url=$manifest_url"

        # See if we already have it in a client property
        set manifest [ad_get_client_property acs-admin [string range $manifest_url end-49 end]]

        if { $manifest eq "" } {
            # Nope, get it now
            #ns_log notice [list util::http::get -timeout 120 -url $manifest_url]
            set dict [util::http::get -timeout 120 -url $manifest_url]

            if { [dict get $dict status] ne "200" } {
                error "Couldn't get the package list. Please try again later. Status: [dict get $dict status]"
            }

            set manifest [dict get $dict page]

            # Store for subsequent requests
            ad_set_client_property -clob t acs-admin [string range $manifest_url end-49 end] $manifest
        }

        # Parse manifest

        set tree [xml_parse -persist $manifest]
        set root_node [xml_doc_get_first_node $tree]

        foreach package_node [xml_node_get_children_by_name $root_node "package"] {
            unset -nocomplain version
            set version(package.key)  [xml_node_get_content [xml_node_get_first_child_by_name $package_node "package-key"]]
            set version(name)         [xml_node_get_content [xml_node_get_first_child_by_name $package_node "version"]]
            set version(package-name) [xml_node_get_content [xml_node_get_first_child_by_name $package_node "pretty-name"]]
            set version(package.type) [xml_node_get_content [xml_node_get_first_child_by_name $package_node "package-type"]]
            set version(download_url) [xml_node_get_content [xml_node_get_first_child_by_name $package_node "download-url"]]

            foreach element {summary release-date} {
                set node [xml_node_get_first_child_by_name $package_node $element]
                if {$node ne ""} {
                    set version($element) [xml_node_get_content $node]
                } else {
                    set version($element""
                }
            }

            foreach element {vendor owner} {
                set node  [xml_node_get_first_child_by_name $package_node $element]
                if {$node ne ""} {
                    set version($element)     [xml_node_get_content $node]
                    set version($element.url) [xml_node_get_attribute $node "url"]
                } else {
                    set version($element""
                    set version($element.url) ""
                }
            }

            # Build a list of packages to install additionally
            set version(install) [list]
            foreach node [xml_node_get_children_by_name $package_node install] {
                set install [apm_attribute_value $node package]
                lappend version(install) $install
            }

            apm::package_version::attributes::parse_xml  -parent_node $package_node  -array version

            foreach dependency_type { provides requires embeds extends } {
                set version($dependency_type) {}
                foreach dependency_node [xml_node_get_children_by_name $package_node "$dependency_type"] {
                    lappend version($dependency_type)  [list [xml_node_get_attribute $dependency_node "url"]  [xml_node_get_attribute $dependency_node "version"]]
                }
            }
            foreach install_node [xml_node_get_children_by_name $package_node "install"] {
                lappend version(install) [xml_node_get_attribute $install_node "package"]
            }

            if { ![info exists installed_version($version(package.key))] } {
                # Package is not installed
                set version(install_type) install
            } elseif$version(name) eq $installed_version($version(package.key)) ||
                       [apm_higher_version_installed_p $version(package.key) $version(name)] != 1 } {
                # This version or a higher version already installed
                set version(install_type) already_installed
            } else {
                # Earlier version installed, this is an upgrade
                set version(install_type) upgrade
            }

            ns_log Debug "apm_get_package_repository: $version(package.key) = $version(install_type) -- [array get installed_version]"

            if { $version(install_type) ne "already_installed" } {
                set repository($version(package.key)) [array get version]
            }
        }
    } else {
        # Parse spec files
        set spec_files [apm_scan_packages "$::acs::rootdir/packages"]
        lappend spec_files {*}[apm_scan_packages]
        foreach spec_file $spec_files {
            ad_try {
                unset -nocomplain version
                array set version [apm_read_package_info_file $spec_file]

                # If the package doesn't support this RDBMS, it's not really available for install
                if { [apm_package_supports_rdbms_p -package_key $version(package.key)] } {

                    if { ![info exists installed_version($version(package.key))] } {
                        # Package is not installed
                        set version(install_type) install
                    } elseif$version(name) eq $installed_version($version(package.key)) ||
                               [apm_higher_version_installed_p $version(package.key) $version(name)] != 1 } {
                        # This version or a higher version already installed
                        set version(install_type) already_installed
                    } else {
                        # Earlier version installed, this is an upgrade
                        set version(install_type) upgrade
                    }

                    if { $version(install_type) ne "already_installed" } {
                        set repository($version(package.key)) [array get version]
                    }
                }
            } on error {errmsg} {
                # We don't error hard here, because we don't want the whole process to fail if there's just one
                # package with a bad .info file
                ns_log Error "apm_get_package_repository: Error while checking package info file $spec_file: $errmsg\n$::errorInfo"
            }
        }
    }
Generic XQL file:
packages/acs-tcl/tcl/apm-install-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/apm-install-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/apm-install-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: