<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html><head>
<title>Class: SpecSaver</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel=StyleSheet href=".././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript" language="JavaScript">
<!--
function popCode(url) {
window.open(url, "Code",
"resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
//-->
</script>
</head>
<body bgcolor="white">
<table summary="Information on class" width="100%" border="0" cellspacing="0">
<tr class="title-row">
<td class="big-title-font">
<sup><font color="aqua">Class</font></sup> SpecSaver
</td>
<td align="right">
<table summary="layout" cellspacing="0" cellpadding="2">
<tr valign="top">
<td class="small-title-font">In:</td>
<td class="small-title-font">
<a href="../files/specsaver_rb.html" class="aqua">
specsaver.rb
</a>
<br />
</td>
</tr>
<tr>
<td class="small-title-font">Parent:</td>
<td class="small-title-font">
Object
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- banner header -->
<div class="description"><p>
Main top level class for co-ordinating the run. Here we can trap Perforce
exceptions and look after the overall environment.
</p>
</div>
<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000041">counter=</a>
<a href="#M000040">counter?</a>
<a href="#M000039">create_client</a>
<a href="#M000033">debug</a>
<a href="#M000035">have_flags?</a>
<a href="#M000037">init_client</a>
<a href="#M000038">init_workspace</a>
<a href="#M000036">method_missing</a>
<a href="#M000032">new</a>
<a href="#M000034">update</a>
</div>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Class methods</td></tr>
</table>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000032"></a>
<b>new</b>()
</td></tr>
</table>
<div class="description">
<p>
Constructor
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 585</span>
<span class="kw">def</span> initialize
@flags = Hash.new
<span class="cmt"># Perforce client for handling tagged output</span>
@p4t = P4.new
@p4t.parse_forms
@p4t.exception_level = 1
@p4t.port = P4PORT
@p4t.user = P4USER
@p4t.password = P4PASSWD
@p4t.client = P4CLIENT
@p4t.connect
<span class="cmt"># Perforce client for non-tagged output</span>
@p4u = P4.new
@p4u.exception_level = 1
@p4u.port = P4PORT
@p4u.user = P4USER
@p4u.password = P4PASSWD
@p4u.client = P4CLIENT
@p4u.connect
<span class="cmt"># Set the client root</span>
@root = CLIENTROOT
init_client()
<span class="kw">end</span>
</pre>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Instance methods</td></tr>
</table>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000033"></a>
<b>debug</b>( level )
</td></tr>
</table>
<div class="description">
<p>
Set the debug level. Useful levels are:
</p>
<pre>
0 (default) - No debug output
1 - Some debug output
2 - More debug output
</pre>
<p>
What more could you want?
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 623</span>
<span class="kw">def</span> debug( level )
$stderr.puts( "Setting debug level to #{level}" )
@p4u.disconnect
@p4t.disconnect
@p4u.debug = level
@p4t.debug = level
@p4u.connect
@p4t.connect
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000034"></a>
<b>update</b>()
</td></tr>
</table>
<div class="description">
<p>
Main interface method. Update all requested specs.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 636</span>
<span class="kw">def</span> update
<span class="cmt"># Timestamp for this run</span>
now = Time.now.to_i
<span class="cmt"># time of last update </span>
since = counter?
<span class="kw">begin</span>
branches = BranchMgr.new( @root, @p4t, @p4u )
clients = ClientMgr.new( @root, @p4t, @p4u )
depots = DepotMgr.new( @root, @p4t, @p4u )
groups = GroupMgr.new( @root, @p4t, @p4u )
jobs = JobMgr.new( @root, @p4t, @p4u )
labels = LabelMgr.new( @root, @p4t, @p4u )
users = UserMgr.new( @root, @p4t, @p4u )
config = ConfigMgr.new( @root, @p4t, @p4u )
branches.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.branches? )
clients.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.clients? )
depots.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.depots? )
groups.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.groups? )
jobs.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.jobs? )
labels.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.labels? )
users.update( since ) <span class="kw">if</span> ( <span class="kw">self</span>.users? )
<span class="kw">if</span> ( <span class="kw">self</span>.config? )
config.update( <span class="str">"protect"</span>, <span class="str">"protections"</span> )
config.update( <span class="str">"jobspec"</span>, <span class="str">"jobspec"</span> )
config.update( <span class="str">"typemap"</span>, <span class="str">"typemap"</span> )
<span class="kw">end</span>
<span class="cmt"># Save the counter.</span>
<span class="kw">self</span>.counter = now
<span class="kw">rescue</span> P4Exception
@p4t.errors.each{ |e| puts( e ) }
@p4u.errors.each{ |e| puts( e ) }
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000035"></a>
<b>have_flags?</b>()
</td></tr>
</table>
<div class="description">
<p>
Test whether or not any flags at all have been set.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 679</span>
<span class="kw">def</span> have_flags?
<span class="kw">return</span> ! @flags.empty?
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000036"></a>
<b>method_missing</b>( m, *args )
</td></tr>
</table>
<div class="description">
<p>
Resolve missing methods by looking in the flags hash. This is used to
implement get and set methods for specifying which types of spec should be
archived. If the method name ends in a "?" it's a getter, if not,
it's a setter.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 689</span>
<span class="kw">def</span> method_missing( m, *args )
method = m.to_s
<span class="kw">if</span> ( method !~ <span class="re">/\?$/</span> )
<span class="cmt"># Assignment</span>
<span class="kw">return</span> @flags[ method ] = <span class="kw">true</span>
<span class="kw">else</span>
method.gsub!( <span class="str">"\\?$"</span>, <span class="str">""</span> )
<span class="kw">end</span>
<span class="kw">if</span> ( @flags.has_key?( method ) )
@flags[ method ]
<span class="kw">elsif</span> ( @flags.has_key?( <span class="str">"all"</span> ) )
@flags[ <span class="str">"all"</span> ]
<span class="kw">else</span>
<span class="kw">false</span>
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Protected Instance methods</td></tr>
</table>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000037"></a>
<b>init_client</b>()
</td></tr>
</table>
<div class="description">
<p>
Initialise the client environment. Check whether or not the client
workspace exists, and if not, create it. Then create any missing
directories and sync to the head revision.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 714</span>
<span class="kw">def</span> init_client()
<span class="kw">begin</span>
@p4t.run_info.each <span class="kw">do</span>
|line|
create_client() <span class="kw">if</span> ( line =~ <span class="re">/^Client unknown./</span> )
<span class="kw">end</span>
init_workspace()
@p4t.run_sync
<span class="kw">rescue</span> P4Exception
@p4t.errors.each { |e| puts( e ) }
raise
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000038"></a>
<b>init_workspace</b>()
</td></tr>
</table>
<div class="description">
<p>
Initialises the workspace by pre-creating a directory for each spec type
ready for the workspace files to be written into.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 732</span>
<span class="kw">def</span> init_workspace()
Dir.mkdir( @root ) <span class="kw">unless</span> ( File.exists?( @root ) )
SPECS.each <span class="kw">do</span>
|type|
dir = @root + <span class="str">"/"</span> + type
Dir.mkdir( dir ) <span class="kw">unless</span> ( File.exists?( dir ) )
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000039"></a>
<b>create_client</b>()
</td></tr>
</table>
<div class="description">
<p>
Automatically create the client workspace if necessary. This ensures that
<a href="../files/specsaver_rb.html">specsaver.rb</a> is less prone to
dodgy client views than scripts that require the client to be pre-created.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 746</span>
<span class="kw">def</span> create_client()
<span class="kw">begin</span>
spec = @p4t.fetch_client
spec[ <span class="str">"Description"</span> ] = <span class="str">"Client for spec versioning script"</span>
spec[ <span class="str">"Root"</span> ] = @root
<span class="cmt"># Don't use String#gsub! it seems to cause problems</span>
opt = spec[ <span class="str">"Options"</span> ].gsub( <span class="str">"normdir"</span>, <span class="str">"rmdir"</span> )
spec[ <span class="str">"Options"</span> ] = opt
spec[ <span class="str">"View"</span> ] = Array.new
spec[ <span class="str">"View"</span> ].push( SPEC_PATH + <span class="str">"/... //"</span> + @p4t.client? + <span class="str">"/..."</span> )
@p4t.save_client( spec )
<span class="kw">rescue</span> P4Exception
@p4t.errors.each { |e| puts( e ) }
<span class="kw">end</span>
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000040"></a>
<b>counter?</b>()
</td></tr>
</table>
<div class="description">
<p>
Get the value of the SPEC_COUNTER. This is used as a timestamp rather than
a traditional counter.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 769</span>
<span class="kw">def</span> counter?
c = @p4t.run_counter( SPEC_COUNTER ).shift.to_i
<span class="kw">return</span> c
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000041"></a>
<b>counter=</b>( val )
</td></tr>
</table>
<div class="description">
<p>
Update the SPEC_COUNTER with a new value.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 777</span>
<span class="kw">def</span> counter=( val )
@p4t.run_counter( SPEC_COUNTER, val )
<span class="kw">true</span>
<span class="kw">end</span>
</pre>
</body>