Created
December 8, 2011 19:39
-
-
Save opensas/1448216 to your computer and use it in GitHub Desktop.
tiny little scala script to check for play documentation translated files, see http://www.dzone.com/links/first_steps_with_scala_say_goodbye_to_bash_scripts.html
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
#!/bin/sh | |
exec scala -savecompiled "$0" "$@" | |
!# | |
import java.io._ | |
val docs = new File(".").listFiles | |
.filter(_.getName.endsWith(".textile")) // process only textile files | |
.map(new DocumentationFile(_)) | |
val translated = docs.filter(_.isTranslated) // only already translated files | |
//Other ways to do it | |
//val translatedLength = translated.foldLeft(0L)( (acum, element) => acum + element.length ) | |
//val translatedLength = translated.foldLeft(0L)( _ + _.length ) | |
//val translatedLength = if (translated.length == 0) 0 else translated.map(_.length).sum | |
val translatedLength = translated.map(_.length).sum | |
val docsLength = docs.map(_.length).sum | |
println( | |
status("translated size", translatedLength, docsLength, (length) => asKB(length) ) | |
) | |
println( | |
status("translated files", translated.length, docs.length) | |
) | |
def status(title: String = "status", current: Long, total: Long, format: (Long) => String = (x) => x.toString): String = { | |
val percent = current * 100 / total | |
title + ": " + format(current) + "/" + format(total) + " " + | |
percent + "%" + | |
" (pending " + format(total - current) + " " + | |
(100-percent) + "%)" | |
} | |
def asKB(length: Long) = (length / 1000) + "kb" | |
class DocumentationFile(val file: File) { | |
val name = file.getName | |
val length = file.length | |
val isTranslated = (firstLine.indexOf("Esta página todavía no ha sido traducida al castellano") == -1) | |
override def toString = "name: " + name + ", length: " + length + ", isTranslated: " + isTranslated | |
def firstLine = new BufferedReader(new FileReader(file)).readLine | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment