release_docs.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2013 Google Inc. All Rights Reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are
00007 # met:
00008 #
00009 #     * Redistributions of source code must retain the above copyright
00010 # notice, this list of conditions and the following disclaimer.
00011 #     * Redistributions in binary form must reproduce the above
00012 # copyright notice, this list of conditions and the following disclaimer
00013 # in the documentation and/or other materials provided with the
00014 # distribution.
00015 #     * Neither the name of Google Inc. nor the names of its
00016 # contributors may be used to endorse or promote products derived from
00017 # this software without specific prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 """Script for branching Google Test/Mock wiki pages for a new version.
00032 
00033 SYNOPSIS
00034        release_docs.py NEW_RELEASE_VERSION
00035 
00036        Google Test and Google Mock's external user documentation is in
00037        interlinked wiki files.  When we release a new version of
00038        Google Test or Google Mock, we need to branch the wiki files
00039        such that users of a specific version of Google Test/Mock can
00040        look up documenation relevant for that version.  This script
00041        automates that process by:
00042 
00043          - branching the current wiki pages (which document the
00044            behavior of the SVN trunk head) to pages for the specified
00045            version (e.g. branching FAQ.wiki to V2_6_FAQ.wiki when
00046            NEW_RELEASE_VERSION is 2.6);
00047          - updating the links in the branched files to point to the branched
00048            version (e.g. a link in V2_6_FAQ.wiki that pointed to
00049            Primer.wiki#Anchor will now point to V2_6_Primer.wiki#Anchor).
00050 
00051        NOTE: NEW_RELEASE_VERSION must be a NEW version number for
00052        which the wiki pages don't yet exist; otherwise you'll get SVN
00053        errors like "svn: Path 'V1_7_PumpManual.wiki' is not a
00054        directory" when running the script.
00055 
00056 EXAMPLE
00057        $ cd PATH/TO/GTEST_SVN_WORKSPACE/trunk
00058        $ scripts/release_docs.py 2.6  # create wiki pages for v2.6
00059        $ svn status                   # verify the file list
00060        $ svn diff                     # verify the file contents
00061        $ svn commit -m "release wiki pages for v2.6"
00062 """
00063 
00064 __author__ = 'wan@google.com (Zhanyong Wan)'
00065 
00066 import os
00067 import re
00068 import sys
00069 
00070 import common
00071 
00072 
00073 # Wiki pages that shouldn't be branched for every gtest/gmock release.
00074 GTEST_UNVERSIONED_WIKIS = ['DevGuide.wiki']
00075 GMOCK_UNVERSIONED_WIKIS = [
00076     'DesignDoc.wiki',
00077     'DevGuide.wiki',
00078     'KnownIssues.wiki'
00079     ]
00080 
00081 
00082 def DropWikiSuffix(wiki_filename):
00083   """Removes the .wiki suffix (if any) from the given filename."""
00084 
00085   return (wiki_filename[:-len('.wiki')] if wiki_filename.endswith('.wiki')
00086           else wiki_filename)
00087 
00088 
00089 class WikiBrancher(object):
00090   """Branches ..."""
00091 
00092   def __init__(self, dot_version):
00093     self.project, svn_root_path = common.GetSvnInfo()
00094     if self.project not in ('googletest', 'googlemock'):
00095       sys.exit('This script must be run in a gtest or gmock SVN workspace.')
00096     self.wiki_dir = svn_root_path + '/wiki'
00097     # Turn '2.6' to 'V2_6_'.
00098     self.version_prefix = 'V' + dot_version.replace('.', '_') + '_'
00099     self.files_to_branch = self.GetFilesToBranch()
00100     page_names = [DropWikiSuffix(f) for f in self.files_to_branch]
00101     # A link to Foo.wiki is in one of the following forms:
00102     #   [Foo words]
00103     #   [Foo#Anchor words]
00104     #   [http://code.google.com/.../wiki/Foo words]
00105     #   [http://code.google.com/.../wiki/Foo#Anchor words]
00106     # We want to replace 'Foo' with 'V2_6_Foo' in the above cases.
00107     self.search_for_re = re.compile(
00108         # This regex matches either
00109         #   [Foo
00110         # or
00111         #   /wiki/Foo
00112         # followed by a space or a #, where Foo is the name of an
00113         # unversioned wiki page.
00114         r'(\[|/wiki/)(%s)([ #])' % '|'.join(page_names))
00115     self.replace_with = r'\1%s\2\3' % (self.version_prefix,)
00116 
00117   def GetFilesToBranch(self):
00118     """Returns a list of .wiki file names that need to be branched."""
00119 
00120     unversioned_wikis = (GTEST_UNVERSIONED_WIKIS if self.project == 'googletest'
00121                          else GMOCK_UNVERSIONED_WIKIS)
00122     return [f for f in os.listdir(self.wiki_dir)
00123             if (f.endswith('.wiki') and
00124                 not re.match(r'^V\d', f) and  # Excluded versioned .wiki files.
00125                 f not in unversioned_wikis)]
00126 
00127   def BranchFiles(self):
00128     """Branches the .wiki files needed to be branched."""
00129 
00130     print 'Branching %d .wiki files:' % (len(self.files_to_branch),)
00131     os.chdir(self.wiki_dir)
00132     for f in self.files_to_branch:
00133       command = 'svn cp %s %s%s' % (f, self.version_prefix, f)
00134       print command
00135       os.system(command)
00136 
00137   def UpdateLinksInBranchedFiles(self):
00138 
00139     for f in self.files_to_branch:
00140       source_file = os.path.join(self.wiki_dir, f)
00141       versioned_file = os.path.join(self.wiki_dir, self.version_prefix + f)
00142       print 'Updating links in %s.' % (versioned_file,)
00143       text = file(source_file, 'r').read()
00144       new_text = self.search_for_re.sub(self.replace_with, text)
00145       file(versioned_file, 'w').write(new_text)
00146 
00147 
00148 def main():
00149   if len(sys.argv) != 2:
00150     sys.exit(__doc__)
00151 
00152   brancher = WikiBrancher(sys.argv[1])
00153   brancher.BranchFiles()
00154   brancher.UpdateLinksInBranchedFiles()
00155 
00156 
00157 if __name__ == '__main__':
00158   main()


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06