specsaver.rb
Path: specsaver.rb
Modified: Mon Apr 14 12:13:49 BST 2003

Introduction

 A Ruby script to detect changes to different types of spec ( client/label/
 branch/etc. ) and to record the changes by checking the specs in as text
 files into a dedicated area of the depot. Designed to be periodically
 executed via either cron or the Windows scheduler depending on platform.

 Note: This script REQUIRES a working build of P4Ruby which you can
       get from the Perforce public depot in
              //guest/tony_smith/perforce/API/Ruby/...

       You'll also need the Perforce API for your platform to build P4Ruby.
 specsaver.rb tries to be as efficient as possible in determining whether
 or not an object has been modified. It doesn't depend on a blanket
 "p4 revert -a" approach, but uses a counter and the built-in timestamps for
 objects that have them.

Getting Started

 The script creates its own clientspec so minimal setup is required. All
 you need to do is to edit the variables in the configuration section and
 ensure that the script has write access to the SPEC_PATH in the depot and
 then you can run it.

 If you want to archive privileged metadata like your protections table,
 then specsaver needs to be run under a super-user account. If you're just
 after clientspecs etc. then no special privileges are required.

Usage

specsaver.rb [ options ]

where options are:

   --all      - archive all types of object
   --branches - archive branch specs
   --clients  - archive client specs
   --config   - archive typemap, protections and jobspec
   --depots   - archive depot definitions
   --groups   - archive group specs
   --jobs     - archive jobs (but not fixes)
   --labels   - archive label views and files
   --users    - archive user specs (not passwords)

Known Uglies

Currently we only use one counter to store a timestamp for all types of object. This is occasionally a source of frustration and at some point I'll adapt the script to use a counter for each type of object. Until then, if you suspect that specsaver.rb isn't catching all the changed objects - usually the result of some human interference - then delete the counter or reset it to zero and let it figure it out for itself. It'll take a while, but it will get it right.

To avoid the problem altogether always use the same arguments when invoking specsaver.rb. i.e. if you invoke it once with --all, then always use --all. If you do want to change your mind, then just delete or reset the counter.

Version

$Id: //guest/tony_smith/perforce/utils/specsaver.rb#11 $

Required files
P4    getoptlong   
Methods
croak_syntax   
Classes and Modules
Class BranchMgr
Class ClientMgr
Class ConfigMgr
Class DepotMgr
Class GenSpecMgr
Class GroupMgr
Class JobMgr
Class LabelMgr
Class SpecMgr
Class SpecSaver
Class UserMgr
Public Instance methods
croak_syntax()

Dump the usage information to stdout and exit.

# File specsaver.rb, line 789
def croak_syntax
    puts( }

Usage: specsaver.rb [ options ]

where options are:

    --all	- archive all types of object
    --branches	- archive branch specs
    --clients	- archive client specs
    --config	- archive typemap, protections and jobspec
    --depots	- archive depot definitions
    --groups	- archive group specs
    --jobs	- archive jobs (but not fixes)
    --labels	- archive label views and files
    --users	- archive user specs (not passwords)

} )
    exit( 0 )
end