apm_guess_file_type (public)

 apm_guess_file_type package_key path

Defined in packages/acs-bootstrap-installer/tcl/30-apm-load-procs.tcl

Guesses and returns the file type key corresponding to a particular path (or an empty string if none is known). $path should be relative to the package directory (e.g., www/index.tcl) for /packages/bboard/admin-www/index.tcl. We use the following rules:

  1. Files with extension .sql are considered data-model files,
  2. Files with extension .dat are considered SQL data files.
  3. Files with extension .ctl are considered sql data loader control files. or if any path contains the substring upgrade, data-model upgrade files.
  4. Files with extension .sqlj are considered sqlj_code files.
  5. Files with extension .info are considered package specification files.
  6. Files with extension .xql are considered query files.
  7. Files with extension .java are considered java code files.
  8. Files with extension .jar are considered java archive files.
  9. Files with a path component named doc are considered documentation files.
  10. Files with extension .pl or .sh or which have a path component named bin, are considered shell-executable files.
  11. Files with a path component named templates are considered template files.
  12. Files with extension .html or .adp, in the top level of the package, are considered documentation files.
  13. Files with a path component named www or admin-www are considered content-page files.
  14. Files with a path component named lib are considered include_page files.
  15. Files under package-key/tcl ending in -procs(-)+()*.tcl) or -init.tcl are considered Tcl procedure or Tcl initialization files, respectively.
  16. File ending in .tcl are considered Tcl utility script files (normally found only in the bootstrap installer).
  17. Files with extension .xml in the directory catalog are considered message catalog files.
  18. Tcl procs or init files under package-key/tcl in a test directory are of type test_procs and test_init respectively.
Rules are applied in this order (stopping with the first match).

Parameters:
package_key
path

Partial Call Graph (max 5 caller/called nodes):
%3 test_apm_guess_file_type apm_guess_file_type (test acs-bootstrap-installer) apm_guess_file_type apm_guess_file_type test_apm_guess_file_type->apm_guess_file_type ad_file ad_file (public) apm_guess_file_type->ad_file apm_is_catalog_file apm_is_catalog_file (public) apm_guess_file_type->apm_is_catalog_file apm_data_model_scripts_find apm_data_model_scripts_find (public) apm_data_model_scripts_find->apm_guess_file_type apm_file_watchable_p apm_file_watchable_p (public) apm_file_watchable_p->apm_guess_file_type apm_get_package_files apm_get_package_files (public) apm_get_package_files->apm_guess_file_type apm_guess_db_type apm_guess_db_type (public) apm_guess_db_type->apm_guess_file_type apm_load_queries apm_load_queries (private) apm_load_queries->apm_guess_file_type

Testcases:
apm_guess_file_type
Source code:
    set components [split $path "/"]
    set dirs_in_pageroot [llength [split $::acs::pageroot "/"]]       ;# See comments by RBM

    # Fix to cope with both full and relative paths
    if { [string index $path 0] eq "/"} {
        set components_lesser [lrange $components $dirs_in_pageroot end]
    } else {
        set components_lesser $components
    }
    set extension [ad_file extension $path]
    set type ""


    # DRB: someone named a file "acs-mail-create-packages.sql" rather than
    # the conventional "acs-mail-packages-create.sql", causing it to be
    # recognized as a data_model_create file, causing it to be explicitly
    # run by the installer (the author intended it to be included by
    # acs-mail-create.sql only).  I've tightened up the regexp below to
    # avoid this problem, along with renaming the file...

    # DRB: I've tightened it up again because forums-forums-create.sql
    # was being recognized as a datamodel create script for the forums
    # package.

    if {$extension eq ".sql"} {
        if { [lsearch -glob $components "*upgrade-*-*"] >= 0 } {
            set type "data_model_upgrade"
        } elseif { [regexp -- "^$package_key-(create|drop)\.sql\$" [ad_file tail $path"" kind] } {
            set type "data_model_$kind"
        } else {
            set type "data_model"
        }
    } elseif {$extension eq ".dat"} {
        set type "sql_data"
    } elseif {$extension eq ".ctl"} {
        set type "ctl_file"
    } elseif {$extension eq ".sqlj"} {
        set type "sqlj_code"
    } elseif {$extension eq ".info"} {
        set type "package_spec"
    } elseif {$extension eq ".xql"} {
        set type "query_file"
    } elseif {$extension eq ".java"} {
        set type "java_code"
    } elseif {$extension eq ".jar"} {
        set type "java_archive"
    } elseif"doc" in $components } {
        set type "documentation"
    } elseif$extension eq ".pl" || $extension eq ".sh" || "bin" in $components } {
        set type "shell"
    } elseif"templates" in $components } {
        set type "template"
    } elseif { [llength $components] == 1 &&
               ($extension eq ".html" || $extension eq ".adp") } {
        #
        # HTML or ADP file in the top level of a package - assume it
        # is documentation.
        #
        set type "documentation"

        # RBM: Changed the next elseif to check for 'www' or
        # 'admin-www' only n levels down the path, since that'd be the
        # minimum in a path counting from the pageroot

    } elseif"www" in $components_lesser || "admin-www" in $components_lesser } {
        set type "content_page"
    } elseif"lib" in $components_lesser } {
        set type "include_page"
    } elseif$extension eq ".tcl" && [lindex $components_lesser 0] eq "tcl" } {
        # A .tcl file residing under dir .../package_key/tcl/
        if { [regexp -- {-(procs|init)(-[0-9a-zA-Z]*)?\.tcl$} [ad_file tail $path"" kind] } {
            if {[lindex $components end-1] eq "test"} {
                set type "test_$kind"
            } else {
                set type "tcl_$kind"
            }
        } else {
            set type "tcl_util"
        }
    } elseif { [apm_is_catalog_file "${package_key}/${path}"] } {
        set type "message_catalog"
    }

    return $type
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: