Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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
00102
00103
00104
00105
00106
00107 self.search_for_re = re.compile(
00108
00109
00110
00111
00112
00113
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
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()