home *** CD-ROM | disk | FTP | other *** search
- # ~/icase/export_all_to_file.tcl
- #
- # Created: 5 march 1996
- # Updated: 15 april 1996
- # Version: 1.4
- # Purpose: To export all diagrams to a single file
- # Notes on V1.1: made some changes to export cdm's explicitly if more
- # than one system is exported.
- # Notes on V1.2: made the file PC compatible
- # Notes on V1.3: made adjustments to get et.tcl from the proper location
- # Notes on V1.4: generalized the file selection procedure (platform independent)
- #
-
- #puts "Using ~/icase/export_all_to_file.tcl"
-
-
- set home [lindex [glob ~] 0]
- source "[path_name concat [path_name concat $home icase] small_library.tcl]"
-
-
- proc usage {} {
- puts "Usage: otsh ~/icase/export_all_to_file.tcl -- ( 4000 | 4001 | 4002 | 5100 )"
- exit 1
- }
-
-
-
- # --------------------------------------------------------------------------
- # A procedure to export the diagrams (first argument) on the specified level
- # --------------------------------------------------------------------------
-
- proc exportDiagrams { diagrams level } {
- global args
- global file_name
-
- set line "--------------------------------------"
- set line "$line$line"
-
- foreach diagram $diagrams {
- set path $level/$diagram
- set ok [[ClientContext::global] setLevelPath $path]
-
- # --------------
- # Error handling
- # --------------
- if { $ok } {
- puts " Can't determine client context: '$env(M4_levelpath)'"
- puts " Program stops, whithout export generation. "
- exit 1
- }
-
- # -----------------------------
- # Feedback progress to the user
- # -----------------------------
- puts -nonewline " Diagram '$diagram' ... "
- flush stdout
-
- # ------------------------------------------
- # save some specific information in the file
- # ------------------------------------------
- set f [open $file_name a]
- puts $f "# $line"
- puts $f "# diagram = '$level/$diagram'."
- puts $f "# $line"
- flush $f
- close $f
-
- # -----------------------------------------------------------------
- # set the export tool arguments and execute it.
- # -----------------------------------------------------------------
- eval exportTool { $args }
-
- # ---------------------------------------------
- # write a trailer to the file (two empty lines)
- # ---------------------------------------------
- set f [open $file_name a]
- puts $f ""
- puts $f ""
- flush $f
- close $f
-
- # -----------------------------
- # Feedback progress to the user
- # -----------------------------
- puts "exported."
- flush stdout
- }
- }
-
-
- # -----------------------------------
- # Iterate over all systems in a phase
- # -----------------------------------
-
- proc exportSystems { systems level } {
- foreach system $systems {
- if { [[$system system] type] == "system" } {
- puts " Exporting system '[[$system system] name]'"
- set localFiles [$system localFileVersions]
- set diagrams ""
- foreach diagram $localFiles {
- #if { [string first "@Graph:" "$diagram"] == 0 } {
- set name [[$diagram file] qualifiedName]
- set type [[$diagram file] type]
-
- lappend diagrams "$name.$type"
- #}
- }
- exportDiagrams "$diagrams" "$level/[[$system system] name].system"
- }
- }
- }
-
-
- # ------------------------------------------
- # Iterate over all phases in a configuration
- # ------------------------------------------
-
- proc exportPhases { phases level } {
- foreach phase $phases {
- set systems [$phase systemVersions]
- set name [[$phase phase] name]
- set type [[$phase phase] type]
- puts " Exporting phase '$name.$type"
- exportSystems "$systems" "$level/$name.$type"
- }
- }
-
-
- # --------------------------------------------
- # Iterate over all configurations in a project
- # --------------------------------------------
-
- proc exportConfigurations { configurations level } {
- foreach configuration $configurations {
- set phases [$configuration phaseVersions]
- set name [[$configuration config] name]
- set version [$configuration versionNumber]
- puts " Exporting configuration '$name:$version'"
- exportPhases "$phases" "$level/$name:$version"
- }
- }
-
-
- # --------------------------------------------
- # Iterate over all configurations in a project
- # --------------------------------------------
-
- proc exportProjects { projects level } {
- foreach project $projects {
- puts "Exporting project '[$project name]'"
- set configurations [$project configVersions]
- exportConfigurations "$configurations" "$level/[$project name]"
- }
- }
-
-
- # --------------------------------------------------------------
- # See if any boolean options were specified, set the appropriate
- # variables, and remove any options from argv.
- # --------------------------------------------------------------
-
- proc exportMain {} {
- global args
- global ucgargv
- global file_name
- global et_dont_run
-
- # -------------------------------------
- # A check for proper command line usage
- # -------------------------------------
- if { $ucgargv != "4000" && $ucgargv != "4001" && $ucgargv != "4002" && $ucgargv != "5100" } {
- usage
- exit 1;
- }
-
- set version "[string range [versionInfo maintVersion] 0 1]"
- # --------------------------------------------------------------
- # check if the save version is appropriate for the current level
- # --------------------------------------------------------------
- if { "40$version" > "$ucgargv" } {
- puts -nonewline "Error: input version ('$40$version') higher than "
- puts "output version ('$ucgargv')"
- exit 1;
- }
-
- # -------------------------------------------------------------------
- # source the export source without executing the procedure exportTool
- # -------------------------------------------------------------------
- set src "[path_name concat [lindex [glob ~] 0] icase]"
- set src "[path_name concat $src get_export_source.tcl]"
- source "$src"
-
- # --------------------------------------------------
- # Prompt the File selection dialog and handle errors
- # --------------------------------------------------
- puts "Select a file to which the tcl script must be written..."
- set file_name "[FileSelect]"
- if { $file_name == "" } {
- puts "File name empty, can't comply"
- exit 1
- }
- if { [file exists $file_name] } {
- if { [file type $file_name] != "file" } {
- puts "File $file_name empty, can't comply"
- exit 1
- }
- if { ! [file writable $file_name] } {
- puts "File '$file_name' not writable (for you), can't comply"
- exit 1
- }
- # -------------------------------------------------------------
- # in the future an extra question to the user if he/she is sure
- # -------------------------------------------------------------
- }
-
- # ----------------------------------------------------------
- # set the arguments to read the db on the appropriate level,
- # output for V4.0/01 and explicit cdm generation.
- # ----------------------------------------------------------
- set args "[list -a$file_name] -vi40$version -vo$ucgargv -e -l"
-
- # ------------------
- # output of a header
- # ------------------
- set line "--------------------------------------"
- set line "$line$line"
-
-
- # --------------------------------------
- # write a header about the user and data
- # --------------------------------------
- set f [open $file_name w]
- puts $f "# $line"
- puts $f "# export by '[get_user_name]' on [date]."
- puts $f "# $line"
- puts $f ""
- flush $f
- close $f
-
- # ------------------------------------------------------
- # Setup of variables used to walk through the level tree
- # ------------------------------------------------------
- set M4_levelpath "[[ClientContext::global] currentLevelString]"
- set clientContext [ClientContext::global]
- set corporateID [[ClientContext::global] currentCorporate]
-
- set level "/[$corporateID name]"
-
-
- # -----------------------------------------------------------------------
- # Walk through all sublevels so make a level path until the current level
- # -----------------------------------------------------------------------
- if { $level == $M4_levelpath } {
- # ------------------------------------
- # corporate level, export all projects
- # ------------------------------------
- set projects [$corporateID projects]
- exportProjects "$projects" "$level"
- } else {
- puts "Starting export from level '$M4_levelpath'"
- set project [[$clientContext currentProject] name]
- if { "$level/$project" == "$M4_levelpath" } {
- # ---------------------------------------
- # project level, export this project only
- # ---------------------------------------
- exportProjects "[$clientContext currentLevelId]" $level
- } else {
- set level "$level/$project"
- set configurationID [$clientContext currentConfig]
- set configuration "[[$configurationID config] name]"
- set configuration "$configuration:[$configurationID versionNumber]"
- if { "$level/$configuration" == "$M4_levelpath" } {
- # ---------------------------------------------------
- # configuration level, export this configuration only
- # ---------------------------------------------------
- exportConfigurations "[$clientContext currentLevelId]" $level
- } else {
- set level "$level/$configuration"
- set phaseID [[$clientContext currentPhase] phase]
- set phase "[$phaseID name].[$phaseID type]"
- if { "$level/$phase" == "$M4_levelpath" } {
- # -----------------------------------
- # phase level, export this phase only
- # -----------------------------------
- exportPhases "[$clientContext currentLevelId]" $level
- } else {
- set level "$level/$phase"
- exportSystems "[$clientContext currentLevelId]" $level
- }
- }
- }
- }
-
- puts "export Finished"
- }
-
- # ------------------------------------------
- # ugly source, should get rid of this call!!
- # ------------------------------------------
- global export_dont_run
- if { [catch {set export_dont_run}] } {
- exportMain
- }
-