 Issue 29400555:
  Issue 4992 - Adds optional revision arg to generate_static_pages  (Closed) 
  Base URL: https://hg.adblockplus.org/cms
    
  
    Issue 29400555:
  Issue 4992 - Adds optional revision arg to generate_static_pages  (Closed) 
  Base URL: https://hg.adblockplus.org/cms| 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,16 @@ | 
| 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() | 
| 
Vasily Kuznetsov
2017/04/03 09:55:08
Perhaps we should add a description here to make t
 
Jon Sonesen
2017/04/03 10:53:52
Done.
 | 
| + parser.add_argument('-r', '--rev', | 
| + help='see "hg help revisions" for more details', | 
| 
Vasily Kuznetsov
2017/04/03 09:55:08
It's nice that you refer to "hg help revisions", b
 
Jon Sonesen
2017/04/03 10:53:52
Done.
 | 
| + default='default') | 
| + parser.add_argument('source', help="Path to your website's repository") | 
| + parser.add_argument('output', help='Path to the desired output directory') | 
| + args = parser.parse_args() | 
| + generate_pages(args.source, args.output, args.rev) |