apm_register_package

one of the documented procedures in this installation of the ACS
Usage:
apm_register_package { -callback apm_dummy_callback } path
What it does:
Registers a new package and/or version in the database, returning the version_id. If $callback is provided, periodically invokes this procedure with a single argument containing a human-readable (English) status message.

This routine throws an error if the specification file is nonexistent or invalid.

Defined in: /web/philip/packages/acs-core/apm-procs.tcl

Source code:

arg_parser_for_apm_register_package $args

    # Note: We use the Tcl proc "#" as a dummy do-nothing callback proc.
    apm_callback_and_log $callback "Reading the configuration file at $path..."

    array set version [apm_read_package_info_file $path]

    db_transaction {
	set package_key $version(package.key)

	# If the package doesn't already exist in apm_packages, insert a new row.
	if { ![db_0or1row "select package_id from apm_packages where package_url = '[db_quote $version(package.url)]'"] } {
	    set package_id [db_nextval "apm_package_id_seq"]
	    db_dml "
                insert into apm_packages(package_id, package_key, package_url)
                values($package_id, '[db_quote $package_key]', '[db_quote $version(package.url)]')
            "
        }

	# Prepare a list of column names and values.
	set columns [list  [list package_id $package_id]  [list package_name "'[db_quote $version(package-name)]'"]  [list version_name "'[db_quote $version(name)]'"]  [list summary "'[db_quote $version(summary)]'"]  [list description_format "'[db_quote $version(description.format)]'"]  [list description "'[db_quote $version(description)]'"]  [list release_date "'[db_quote $version(release-date)]'"]  [list vendor "'[db_quote $version(vendor)]'"]  [list vendor_url "'[db_quote $version(vendor.url)]'"]  [list package_group "'[db_quote $version(group)]'"]]

	# If the version already exists in apm_package_versions, update it;
	# otherwise, insert a new version.
	if { [db_0or1row "select version_id from apm_package_versions where version_url = '[db_quote $version(url)]'"] } {
	    db_dml -type update -where "version_id = $version_id" apm_package_versions $columns
	} else {
	    set version_id [db_nextval "apm_package_version_id_seq"]
	    lappend columns [list version_id $version_id]
	    lappend columns [list version_url "'[db_quote $version(url)]'"]
	    lappend columns [list enabled_p "'f'"]
	    lappend columns [list installed_p "'f'"]

	    db_dml -type insert apm_package_versions $columns
	}

	# Note that we do a bunch of delete/inserts below - this is acceptable because
	# nothing ever references apm_package_(dependencies|owners|files|includes) -
	# the numeric primary keys exist solely for the use of the administration
	# interface.

	# Delete and reinsert dependencies.
	db_dml "delete from apm_package_dependencies where version_id = $version_id"
	foreach dependency_type { provides requires } {
	    foreach item $version($dependency_type) {
		db_dml "
                    insert into apm_package_dependencies(dependency_id, version_id, dependency_type, service_url, service_version)
                    values(apm_package_dependency_id_seq.nextval, $version_id, '$dependency_type', '[db_quote [lindex $item 0]]', '[db_quote [lindex $item 1]]')
                "
            }
	}

	# Delete and reinsert owners (in sorted order, to preserve package
	# developers' fragile egos).
	set counter 0
	db_dml "delete from apm_package_owners where version_id = $version_id"
	foreach item $version(owners) {
	    incr counter
	    db_dml "
                insert into apm_package_owners(version_id, owner_url, owner_name, sort_key)
                values($version_id, '[db_quote [lindex $item 0]]', '[db_quote [lindex $item 1]]', $counter)
            "
	}

	# Delete and reinsert files.
	db_dml "delete from apm_package_files where version_id = $version_id"
	foreach item $version(files) {
	    db_dml "
                insert into apm_package_files(file_id, version_id, path, file_type)
                values(apm_package_file_id_seq.nextval, $version_id, '[db_quote [lindex $item 0]]', '[db_quote [lindex $item 1]]')
            "
	}

	# Delete and reinsert includes.
	db_dml "delete from apm_package_includes where version_id = $version_id"
	foreach item $version(includes) {
	    db_dml "
	        insert into apm_package_includes(include_id, version_id, version_url)
                values(apm_package_include_id_seq.nextval, $version_id, '[db_quote $item]')
            "
	}

	apm_callback_and_log $callback "Registered $version(package-name), version $version(name)."
    }

    return $version_id


philg@mit.edu