プロジェクトメンバのメアド一括登録
まぁ、こんなで。色々足りてないけど今のとこ問題なし。
import groovy.sql.Sql import groovy.grape.*; // Tracログインアカウント名 or メールアドレス // メールアドレスを指定する場合はメールアドレスがログインアカウントと同一であること。 def accounts = [ "cynipe" ] def DEFAULT_DOMAIN = "somewhere.com" @Grab(group = "org.xerial", module = "sqlite-jdbc", version = "3.6.17.1") class dummy{} // grapeがクラスパスを通してくれないので自分で通す。 def DRIVER_PATH="""${System.getProperty("user.home")}/.groovy/grapes/org.xerial/sqlite-jdbc/jars/sqlite-jdbc-3.6.17.1.jar""" this.class.classLoader.rootLoader.addURL(new URL("file:///${DRIVER_PATH}")) if(args.length == 0) { println "specify your trac project dir. ex) groovy TracInit.groovy /var/www/trac/siohamb" return } def db = Sql.newInstance("jdbc:sqlite:${args[0]}db/trac.db", "org.sqlite.JDBC") accounts.each { account -> def email = account.contains("@") ? account : "${account}@${DEFAULT_DOMAIN}" db.execute(""" INSERT OR REPLACE INTO session_attribute VALUES(${account}, 1, 'email', ${email}) """) } println "registration successed as follows:" db.eachRow("SELECT * FROM session_attribute WHERE name = 'email'") { attrs -> println "${attrs.sid}, ${attrs.authenticated}, ${attrs.name}, ${attrs.value}" }
変数emailを使い忘れてたのを修正した。