X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=goaljobs.ml;h=4f99de4a14a1a427b086c283a1b142ee8d981dea;hb=55c3a7d9b2bffa53b519be5a319565e311f8d7e6;hp=53db37ceeecd8066c687b0f372a3d438822690a8;hpb=8fbc663ca72ef0c0a73cfb0f41d363e0c89a510e;p=goaljobs.git diff --git a/goaljobs.ml b/goaljobs.ml index 53db37c..4f99de4 100644 --- a/goaljobs.ml +++ b/goaljobs.ml @@ -62,7 +62,44 @@ let more_recent objs srcs = ) objs ) -let url_exists url = goal_failed "url_exists not implemented!" +let url_exists url = + (* http://stackoverflow.com/questions/12199059/how-to-check-if-an-url-exists-with-the-shell-and-probably-curl *) + let cmd = + sprintf "curl --output /dev/null --silent --head --fail %s" (quote url) in + match Sys.command cmd with + | 0 -> true + | 1 -> false + | r -> + let msg = sprintf "curl error testing '%s' (exit code %d)" url r in + goal_failed msg + +let file_contains_string filename str = + let cmd = sprintf "grep -q %s %s" (quote str) (quote filename) in + match Sys.command cmd with + | 0 -> true + | 1 -> false + | r -> + let msg = sprintf "grep error testing for '%s' in '%s' (exit code %d)" + str filename r in + goal_failed msg + +let url_contains_string url str = + let tmp = Filename.temp_file "goaljobsurl" "" in + let cmd = + sprintf "curl --output %s --silent --fail %s" (quote tmp) (quote url) in + (match Sys.command cmd with + | 0 -> () + | 1 -> + let msg = sprintf "curl failed to download URL '%s'" url in + goal_failed msg + | r -> + let msg = sprintf "curl error testing '%s' (exit code %d)" url r in + goal_failed msg + ); + let r = file_contains_string tmp str in + unlink tmp; + r + let sh fs = let do_sh cmd = @@ -156,6 +193,16 @@ let goal_url_exists url = let msg = sprintf "url_exists: URL '%s' required but does not exist" url in goal_failed msg ) +let goal_file_contains_string filename str = + if not (file_contains_string filename str) then ( + let msg = sprintf "file_contains_string: file '%s' is required to contain string '%s'" filename str in + goal_failed msg + ) +let goal_url_contains_string url str = + if not (url_contains_string url str) then ( + let msg = sprintf "url_contains_string: URL '%s' is required to contain string '%s'" url str in + goal_failed msg + ) let goal_memory_exists k = if not (memory_exists k) then ( let msg = sprintf "memory_exists: key '%s' required but does not exist" k in