# HG changeset patch # User Dan Buch # Date 1323236130 18000 # Node ID 8506a84ece82de884742715df31fba92781b2fe7 # Parent e0d072b2e7d00e7aa3f031e1a817da2c32f72740 Converting one last admin script to python diff -r e0d072b2e7d00e7aa3f031e1a817da2c32f72740 -r 8506a84ece82de884742715df31fba92781b2fe7 devscripts/fetch-reindent-versions --- a/devscripts/fetch-reindent-versions Wed Dec 07 00:17:39 2011 -0500 +++ b/devscripts/fetch-reindent-versions Wed Dec 07 00:35:30 2011 -0500 @@ -1,13 +1,44 @@ -#!/bin/bash +#!/usr/bin/env python +from __future__ import print_function -TOP=$(dirname $(dirname $(readlink -f $0))) -REPO_BASE="http://hg.python.org/cpython-fullhistory" +import sys +from os.path import dirname, abspath, join as pathjoin +from urllib2 import urlopen -for tag in "2.3.7" "2.4.6" "2.5.5" "2.6.6" "2.7.1" "3.0.1" "3.1.3" "3.2" -do - vnum="v$(echo $tag | sed 's/\.//g' | cut -b 1-2)" - dest="${TOP}/reindent/${vnum}/reindent.py" - dl_url="${REPO_BASE}/raw-file/v${tag}/Tools/scripts/reindent.py" - echo "Downloading ${dl_url} to ${dest}" - curl "${dl_url}" > "${dest}" 2>/dev/null -done +TOP = dirname(dirname(abspath(__file__))) +REPO_BASE = "http://hg.python.org/cpython-fullhistory" +TAGS_VERSIONS = { + '2.3.7': '23', + '2.4.6': '24', + '2.5.5': '25', + '2.6.6': '26', + '2.7.1': '27', + '3.0.1': '30', + '3.1.3': '31', + '3.2': '32' +} + + +def main(): + for tag, vnum in TAGS_VERSIONS.items(): + try: + dest = "{TOP}/reindent/v{vnum}/reindent.py".format(TOP=TOP, vnum=vnum) + dl_url = \ + "{REPO_BASE}/raw-file/v{tag}/Tools/scripts/reindent.py".format( + REPO_BASE=REPO_BASE, + tag=tag + ) + print("Downloading {dl_url} to {dest}".format( + dl_url=dl_url, dest=dest) + ) + + with open(dest, 'w') as outfile: + outfile.write(urlopen(dl_url).read()) + except Exception: + return 1 + + return 0 + + +if __name__ == '__main__': + sys.exit(main())