home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / repbackupd.tcl < prev    next >
Text File  |  1996-11-29  |  7KB  |  241 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)repbackupd.tcl    /main/hindenburg/15
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)repbackupd.tcl    /main/hindenburg/15   29 Nov 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "repository.tcl"
  13. # End user added include file section
  14.  
  15. require "repdbdialo.tcl"
  16.  
  17. Class RepBackupDialog : {RepDbDialog} {
  18.     constructor
  19.     method destructor
  20.     method popUp
  21.     method ok
  22.     method checkOk
  23.     method backupFinished
  24.     method shutdownServers
  25.     method browseArchive
  26.     attribute archiveBrowser
  27.     attribute archiveButton
  28.     attribute archiveCmd
  29.     attribute archiveDst
  30.     attribute dumpButton
  31. }
  32.  
  33. constructor RepBackupDialog {class this name view} {
  34.     set this [RepDbDialog::constructor $class $this $name $view]
  35.     # Start constructor user section
  36.  
  37.         set rep [[$this view] rep]
  38.         set name [$rep currentName]
  39.         set corp [$rep currentCorporate]
  40.  
  41.         $this config \
  42.             -title "Backup Repository '$name'" \
  43.             -okPressed { busy { %this ok } } \
  44.         -helpPressed { [%this view] helpOnName backupRepository }
  45.  
  46.         interface DlgColumn $this.gui {
  47.         verStretchFactor 0
  48.             NamedGroup backup {
  49.                 label "Backup"
  50.                 DlgColumn c {
  51.             CheckButton dump {
  52.             label "Dump Database"
  53.             state 1
  54.             }
  55.             CheckButton archive {
  56.             label "Archive Repository Directory"
  57.             state 1
  58.             }
  59.             DlgColumn dst {
  60.             Label l {
  61.                 text "Destination File"
  62.                 horStretchFactor 100
  63.             }
  64.             DlgRow r {
  65.                 spaceType NONE
  66.                 DlgColumn d {
  67.                 spaceType EVEN
  68.                 horStretchFactor 100
  69.                 SingleLineText dst {
  70.                     columnCount 30
  71.                     horStretchFactor 100
  72.                 }
  73.                 }
  74.                 DlgColumn b {
  75.                 spaceType EVEN
  76.                 horStretchFactor 0
  77.                 PushButton browse {
  78.                     label "Browse..."
  79.                     horStretchFactor 0
  80.                 }
  81.                 }
  82.             }
  83.             }
  84.             DlgColumn cmd {
  85.             Label l {
  86.                             text "Command to archive repository directory"
  87.                         }
  88.             SingleLineText cmd {
  89.                 columnCount 30
  90.             }
  91.                     }
  92.                 }
  93.             }
  94.             NamedGroup db {
  95.                 label "Database"
  96.                 DlgColumn attr {
  97.             verStretchFactor 0
  98.                 }
  99.             }
  100.         }
  101.  
  102.         PushButton new $this.shutdown \
  103.             -label "Shutdown" \
  104.             -activated "busy { $this shutdownServers }"
  105.  
  106.         set a $this.gui.backup.c
  107.         $this dumpButton $a.dump
  108.         $this archiveButton $a.archive
  109.         $this archiveCmd $a.cmd.cmd
  110.         $this archiveDst $a.dst.r.d.dst
  111.         set   archiveBrowse $a.dst.r.b.browse
  112.  
  113.         [$this dumpButton] stateChanged "$this checkOk"
  114.         [$this archiveCmd] textModified "$this checkOk"
  115.         [$this archiveButton] stateChanged "
  116.             [$this archiveCmd] sensitive \[%this state]
  117.             [$this archiveDst] sensitive \[%this state]
  118.             $archiveBrowse sensitive \[%this state]
  119.             $this checkOk
  120.         "
  121.         $archiveBrowse activated "$this browseArchive"
  122.  
  123.         # Default destination archive: repository name with
  124.         # "_backup" appended.
  125.         #
  126.         set dst [path_name concat [$corp location] ${name}_backup]
  127.         [$this archiveDst] text $dst
  128.  
  129.         $this createDbInterface $this.gui.db.attr 30
  130.         $this setDbFields
  131.         $this setupForPassword
  132.  
  133.     # End constructor user section
  134.     return $this
  135. }
  136.  
  137. method RepBackupDialog::destructor {this} {
  138.     # Start destructor user section
  139.     # End destructor user section
  140.     $this RepDbDialog::destructor
  141. }
  142.  
  143. method RepBackupDialog::popUp {this} {
  144.     [$this archiveCmd] text [m4_var get M4_archive_cmd]
  145.     $this checkOk
  146.     $this RepDbDialog::popUp
  147. }
  148.  
  149. method RepBackupDialog::ok {this} {
  150.     m4_var set M4_archive_cmd [[$this archiveCmd] text]
  151.  
  152.     if ![$this getDbFields cmdInfo] {
  153.     [$this view] message "Repository not backed up."
  154.         return
  155.     }
  156.  
  157.     set rep [[$this view] rep]
  158.     set name [$rep currentName]
  159.  
  160.     set dump [[$this dumpButton] state]
  161.     set archive [[$this archiveButton] state]
  162.  
  163.     if $archive {
  164.     set dst [Repository::expandDirName [[$this archiveDst] text]]
  165.     set cmd [[$this archiveCmd] text]
  166.     if {[string length $cmd] == 0} {
  167.         [$this view] error "No archive command specified."
  168.         [$this view] message "Repository not backed up."
  169.         return
  170.     }
  171.     } else {
  172.         set dst ""
  173.         set cmd ""
  174.     }
  175.  
  176.     if $dump {
  177.     $rep backupRepository "$this backupFinished" cmdInfo \
  178.                     {} $name {} $archive $dst
  179.     } elseif $archive {
  180.     $rep archiveRepository "$this backupFinished" $dst
  181.     } else {
  182.         [$this view] warning "Nothing to backup."
  183.     [$this view] message "Repository not backed up."
  184.     }
  185. }
  186.  
  187. method RepBackupDialog::checkOk {this} {
  188.     if {[[$this dumpButton] state] || [[$this archiveButton] state]} {
  189.         if {[[$this archiveButton] state] &&
  190.             [string length [[$this archiveCmd] text]] == 0} {
  191.         $this okSensitive 0
  192.         } elseif {[[$this dumpButton] state] &&
  193.                   ![$this passwordOk]} {
  194.         $this okSensitive 0
  195.         } else {
  196.         $this okSensitive 1
  197.         }
  198.     } else {
  199.         $this okSensitive 0
  200.     }
  201. }
  202.  
  203. method RepBackupDialog::backupFinished {this exitCode} {
  204.     set rep [[$this view] rep]
  205.     set name [$rep currentName]
  206.  
  207.     if {$exitCode == 0} {
  208.     [$this view] message "Backed up repository '$name' successfully."
  209.     } else {
  210.         [$this view] message "Backup of repository '$name' failed."
  211.     }
  212. }
  213.  
  214. method RepBackupDialog::shutdownServers {this} {
  215.     set rep [[$this view] rep]
  216.     set name [$rep currentName]
  217.  
  218.     $rep shutdownDbServers $name
  219. }
  220.  
  221. method RepBackupDialog::browseArchive {this} {
  222.     if {[$this archiveBrowser] == ""} {
  223.         $this archiveBrowser [FileChooser new [$this view].archivebrowser \
  224.         -selectionPolicy SINGLE \
  225.         -title "Select Destination Archive" \
  226.         -okPressed \
  227.                 "[$this archiveDst] text \[lindex \[%this selectedSet] 0]"]
  228.         [$this archiveBrowser] delHelpButton
  229.     }
  230.  
  231.     set file [Repository::expandFileName [[$this archiveDst] text]]
  232.     Repository::expandDirName [file dir $file] existingDir
  233.  
  234.     [$this archiveBrowser] selectedSet $file
  235.     [$this archiveBrowser] directory $existingDir
  236.     [$this archiveBrowser] popUp
  237. }
  238.  
  239. # Do not delete this line -- regeneration end marker
  240.  
  241.