Dan Buch avatar Dan Buch committed 8506a84

Converting one last admin script to python

Comments (0)

Files changed (1)

devscripts/fetch-reindent-versions

-#!/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())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.