Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v
diff -u -r1.133 -r1.134
--- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 12 Aug 2013 21:32:47 -0000 1.133
+++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 27 Oct 2014 16:40:09 -0000 1.134
@@ -10,6 +10,66 @@
namespace eval util {}
+ad_proc util::zip {
+ -source:required
+ -destination:required
+} {
+ Create a zip file.
+
+ @param source is the content to be zipped. If it is a directory, archive will
+ contain all files into directory without the trailing directory itself.
+
+ @param destination is the name of the created file
+} {
+ set zip [util::which zip]
+ if {$zip eq ""} {
+ error "zip command not found on the system."
+ }
+ set cmd [list exec]
+ switch $::tcl_platform(platform) {
+ windows {lappend cmd cmd.exe /c}
+ default {lappend cmd bash -c}
+ }
+ if {[file isfile $source]} {
+ set filename [file tail $source]
+ set in_path [file dirname $source]
+ } else {
+ set filename "."
+ set in_path $source
+ }
+ # To avoid having the full path of the file included in the archive,
+ # we must first cd to the source directory. zip doesn't have an option
+ # to do this without building a little script...
+ set zip_cmd [list]
+ lappend zip_cmd "cd $in_path"
+ lappend zip_cmd "${zip} -r \"${destination}\" \"${filename}\""
+ set zip_cmd [join $zip_cmd " && "]
+
+ lappend cmd $zip_cmd
+
+ # create the archive
+ {*}$cmd
+}
+
+ad_proc util::unzip {
+ -source:required
+ -destination:required
+ -overwrite:boolean
+} {
+ @param source must be the name of a valid zip file to be decompressed
+
+ @param destination must be the name of a valid directory to contain decompressed files
+} {
+ set unzip [util::which unzip]
+ if {$unzip eq ""} {error "unzip command not found on the system."}
+ # -n means we don't overwrite existing files
+ set cmd [list exec $unzip]
+ if {$overwrite_p} {lappend cmd -o
+ } else {lappend cmd -n}
+ lappend cmd $source -d $destination
+ {*}$cmd
+}
+
# Let's define the nsv arrays out here, so we can call nsv_exists
# on their keys without checking to see if it already exists.
# we create the array by setting a bogus key.
@@ -24,7 +84,13 @@
}
}
-ad_proc util_report_library_entry {{extra_message ""}} "Should be called at beginning of private Tcl library files so that it is easy to see in the error log whether or not private Tcl library files contain errors." {
+ad_proc util_report_library_entry {
+ {extra_message ""}
+} {
+ Should be called at beginning of private Tcl library files so
+ that it is easy to see in the error log whether or not
+ private Tcl library files contain errors.
+} {
set tentative_path [info script]
regsub -all {/\./} $tentative_path {/} scrubbed_path
if { $extra_message eq "" } {
@@ -48,7 +114,7 @@
$foo and $bar set to whatever the user typed in the form
this uses the initially nauseating but ultimately delicious
- tcl system function "uplevel" that lets a subroutine bash
+ Tcl system function "uplevel" that lets a subroutine bash
the environment and local vars of its caller. It ain't Common Lisp...
This is an ad-hoc check to make sure users aren't trying to pass in
@@ -75,7 +141,7 @@
# out because it will cause an unstable release. To add this security
# feature, we will need to go through all the code in the ACS and make
# sure that the code doesn't try to overwrite intentionally and also
- # check to make sure that when tcl files are sourced from another proc,
+ # check to make sure that when Tcl files are sourced from another proc,
# the appropriate variables are unset. If you want to install this
# security feature, then you can look in the release notes for more info.
#
@@ -198,10 +264,8 @@
# Database-related code
##
-ad_proc ad_dbclick_check_dml {
- {
- -bind ""
- }
+ad_proc -deprecated ad_dbclick_check_dml {
+ {-bind ""}
statement_name table_name id_column_name generated_id return_url insert_dml
} {
This proc is used for pages using double click protection. table_name
@@ -259,7 +323,9 @@
return
}
-ad_proc -public util_AnsiDatetoPrettyDate {sql_date} {
+ad_proc -public util_AnsiDatetoPrettyDate {
+ sql_date
+} {
Converts 1998-09-05 to September 5, 1998
} {
set sql_date [string range $sql_date 0 9]
@@ -273,15 +339,17 @@
# was "8.0"
set trimmed_month [string trimleft $month 0]
- set pretty_month [lindex $allthemonths [expr {$trimmed_month - 1}]]
+ set pretty_month [lindex $allthemonths $trimmed_month-1]
set trimmed_day [string trimleft $day 0]
return "$pretty_month $trimmed_day, $year"
}
}
-ad_proc -public remove_nulls_from_ns_set {old_set_id} {
+ad_proc -public remove_nulls_from_ns_set {
+ old_set_id
+} {
Creates and returns a new ns_set without any null value fields
@return new ns_set
@@ -302,9 +370,7 @@
}
ad_proc -public merge_form_with_query {
- {
- -bind {}
- }
+ {-bind {}}
form statement_name sql_qry
} {
Merges a form with a query string.
@@ -335,10 +401,11 @@
-proc util_PrettyBoolean {t_or_f { default "default" } } {
- if { $t_or_f eq "t" || $t_or_f eq "T" } {
+ad_proc -deprecated util_PrettyBoolean {t_or_f { default "default" } } {
+} {
+ if { $t_or_f == "t" || $t_or_f eq "T" } {
return "Yes"
- } elseif { $t_or_f eq "f" || $t_or_f eq "F" } {
+ } elseif { $t_or_f == "f" || $t_or_f eq "F" } {
return "No"
} else {
# Note that we can't compare default to the empty string as in
@@ -352,7 +419,11 @@
}
}
-ad_proc util_PrettyTclBoolean {zero_or_one} "Turns a 1 (or anything else that makes a Tcl IF happy) into Yes; anything else into No" {
+ad_proc util_PrettyTclBoolean {
+ zero_or_one
+} {
+ Turns a 1 (or anything else that makes a Tcl IF happy) into Yes; anything else into No
+} {
if {$zero_or_one} {
return "Yes"
} else {
@@ -446,9 +517,9 @@
foreach option $options {
if { [lindex $option $value_index] in $select_option } {
- append select_options "\n"
+ append select_options "\n"
} else {
- append select_options "\n"
+ append select_options "\n"
}
}
return $select_options
@@ -491,7 +562,7 @@
This will export the three variables foo, bar and baz as
- hidden HTML form fields. It does exactly the same as [export_form_vars foo bar baz].
+ hidden HTML form fields. It does exactly the same as [export_vars -form {foo bar baz}].
@@ -832,9 +903,9 @@
}
# Prepend with the base URL
- if { [exists_and_not_null base] } {
+ if { [info exists base] && $base ne "" } {
if { $export_string ne "" } {
- if { [string match {*[?]*} $base] } {
+ if { [string first ? $base] > -1 } {
# The base already has query vars
set export_string "${base}&${export_string}"
} else {
@@ -847,7 +918,7 @@
}
# Append anchor
- if { [exists_and_not_null anchor] } {
+ if { ([info exists anchor] && $anchor ne "") } {
append export_string "\#$anchor"
}
@@ -887,7 +958,7 @@
Example:
-
doc_body_append [ad_export_vars { msg_id user(email) { order_by date } }]
+
doc_body_append [export_vars { msg_id user(email) { order_by date } }]
will export the variable msg_id and the value email from the array user,
and it will export a variable named order_by with the value date.
@@ -908,7 +979,7 @@
A more involved example:
+doc_body_append [export_vars -override { order_by $new_order_by } $my_vars]
@param form set this parameter if you want the variables exported as hidden form variables,
as opposed to URL variables, which is the default.
@@ -954,8 +1025,7 @@
set export($arg) $var
} else {
# convert the parenthesis into a dot before setting
- set export([string range $arg 0 [expr { $left_paren - 1}]].[string \
- range $arg [expr { $left_paren + 1}] end-1]) $var
+ set export([string range $arg 0 $left_paren-1].[string range $arg $left_paren+1 end-1]) $var
}
}
}
@@ -968,8 +1038,7 @@
set export($name) [lindex [uplevel list \[subst [list $value]\]] 0]
} else {
# convert the parenthesis into a dot before setting
- set export([string range $arg 0 [expr { $left_paren - 1}]].[string \
- range $arg [expr { $left_paren + 1}] end-1]) \
+ set export([string range $arg 0 $left_paren-1].[string range $arg $left_paren+1 end-1]) \
[lindex [uplevel list \[subst [list $value]\]] 0]
}
}
@@ -1020,7 +1089,7 @@
export_vars is now the prefered interface.