/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc.

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#ifndef cmCTestVC_h
#define cmCTestVC_h

#include "cmProcessTools.h"

class cmCTest;
class cmXMLWriter;

/** \class cmCTestVC
 * \brief Base class for version control system handlers
 *
 */
class cmCTestVC: public cmProcessTools
{
public:
  /** Construct with a CTest instance and update log stream.  */
  cmCTestVC(cmCTest* ctest, std::ostream& log);

  virtual ~cmCTestVC();

  /** Command line tool to invoke.  */
  void SetCommandLineTool(std::string const& tool);

  /** Top-level source directory.  */
  void SetSourceDirectory(std::string const& dir);

  /** Get the date/time specification for the current nightly start time.  */
  std::string GetNightlyTime();

  /** Prepare the work tree.  */
  bool InitialCheckout(const char* command);

  /** Perform cleanup operations on the work tree.  */
  void Cleanup();

  /** Update the working tree to the new revision.  */
  bool Update();

  /** Get the command line used by the Update method.  */
  std::string const& GetUpdateCommandLine() const
    { return this->UpdateCommandLine; }

  /** Write Update.xml entries for the updates found.  */
  bool WriteXML(cmXMLWriter& xml);

  /** Enumerate non-trivial working tree states during update.  */
  enum PathStatus { PathUpdated, PathModified, PathConflicting };

  /** Get the number of working tree paths in each state after update.  */
  int GetPathCount(PathStatus s) const { return this->PathCount[s]; }

protected:
  // Internal API to be implemented by subclasses.
  virtual void CleanupImpl();
  virtual void NoteOldRevision();
  virtual bool UpdateImpl();
  virtual void NoteNewRevision();
  virtual bool WriteXMLUpdates(cmXMLWriter& xml);

#if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
public: // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
#endif
  /** Basic information about one revision of a tree or file.  */
  struct Revision
  {
    std::string Rev;
    std::string Date;
    std::string Author;
    std::string EMail;
    std::string Committer;
    std::string CommitterEMail;
    std::string CommitDate;
    std::string Log;
  };

protected:
  struct File;
  friend struct File;

  /** Represent change to one file.  */
  struct File
  {
    PathStatus Status;
    Revision const* Rev;
    Revision const* PriorRev;
    File(): Status(PathUpdated), Rev(0), PriorRev(0) {}
    File(PathStatus status, Revision const* rev, Revision const* priorRev):
      Status(status), Rev(rev), PriorRev(priorRev) {}
  };

  /** Convert a list of arguments to a human-readable command line.  */
  static std::string ComputeCommandLine(char const* const* cmd);

  /** Run a command line and send output to given parsers.  */
  bool RunChild(char const* const* cmd, OutputParser* out,
                OutputParser* err, const char* workDir = 0);

  /** Run VC update command line and send output to given parsers.  */
  bool RunUpdateCommand(char const* const* cmd,
                        OutputParser* out, OutputParser* err = 0);

  /** Write xml element for one file.  */
  void WriteXMLEntry(cmXMLWriter& xml, std::string const& path,
                     std::string const& name, std::string const& full,
                     File const& f);

  // Instance of cmCTest running the script.
  cmCTest* CTest;

  // A stream to which we write log information.
  std::ostream& Log;

  // Basic information about the working tree.
  std::string CommandLineTool;
  std::string SourceDirectory;

  // Record update command info.
  std::string UpdateCommandLine;

  // Placeholder for unknown revisions.
  Revision Unknown;

  // Count paths reported with each PathStatus value.
  int PathCount[3];
};

#endif

<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
<a id='n29' href='#n29'>29</a>
<a id='n30' href='#n30'>30</a>
<a id='n31' href='#n31'>31</a>
<a id='n32' href='#n32'>32</a>
<a id='n33' href='#n33'>33</a>
<a id='n34' href='#n34'>34</a>
<a id='n35' href='#n35'>35</a>
<a id='n36' href='#n36'>36</a>
<a id='n37' href='#n37'>37</a>
<a id='n38' href='#n38'>38</a>
<a id='n39' href='#n39'>39</a>
<a id='n40' href='#n40'>40</a>
<a id='n41' href='#n41'>41</a>
<a id='n42' href='#n42'>42</a>
<a id='n43' href='#n43'>43</a>
<a id='n44' href='#n44'>44</a>
<a id='n45' href='#n45'>45</a>
<a id='n46' href='#n46'>46</a>
<a id='n47' href='#n47'>47</a>
<a id='n48' href='#n48'>48</a>
<a id='n49' href='#n49'>49</a>
<a id='n50' href='#n50'>50</a>
<a id='n51' href='#n51'>51</a>
<a id='n52' href='#n52'>52</a>
<a id='n53' href='#n53'>53</a>
<a id='n54' href='#n54'>54</a>
<a id='n55' href='#n55'>55</a>
<a id='n56' href='#n56'>56</a>
<a id='n57' href='#n57'>57</a>
<a id='n58' href='#n58'>58</a>
<a id='n59' href='#n59'>59</a>
<a id='n60' href='#n60'>60</a>
<a id='n61' href='#n61'>61</a>
<a id='n62' href='#n62'>62</a>
<a id='n63' href='#n63'>63</a>
<a id='n64' href='#n64'>64</a>
<a id='n65' href='#n65'>65</a>
<a id='n66' href='#n66'>66</a>
<a id='n67' href='#n67'>67</a>
<a id='n68' href='#n68'>68</a>
<a id='n69' href='#n69'>69</a>
<a id='n70' href='#n70'>70</a>
<a id='n71' href='#n71'>71</a>
</pre></td>
<td class='lines'><pre><code><span class="hl kwa">from</span> test_support <span class="hl kwa">import</span> verbose
<span class="hl kwa">import</span> pwd

<span class="hl kwa">print</span> <span class="hl str">'pwd.getpwall()'</span>
entries <span class="hl opt">=</span> pwd<span class="hl opt">.</span><span class="hl kwd">getpwall</span><span class="hl opt">()</span>

<span class="hl kwa">for</span> e <span class="hl kwa">in</span> entries<span class="hl opt">:</span>
    name <span class="hl opt">=</span> e<span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">]</span>
    uid <span class="hl opt">=</span> e<span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">]</span>
    <span class="hl kwa">if</span> verbose<span class="hl opt">:</span>
        <span class="hl kwa">print</span> name<span class="hl opt">,</span> uid
    <span class="hl kwa">print</span> <span class="hl str">'pwd.getpwuid()'</span>
    dbuid <span class="hl opt">=</span> pwd<span class="hl opt">.</span><span class="hl kwd">getpwuid</span><span class="hl opt">(</span>uid<span class="hl opt">)</span>
    <span class="hl kwa">if</span> dbuid<span class="hl opt">[</span><span class="hl num">0</span><span class="hl opt">] !=</span> name<span class="hl opt">:</span>
        <span class="hl kwa">print</span> <span class="hl str">'Mismatch in pwd.getpwuid()'</span>
    <span class="hl kwa">print</span> <span class="hl str">'pwd.getpwnam()'</span>
    dbname <span class="hl opt">=</span> pwd<span class="hl opt">.</span><span class="hl kwd">getpwnam</span><span class="hl opt">(</span>name<span class="hl opt">)</span>
    <span class="hl kwa">if</span> dbname<span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">] !=</span> uid<span class="hl opt">:</span>
        <span class="hl kwa">print</span> <span class="hl str">'Mismatch in pwd.getpwnam()'</span>
    <span class="hl kwa">else</span><span class="hl opt">:</span>
        <span class="hl kwa">print</span> <span class="hl str">'name matches uid'</span>
    <span class="hl kwa">break</span>

<span class="hl slc"># try to get some errors</span>
bynames <span class="hl opt">= {}</span>
byuids <span class="hl opt">= {}</span>
<span class="hl kwa">for</span> n<span class="hl opt">,</span> p<span class="hl opt">,</span> u<span class="hl opt">,</span> g<span class="hl opt">,</span> gecos<span class="hl opt">,</span> d<span class="hl opt">,</span> s <span class="hl kwa">in</span> entries<span class="hl opt">:</span>
    bynames<span class="hl opt">[</span>n<span class="hl opt">] =</span> u
    byuids<span class="hl opt">[</span>u<span class="hl opt">] =</span> n

allnames <span class="hl opt">=</span> bynames<span class="hl opt">.</span><span class="hl kwd">keys</span><span class="hl opt">()</span>
namei <span class="hl opt">=</span> <span class="hl num">0</span>
fakename <span class="hl opt">=</span> allnames<span class="hl opt">[</span>namei<span class="hl opt">]</span>
<span class="hl kwa">while</span> bynames<span class="hl opt">.</span><span class="hl kwd">has_key</span><span class="hl opt">(</span>fakename<span class="hl opt">):</span>
    chars <span class="hl opt">=</span> <span class="hl kwb">map</span><span class="hl opt">(</span><span class="hl kwa">None</span><span class="hl opt">,</span> fakename<span class="hl opt">)</span>
    <span class="hl kwa">for</span> i <span class="hl kwa">in</span> <span class="hl kwb">range</span><span class="hl opt">(</span><span class="hl kwb">len</span><span class="hl opt">(</span>chars<span class="hl opt">)):</span>
        <span class="hl kwa">if</span> chars<span class="hl opt">[</span>i<span class="hl opt">] ==</span> <span class="hl str">'z'</span><span class="hl opt">:</span>
            chars<span class="hl opt">[</span>i<span class="hl opt">] =</span> <span class="hl str">'A'</span>
            <span class="hl kwa">break</span>
        <span class="hl kwa">elif</span> chars<span class="hl opt">[</span>i<span class="hl opt">] ==</span> <span class="hl str">'Z'</span><span class="hl opt">:</span>
            <span class="hl kwa">continue</span>
        <span class="hl kwa">else</span><span class="hl opt">:</span>
            chars<span class="hl opt">[</span>i<span class="hl opt">] =</span> <span class="hl kwb">chr</span><span class="hl opt">(</span><span class="hl kwb">ord</span><span class="hl opt">(</span>chars<span class="hl opt">[</span>i<span class="hl opt">]) +</span> <span class="hl num">1</span><span class="hl opt">)</span>
            <span class="hl kwa">break</span>
    <span class="hl kwa">else</span><span class="hl opt">:</span>
        namei <span class="hl opt">=</span> namei <span class="hl opt">+</span> <span class="hl num">1</span>
        <span class="hl kwa">try</span><span class="hl opt">:</span>
            fakename <span class="hl opt">=</span> allnames<span class="hl opt">[</span>namei<span class="hl opt">]</span>
        <span class="hl kwa">except</span> <span class="hl kwc">IndexError</span><span class="hl opt">:</span>
            <span class="hl slc"># should never happen... if so, just forget it</span>
            <span class="hl kwa">break</span>
    fakename <span class="hl opt">=</span> <span class="hl str">''</span><span class="hl opt">.</span><span class="hl kwd">join</span><span class="hl opt">(</span><span class="hl kwb">map</span><span class="hl opt">(</span><span class="hl kwa">None</span><span class="hl opt">,</span> chars<span class="hl opt">))</span>

<span class="hl kwa">try</span><span class="hl opt">:</span>
    pwd<span class="hl opt">.</span><span class="hl kwd">getpwnam</span><span class="hl opt">(</span>fakename<span class="hl opt">)</span>
<span class="hl kwa">except</span> <span class="hl kwc">KeyError</span><span class="hl opt">:</span>
    <span class="hl kwa">print</span> <span class="hl str">'caught expected exception'</span>
<span class="hl kwa">else</span><span class="hl opt">:</span>
    <span class="hl kwa">print</span> <span class="hl str">'fakename'</span><span class="hl opt">,</span> fakename<span class="hl opt">,</span> <span class="hl str">'did not except pwd.getpwnam()'</span>

<span class="hl slc"># Choose a non-existent uid.</span>
fakeuid <span class="hl opt">=</span> <span class="hl num">4127</span>
<span class="hl kwa">while</span> byuids<span class="hl opt">.</span><span class="hl kwd">has_key</span><span class="hl opt">(</span>fakeuid<span class="hl opt">):</span>
    fakeuid <span class="hl opt">= (</span>fakeuid <span class="hl opt">*</span> <span class="hl num">3</span><span class="hl opt">) %</span> <span class="hl num">0x10000</span>

<span class="hl kwa">try</span><span class="hl opt">:</span>
    pwd<span class="hl opt">.</span><span class="hl kwd">getpwuid</span><span class="hl opt">(</span>fakeuid<span class="hl opt">)</span>
<span class="hl kwa">except</span> <span class="hl kwc">KeyError</span><span class="hl opt">:</span>
    <span class="hl kwa">print</span> <span class="hl str">'caught expected exception'</span>
<span class="hl kwa">else</span><span class="hl opt">:</span>
    <span class="hl kwa">print</span> <span class="hl str">'fakeuid'</span><span class="hl opt">,</span> fakeuid<span class="hl opt">,</span> <span class="hl str">'did not except pwd.getpwuid()'</span>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit v0.12</a> at 2025-03-10 20:22:57 (GMT)</div>
</div> <!-- id=cgit -->
</body>
</html>