Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/bin/generate_static_pages.py

Issue 29400555: Issue 4992 - Adds optional revision arg to generate_static_pages (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: fixed redundant sys.argv definition Created April 4, 2017, 6:59 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/bin/generate_static_pages.py
===================================================================
--- a/cms/bin/generate_static_pages.py
+++ b/cms/bin/generate_static_pages.py
@@ -8,23 +8,23 @@
# Adblock Plus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
-import sys
import os
import re
import errno
import codecs
import ConfigParser
import logging
+from argparse import ArgumentParser
from cms.utils import get_page_params, process_page
from cms.sources import MercurialSource
MIN_TRANSLATED = 0.3
def memoize(func):
@@ -34,17 +34,17 @@
try:
return memoized[args]
except KeyError:
return memoized.setdefault(args, func(*args))
wrapper.clear_cache = memoized.clear
return wrapper
-def generate_pages(repo, output_dir):
+def generate_pages(repo, output_dir, revision):
known_files = set()
def write_file(path_parts, contents, binary=False):
encoding = None if binary else 'utf-8'
outfile = os.path.join(output_dir, *path_parts)
if outfile in known_files:
logging.warning('File %s has multiple sources', outfile)
return
@@ -59,17 +59,17 @@
os.makedirs(os.path.dirname(outfile))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with codecs.open(outfile, 'wb', encoding=encoding) as handle:
handle.write(contents)
- with MercurialSource(repo) as source:
+ with MercurialSource(repo, revision) as source:
# Cache the result for some functions - we can assume here that the data
# never changes
source.resolve_link = memoize(source.resolve_link)
source.read_config = memoize(source.read_config)
source.read_template = memoize(source.read_template)
source.read_locale = memoize(source.read_locale)
source.read_include = memoize(source.read_include)
source.exec_file = memoize(source.exec_file)
@@ -139,14 +139,17 @@
os.remove(path)
elif os.path.isdir(path):
remove_unknown(path)
if not os.listdir(path):
os.rmdir(path)
remove_unknown(output_dir)
if __name__ == '__main__':
- if len(sys.argv) < 3:
- print >>sys.stderr, 'Usage: %s source_repository output_dir' % sys.argv[0]
- sys.exit(1)
-
- repo, output_dir = sys.argv[1:3]
- generate_pages(repo, output_dir)
+ parser = ArgumentParser('Convert website source to static website')
+ parser.add_argument('-r', '--rev',
+ help=('Specify which revision to generate from. '
+ 'See "hg help revisions" for details.'),
+ default='default')
+ parser.add_argument('source', help="Path to website's repository")
+ parser.add_argument('output', help='Path to desired output directory')
+ args = parser.parse_args()
+ generate_pages(args.source, args.output, args.rev)
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld