home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / all2file.tcl < prev    next >
Encoding:
Text File  |  1996-12-20  |  10.9 KB  |  305 lines

  1. #              ~/icase/export_all_to_file.tcl
  2. #
  3. # Created: 5 march 1996
  4. # Updated: 15 april 1996
  5. # Version: 1.4
  6. # Purpose: To export all diagrams to a single file 
  7. # Notes on V1.1: made some changes to export cdm's explicitly if more
  8. #                than one system is exported.
  9. # Notes on V1.2: made the file PC compatible
  10. # Notes on V1.3: made adjustments to get et.tcl from the proper location
  11. # Notes on V1.4: generalized the file selection procedure (platform independent)
  12. #
  13.  
  14. #puts "Using ~/icase/export_all_to_file.tcl"
  15.  
  16.  
  17. set home [lindex [glob ~] 0]
  18. source "[path_name concat [path_name concat $home icase] small_library.tcl]"
  19.  
  20.  
  21. proc usage {} {
  22.     puts "Usage: otsh ~/icase/export_all_to_file.tcl -- ( 4000 | 4001 | 4002 | 5100 )"
  23.     exit 1
  24. }
  25.  
  26.  
  27.  
  28. # --------------------------------------------------------------------------
  29. # A procedure to export the diagrams (first argument) on the specified level
  30. # --------------------------------------------------------------------------
  31.  
  32. proc exportDiagrams { diagrams level } {
  33.     global args
  34.     global file_name
  35.  
  36.     set line "--------------------------------------"
  37.     set line "$line$line"
  38.  
  39.     foreach diagram $diagrams {
  40.         set path  $level/$diagram
  41.         set ok [[ClientContext::global] setLevelPath $path]
  42.  
  43.         # --------------
  44.         # Error handling
  45.         # --------------
  46.         if { $ok } {
  47.             puts " Can't determine client context: '$env(M4_levelpath)'"
  48.             puts " Program stops, whithout export generation. "
  49.             exit 1
  50.         }
  51.  
  52.         # -----------------------------
  53.         # Feedback progress to the user
  54.         # -----------------------------
  55.         puts -nonewline "        Diagram '$diagram' ... "
  56.         flush stdout
  57.  
  58.         # ------------------------------------------ 
  59.         # save some specific information in the file 
  60.         # ------------------------------------------ 
  61.         set f [open $file_name a]
  62.         puts $f "# $line"
  63.         puts $f "# diagram = '$level/$diagram'."
  64.         puts $f "# $line"
  65.         flush $f
  66.         close $f
  67.  
  68.         # -----------------------------------------------------------------
  69.         # set the export tool arguments and execute it.
  70.         # -----------------------------------------------------------------
  71.         eval exportTool { $args }
  72.  
  73.         # ---------------------------------------------
  74.         # write a trailer to the file (two empty lines)
  75.         # ---------------------------------------------
  76.         set f [open $file_name a]
  77.         puts $f "" 
  78.         puts $f ""
  79.         flush $f
  80.         close $f
  81.  
  82.         # -----------------------------
  83.         # Feedback progress to the user
  84.         # -----------------------------
  85.         puts "exported."
  86.         flush stdout
  87.     }
  88. }
  89.  
  90.  
  91. # -----------------------------------
  92. # Iterate over all systems in a phase
  93. # -----------------------------------
  94.  
  95. proc exportSystems { systems level } {
  96.     foreach system $systems {
  97.         if { [[$system system] type] == "system" } {
  98.             puts "      Exporting system '[[$system system] name]'"
  99.             set localFiles [$system localFileVersions]
  100.             set diagrams ""
  101.             foreach diagram $localFiles {
  102.                 #if { [string first "@Graph:" "$diagram"] == 0 } {
  103.                     set name [[$diagram file] qualifiedName]
  104.                     set type [[$diagram file] type]
  105.     
  106.                     lappend diagrams "$name.$type"
  107.                 #}
  108.             }
  109.             exportDiagrams "$diagrams" "$level/[[$system system] name].system"
  110.         }
  111.     }
  112. }
  113.  
  114.  
  115. # ------------------------------------------
  116. # Iterate over all phases in a configuration
  117. # ------------------------------------------
  118.  
  119. proc exportPhases { phases level } {
  120.     foreach phase $phases {
  121.         set systems [$phase systemVersions]
  122.         set name [[$phase phase] name]
  123.         set type [[$phase phase] type]
  124.         puts "    Exporting phase '$name.$type"
  125.         exportSystems "$systems" "$level/$name.$type"
  126.     }
  127. }
  128.  
  129.  
  130. # --------------------------------------------
  131. # Iterate over all configurations in a project
  132. # --------------------------------------------
  133.  
  134. proc exportConfigurations { configurations level } {
  135.     foreach configuration $configurations {
  136.         set phases [$configuration phaseVersions]
  137.         set name [[$configuration config] name]
  138.         set version [$configuration versionNumber]
  139.         puts "  Exporting configuration '$name:$version'"
  140.         exportPhases "$phases" "$level/$name:$version"
  141.     }
  142. }
  143.  
  144.  
  145. # --------------------------------------------
  146. # Iterate over all configurations in a project
  147. # --------------------------------------------
  148.  
  149. proc exportProjects { projects level } {
  150.     foreach project $projects {
  151.         puts "Exporting project '[$project name]'"
  152.         set configurations [$project configVersions]
  153.         exportConfigurations "$configurations" "$level/[$project name]"
  154.     }
  155. }
  156.  
  157.  
  158. # --------------------------------------------------------------
  159. # See if any boolean options were specified, set the appropriate
  160. # variables, and remove any options from argv.
  161. # --------------------------------------------------------------
  162.  
  163. proc exportMain {} {
  164.     global args
  165.     global ucgargv
  166.     global file_name
  167.     global et_dont_run
  168.  
  169.     # -------------------------------------
  170.     # A check for proper command line usage
  171.     # -------------------------------------
  172.     if { $ucgargv != "4000" && $ucgargv != "4001" && $ucgargv != "4002" && $ucgargv != "5100" } {
  173.         usage
  174.         exit 1;
  175.     }
  176.  
  177.     set version "[string range [versionInfo maintVersion] 0 1]"
  178.     # --------------------------------------------------------------
  179.     # check if the save version is appropriate for the current level
  180.     # --------------------------------------------------------------
  181.     if { "40$version" > "$ucgargv" } {
  182.         puts -nonewline "Error: input version ('$40$version') higher than "
  183.         puts "output version ('$ucgargv')"
  184.         exit 1;
  185.     }
  186.  
  187.     # -------------------------------------------------------------------
  188.     # source the export source without executing the procedure exportTool
  189.     # -------------------------------------------------------------------
  190.     set src "[path_name concat [lindex [glob ~] 0] icase]"
  191.     set src "[path_name concat $src get_export_source.tcl]"
  192.     source "$src"
  193.  
  194.     # --------------------------------------------------
  195.     # Prompt the File selection dialog and handle errors
  196.     # --------------------------------------------------
  197.     puts "Select a file to which the tcl script must be written..."
  198.     set file_name "[FileSelect]"
  199.     if { $file_name == "" } {
  200.         puts "File name empty, can't comply"
  201.         exit 1
  202.     }
  203.     if { [file exists $file_name] } {
  204.         if { [file type $file_name] != "file" } {
  205.             puts "File $file_name  empty, can't comply"
  206.             exit 1
  207.         }
  208.         if { ! [file writable $file_name] } {
  209.             puts "File '$file_name' not writable (for you), can't comply"
  210.             exit 1
  211.         }
  212.         # -------------------------------------------------------------
  213.         # in the future an extra question to the user if he/she is sure
  214.         # -------------------------------------------------------------
  215.     }
  216.  
  217.     # ----------------------------------------------------------
  218.     # set the arguments to read the db on the appropriate level,
  219.     # output for V4.0/01 and explicit cdm generation.
  220.     # ----------------------------------------------------------
  221.     set args "[list -a$file_name] -vi40$version -vo$ucgargv -e -l"
  222.  
  223.     # ------------------
  224.     # output of a header
  225.     # ------------------
  226.     set line "--------------------------------------"
  227.     set line "$line$line"
  228.  
  229.  
  230.     # --------------------------------------
  231.     # write a header about the user and data
  232.     # --------------------------------------
  233.     set f [open $file_name w]
  234.     puts $f "# $line"
  235.     puts $f "# export by '[get_user_name]' on [date]."
  236.     puts $f "# $line"
  237.     puts $f ""
  238.     flush $f
  239.     close $f
  240.  
  241.     # ------------------------------------------------------
  242.     # Setup of variables used to walk through the level tree
  243.     # ------------------------------------------------------
  244.     set M4_levelpath "[[ClientContext::global] currentLevelString]"
  245.     set clientContext [ClientContext::global]
  246.     set corporateID [[ClientContext::global] currentCorporate]
  247.  
  248.     set level "/[$corporateID name]"
  249.  
  250.  
  251.     # ----------------------------------------------------------------------- 
  252.     # Walk through all sublevels so make a level path until the current level 
  253.     # ----------------------------------------------------------------------- 
  254.     if { $level == $M4_levelpath } {
  255.         # ------------------------------------
  256.         # corporate level, export all projects
  257.         # ------------------------------------
  258.         set projects [$corporateID projects]
  259.         exportProjects "$projects" "$level"
  260.     } else {
  261.         puts "Starting export from level '$M4_levelpath'"
  262.         set project [[$clientContext currentProject] name]
  263.         if { "$level/$project" == "$M4_levelpath" } {
  264.             # ---------------------------------------
  265.             # project level, export this project only
  266.             # ---------------------------------------
  267.             exportProjects "[$clientContext currentLevelId]" $level
  268.         } else {
  269.             set level "$level/$project"
  270.             set configurationID [$clientContext currentConfig]
  271.             set configuration "[[$configurationID config] name]"
  272.             set configuration "$configuration:[$configurationID versionNumber]"
  273.             if { "$level/$configuration" == "$M4_levelpath" } {
  274.                 # ---------------------------------------------------
  275.                 # configuration level, export this configuration only
  276.                 # ---------------------------------------------------
  277.                 exportConfigurations "[$clientContext currentLevelId]" $level
  278.             } else {
  279.                 set level "$level/$configuration"
  280.                 set phaseID [[$clientContext currentPhase] phase]
  281.                 set phase "[$phaseID name].[$phaseID type]"
  282.                 if { "$level/$phase" == "$M4_levelpath" } {
  283.                     # -----------------------------------
  284.                     # phase level, export this phase only
  285.                     # -----------------------------------
  286.                     exportPhases "[$clientContext currentLevelId]" $level
  287.                 } else {
  288.                     set level "$level/$phase"
  289.                     exportSystems "[$clientContext currentLevelId]" $level
  290.                 }
  291.             }
  292.         }
  293.     }
  294.  
  295.     puts "export Finished"
  296. }
  297.  
  298. # ------------------------------------------
  299. # ugly source, should get rid of this call!!
  300. # ------------------------------------------
  301. global export_dont_run
  302. if { [catch {set export_dont_run}] } {
  303.     exportMain 
  304. }
  305.