Created
July 12, 2014 02:22
-
-
Save dwwoelfel/8a6944191cbd659665a0 to your computer and use it in GitHub Desktop.
Finds and fixes all of the bad php urls in php-build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user | |
(:require [clojure.string :as string] | |
[clj-http.client :as http])) | |
(defn definition-files [] | |
(let [basedir "/Users/daniel/projects/php-build/share/php-build/definitions"] | |
(map #(fs/join basedir %) (fs/listdir "/Users/daniel/projects/php-build/share/php-build/definitions")))) | |
(defn parse-url [file] | |
(last (re-find #"(?m)install_package \"([^\"]+)\"" (slurp file)))) | |
(defn good-url? [url] | |
(println "checking" url) | |
(= 200 (:status (http/head url {:throw-exceptions false})))) | |
(defn find-good-url [bad-url] | |
(cond (and (re-find #"www.php.net" bad-url) | |
(good-url? (string/replace bad-url "www.php.net" "php.net"))) | |
(string/replace bad-url "www.php.net" "php.net") | |
(and (re-find #"(www)?\.*php.net/distributions" bad-url) | |
(good-url? (string/replace bad-url #"(www)?\.*php.net/distributions" "museum.php.net/php5"))) | |
(string/replace bad-url #"(www)?\.*php.net/distributions" "museum.php.net/php5") | |
(and (re-find #"stas" bad-url) | |
(good-url? (string/replace bad-url "stas" "stas/old"))) | |
(string/replace bad-url "stas" "stas/old") | |
:else (println (format "Giving up on %s!" bad-url)))) | |
(defn fix-php-urls [] | |
(doall (pmap (fn [file] | |
(if-let [php-url (parse-url file)] | |
(when-not (good-url? php-url) | |
(when-let [good-url (find-good-url php-url)] | |
(-> file | |
slurp | |
(string/replace #"(?m)(install_package \")[^\"]+" (str "$1" good-url)) | |
(#(spit file %))))) | |
(println "no url for" file))) | |
(definition-files)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment