Index: openacs-4/packages/acs-admin/www/apm/build-repository.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/apm/Attic/build-repository.tcl,v
diff -u -N -r1.1 -r1.2
--- openacs-4/packages/acs-admin/www/apm/build-repository.tcl 4 Oct 2003 03:03:29 -0000 1.1
+++ openacs-4/packages/acs-admin/www/apm/build-repository.tcl 7 Nov 2003 11:36:47 -0000 1.2
@@ -2,67 +2,225 @@
Build package repository.
}
-# TODO: anonymous cvs export the packages with a given CVS tag corresponding to the channel
-# (channel-5-0-oracle, channel-5-1-postgresql, etc.)
+# TODO: Build repository in temp dir, then rename
+#----------------------------------------------------------------------
+# Configuration Settings
+#----------------------------------------------------------------------
+set cvs_command "cvs"
+set cvs_root ":pserver:anonymous@openacs.org:/cvsroot"
-#####
-#
-# Read all package .info files, building manifest file
-#
-#####
-set channel "[db_type]-5-0"
+set work_dir "[acs_root_dir]/repository-builder/"
-set repository_dir "/web/lars/www/repository/$channel/"
-set repository_url "http://lars.cph02.collaboraid.net/repository/$channel/"
+set repository_dir "[acs_root_dir]/www/repository/"
+set repository_url "http://openacs.org/repository/"
-append manifest {} \n
+set head_channel "5-0"
-foreach spec_file [apm_scan_packages "[acs_root_dir]/packages"] {
- with_catch errmsg {
- array set version [apm_read_package_info_file $spec_file]
+
+#----------------------------------------------------------------------
+# Prepare output
+#----------------------------------------------------------------------
+
+ReturnHeaders
+ns_write [ad_header "Building repository"]
+ns_write
+
+#----------------------------------------------------------------------
+# Find available channels
+#----------------------------------------------------------------------
+
+# Prepare work dir
+publish::mkdirs $work_dir
+
+cd $work_dir
+catch { exec $cvs_command -d $cvs_root -z3 co openacs-4/readme.txt }
+
+catch { exec $cvs_command -d $cvs_root -z3 log -h openacs-4/ } output
+
+set lines [split $output \n]
+for { set i 0 } { $i < [llength $lines] } { incr i } {
+ if { [string equal [string trim [lindex $lines $i]] "symbolic names:"] } {
+ incr i
+ break
+ }
+}
+
+array set channel_tag [list]
+array set channel_bugfix_version [list]
+
+for { } { $i < [llength $lines] } { incr i } {
+ if { ![regexp {^\s+([^:]+):\s+([0-9.]+)} [lindex $lines $i] match tag_name version_name] } {
+ break
+ }
+ if { [regexp {^oacs-(.*)-final$} $tag_name match oacs_version] } {
- append manifest { } {} \n
-
- append manifest { } {} [ad_quotehtml $version(package.key)] {} \n
- append manifest { } {} [ad_quotehtml $version(name)] {} \n
- append manifest { } {} [ad_quotehtml $version(package-name)] {} \n
- append manifest { } {} [ad_quotehtml $version(package.type)] {} \n
-
- set apm_file "${repository_dir}${version(package.key)}-${version(name)}.apm"
-
- set cmd [list exec [apm_tar_cmd] cf - 2>/dev/null]
- foreach file [apm_get_package_files -all_db_types -package_key $version(package.key)] {
- lappend cmd -C "[acs_root_dir]/packages"
- lappend cmd "$version(package.key)/$file"
+ set major_version [lindex [split $oacs_version "-"] 0]
+ set minor_version [lindex [split $oacs_version "-"] 1]
+ set bugfix_version [lindex [split $oacs_version "-"] 2]
+ if { ![regexp {^[0-9]*$} $bugfix_version] } {
+ set bugfix_version 0
}
-
- lappend cmd "|" [apm_gzip_cmd] -c ">" $apm_file
- eval $cmd
- set apm_url "${repository_url}${version(package.key)}-${version(name)}.apm"
+ if { $major_version >= 5 } {
+ set channel "${major_version}-${minor_version}"
- append manifest { } {} $apm_url {} \n
- foreach elm $version(provides) {
- append manifest { } "" \n
+ ns_write "- Processing channel $channel - tag $tag_name\n"
+
+ if { ![info exists channel_bugfix_version($channel)] || $channel_bugfix_version($channel) < $bugfix_version } {
+ set channel_tag($channel) $tag_name
+ set channel_bugfix_version($channel) $bugfix_version
+ } else {
+ ns_write "(skipping because we already have a later tag on this channel)"
+ }
}
+ }
+}
+
+set channel_tag($head_channel) HEAD
+
+
+ns_write "
- Channels are: [array get channel_tag]\n"
+
+
+
+#----------------------------------------------------------------------
+# Read all package .info files, building manifest file
+#----------------------------------------------------------------------
+
+# Wipe the repository dir
+file delete -force "${work_dir}repository/"
+
+foreach channel [lsort -decreasing [array names channel_tag]] {
+
+ ns_write "
- Starting channel $channel with tag $channel_tag($channel)\n"
+
+ # Wipe and re-create the working directory
+ file delete -force $work_dir
+ publish::mkdirs $work_dir
+ cd $work_dir
+
+ # Prepare channel directory
+ set channel_dir "${work_dir}repository/${channel}/"
+ publish::mkdirs $channel_dir
+
+ # Store the list of packages we've seen for this channel, so we don't include the same package twice
+ # Seems odd, but we have to do this given the forked packages sitting in /contrib
+ set packages [list]
+
+ # Checkout from the tag given by channel_tag($channel)
+ if { [string equal $channel_tag($channel) HEAD] } {
+ catch { exec $cvs_command -d $cvs_root -z3 co -r $channel_tag($channel) openacs-4/packages } output
+ catch { exec $cvs_command -d $cvs_root -z3 co -r $channel_tag($channel) openacs-4/contrib/packages } output
+ } else {
+ catch { exec $cvs_command -d $cvs_root -z3 co openacs-4/packages } output
+ catch { exec $cvs_command -d $cvs_root -z3 co openacs-4/contrib/packages } output
+ }
- foreach elm $version(requires) {
- append manifest { } "" \n
- }
+ append manifest {} \n
+
+ foreach packages_dir [list "${work_dir}openacs-4/packages" "${work_dir}openacs-4/contrib/packages"] {
+ foreach spec_file [apm_scan_packages $packages_dir] {
- append manifest { } {
} \n
- } {
- global errorInfo
- ns_log Error "Error while checking package info file $spec_file: $errmsg\n$errorInfo"
+ set package_path [eval file join [lrange [file split $spec_file] 0 end-1]]
+ set package_key [lindex [file split $spec_file] end-1]
+
+ if { [array exists version] } {
+ array unset version
+ }
+ if { [info exists version] } {
+ unset version
+ }
+
+ with_catch errmsg {
+ array set version [apm_read_package_info_file $spec_file]
+
+ if { [lsearch -exact $packages $version(package.key)] != -1 } {
+ ns_write "- Skipping package $package_key, because we already have another version of it"
+ } else {
+ ns_write "
- Building package $package_key for channel $channel\n"
+
+ lappend packages $version(package.key)
+
+ append manifest { } {} \n
+
+ append manifest { } {} [ad_quotehtml $version(package.key)] {} \n
+ append manifest { } {} [ad_quotehtml $version(name)] {} \n
+ append manifest { } {} [ad_quotehtml $version(package-name)] {} \n
+ append manifest { } {} [ad_quotehtml $version(package.type)] {} \n
+ append manifest { } {} [ad_quotehtml $version(summary)] {} \n
+ append manifest { } {}
+ append manifest [ad_quotehtml $version(description)] {} \n
+ append manifest { } {} [ad_quotehtml $version(release-date)] {} \n
+ append manifest { } {}
+ append manifest [ad_quotehtml $version(vendor)] {} \n
+
+ set apm_file "${channel_dir}${version(package.key)}-${version(name)}.apm"
+
+ set files [apm_get_package_files \
+ -all_db_types \
+ -package_key $version(package.key) \
+ -package_path $package_path]
+
+ if { [llength $files] == 0 } {
+ ns_write "No files in package"
+ } else {
+ set cmd [list exec [apm_tar_cmd] cf - 2>/dev/null]
+ lappend cmd -C $package_path
+ foreach file $files {
+ lappend cmd $file
+ }
+ lappend cmd "|" [apm_gzip_cmd] -c ">" $apm_file
+ ns_log Notice "Executing: [ad_quotehtml $cmd]"
+ eval $cmd
+ }
+
+
+ set apm_url "${repository_url}${channel}/${version(package.key)}-${version(name)}.apm"
+
+ append manifest { } {} $apm_url {} \n
+ foreach elm $version(provides) {
+ append manifest { } "" \n
+ }
+
+ foreach elm $version(requires) {
+ append manifest { } "" \n
+ }
+
+ append manifest { } {} \n
+ }
+ } {
+ global errorInfo
+ ns_write "
- Error on spec_file $spec_file: [ad_quotehtml $errmsg]
[ad_quotehtml $errorInfo]\n"
+ }
+ }
}
+ append manifest {
} \n
+
+ set fw [open "${channel_dir}manifest.xml" w]
+ puts $fw $manifest
+ close $fw
+
+ ns_write "
Channel $channel complete.\n"
+
}
-append manifest {} \n
-set fw [open "${repository_dir}manifest.xml" w]
-puts $fw $manifest
-close $fw
+# Without the trailing slash
+set work_repository_dirname "${work_dir}repository"
+set repository_dirname [string range $repository_dir 0 end-1]
+set repository_bak "[string range $repository_dir 0 end-1].bak"
-ns_return 200 text/html "OK"
+ns_write "Moving work repository $work_repository_dirname to live repository dir at $repository_dir\n"
+
+if { [file exists $repository_bak] } {
+ file delete -force $repository_bak
+}
+if { [file exists $repository_dirname] } {
+ file rename $repository_dirname $repository_bak
+}
+file rename $work_repository_dirname $repository_dirname
+
+ns_write " DONE.\n"
+