<?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: SpecMgr</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> SpecMgr
</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>
Virtual base class for handling all types of spec. For each spec you want
to manage, derive a class which must implement at least the following
methods:
</p>
<pre>
list_specs - list specs ("p4 clients"/"p4 labels" etc.)
spec_file - Locate spec file in workspace
</pre>
<p>
Optionally, you may also want to override the changed? method used to
determine whether or not a spec has changed since the last time it was
archived. The default method uses the "Update" timestamp in the
spec, but not all specs have this. If in doubt, changed? should just
evaluate to true anyway, and let the "p4 revert -a" sort it out.
</p>
</div>
<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000026">add_edit_file</a>
<a href="#M000025">changed?</a>
<a href="#M000023">new</a>
<a href="#M000030">revert_unchanged</a>
<a href="#M000028">save_spec</a>
<a href="#M000031">submit</a>
<a href="#M000027">type2name</a>
<a href="#M000024">update</a>
<a href="#M000029">write_ws_file</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="M000023"></a>
<b>new</b>( root, p4tagged, p4untagged )
</td></tr>
</table>
<div class="description">
<p>
Constructor: Supply the client root, and two P4 instances, one with tagged
mode enabled, and one without.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 127</span>
<span class="kw">def</span> initialize( root, p4tagged, p4untagged )
@root = root
@p4t = p4tagged
@p4u = p4untagged
@modlist = Hash.new
<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="M000024"></a>
<b>update</b>( type, since )
</td></tr>
</table>
<div class="description">
<p>
Updates the archives for all specs of the specified type. This is the main
public interface method for this class
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 138</span>
<span class="kw">def</span> update( type, since )
list_specs.each <span class="kw">do</span>
|spec|
save_spec( type, spec ) <span class="kw">if</span> ( changed?( spec, since ) )
<span class="kw">end</span>
submit( description() )
<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="M000025"></a>
<b>changed?</b>( spec, stamp )
</td></tr>
</table>
<div class="description">
<p>
Method to determine whether or not a spec has changed since the specified
timestamp. The default implementation uses the "Update" field of
the spec, but this is not available in all types of spec so this method
should be overridden for those specs. Where there is no easy way to decide
whether or not a spec has changed, override implementations of this method
should just return true and let the "p4 revert -a" sort it all
out.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 157</span>
<span class="kw">def</span> changed?( spec, stamp )
spec[ <span class="str">"Update"</span> ].to_i > stamp
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000026"></a>
<b>add_edit_file</b>( path, name )
</td></tr>
</table>
<div class="description">
<p>
Opens the specified file for add or edit as appropriate
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 164</span>
<span class="kw">def</span> add_edit_file( path, name )
fs = @p4t.run_fstat( path ).shift
<span class="kw">if</span> ( fs )
@p4t.run_edit( path )
<span class="kw">else</span>
@p4t.run_add( <span class="str">"-t"</span>, <span class="str">"text"</span>, path )
fs = @p4t.run_fstat( path ).shift
<span class="kw">end</span>
@modlist[ fs[ <span class="str">"depotFile"</span> ] ] = name
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000027"></a>
<b>type2name</b>( type, spec )
</td></tr>
</table>
<div class="description">
<p>
Compute the name of a spec from its type. Necessary because the field for
jobs is "Job" whilst for clients it's "client" ...
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 179</span>
<span class="kw">def</span> type2name( type, spec )
<span class="kw">return</span> spec[ type ] <span class="kw">if</span> spec.has_key?( type )
<span class="kw">return</span> spec[ type.capitalize ] <span class="kw">if</span> spec.has_key?( type.capitalize )
raise( RuntimeError, <span class="str">"Can't determine object name from type"</span> )
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000028"></a>
<b>save_spec</b>( type, spec )
</td></tr>
</table>
<div class="description">
<p>
Save the named spec into its text file version. As we don't want the spec
in parsed form for this we use the non-tagged P4 instance here to run the
"p4 xxxx -o" and the output of that command is written to the
workspace file.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 191</span>
<span class="kw">def</span> save_spec( type, spec )
path = spec_file( spec )
name = type2name( type, spec )
add_edit_file( path, name )
form = eval( }@p4u.fetch_#{type}( "#{name}" )} )
write_ws_file( path, form )
<span class="kw">end</span>
</pre>
<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000029"></a>
<b>write_ws_file</b>( path, form )
</td></tr>
</table>
<div class="description">
<p>
Method to write form data into the workspace file
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 203</span>
<span class="kw">def</span> write_ws_file( path, form )
File.open( path, <span class="str">"w+"</span> ) <span class="kw">do</span>
|file|
file.write( form )
<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="M000030"></a>
<b>revert_unchanged</b>()
</td></tr>
</table>
<div class="description">
<p>
Revert all unchanged files and remove them from the modlist.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 213</span>
<span class="kw">def</span> revert_unchanged()
@p4t.run_revert( <span class="str">"-a"</span> ).each <span class="kw">do</span>
|r|
r = r.sub( <span class="re">/\#\d+.*/</span>, <span class="str">""</span> )
@modlist.delete( r ) <span class="kw">if</span> @modlist.has_key?( r )
<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="M000031"></a>
<b>submit</b>( desc )
</td></tr>
</table>
<div class="description">
<p>
Submit the changelist and write out a message including the list of objects
being updated.
</p>
</div>
<pre class="source">
<span class="cmt"># File specsaver.rb, line 225</span>
<span class="kw">def</span> submit( desc )
revert_unchanged()
change = @p4t.fetch_change
<span class="kw">if</span> ( change.has_key?( <span class="str">"Files"</span> ) )
change[ <span class="str">"Description"</span> ] = desc
@p4t.submit_spec( change )
puts( desc + <span class="str">"\n\t"</span> + @modlist.values.sort.join( <span class="str">"\n\t"</span> ) )
<span class="kw">end</span>
@modlist = Hash.new
<span class="kw">end</span>
</pre>
</body>