Sep 30, 2008
[Apple] Perian メモ
Perian is a free, open source QuickTime component that adds native support for many popular video formats.
- Perian
- http://www.perian.org/
- SupportedFormats
- http://trac.perian.org/wiki/SupportedFormats
Sep 17, 2008
[Linux] tar 実行時に不思議なエラーに遭遇
tar 実行時に不思議なエラーに遭遇した。
色々調べてようやく原因が分かった。 2Gbyte 以上のファイルを生成できないプラットフォームで、tar ファイルが 2Gbyte を超えた為に発生していたらしい。 余りに便利になりすぎて、一昔前の制約をどんどん忘れていく今日この頃。 幸せなことだけれど、たまにこういう落とし穴にはまる orztar: Only wrote 2047 of 10240 bytes to ./dummy.tar tar: Error is not recoverable: exiting now
ちなみに、発生したのはかなり昔の LinkStation 上。
Sep 14, 2008
[Apple] Mac OS X に Subversion をインストール
コマンドラインから svn コマンドを使用したいので、Mac OS X (Tiger) に Subversion をインストールした。
MacPorts でインストールしようと思ったが、エラーが発生してインストールできなかった。
プログラマの道具箱 さんのエントリ mac portsでsubversionをインストール に記述のあった "sudo port upgrade apr" を試してみたが、apr の更新自体でエラーが発生する始末。make[1]: *** [buckets/apr_brigade.lo] Error 1 make: *** [all-recursive] Error 1
結局 MacPorts でのインストールは諦め、Mac OS X 用のバイナリを DMG で入手してインストールした。 今回は openCollabNet から Subversion 1.5.1-2 Universal.dmg を使用した。
- openCollabNet
- http://www.collab.net/downloads/community/
それにしても、最近 MacPorts でエラーばかり起きる。 調子が悪いのだろうか・・・。$ /usr/local/bin/svn --version svn, version 1.5.1 (r32289) compiled Aug 6 2008, 13:59:27 Copyright (C) 2000-2008 CollabNet. Subversion is open source software, see http://subversion.tigris.org/ This product includes software developed by CollabNet (http://www.Collab.Net/). The following repository access (RA) modules are available: * ra_neon : Module for accessing a repository via WebDAV protocol using Neon. - handles 'http' scheme - handles 'https' scheme * ra_svn : Module for accessing a repository using the svn network protocol. - with Cyrus SASL authentication - handles 'svn' scheme * ra_local : Module for accessing a repository on local disk. - handles 'file' scheme * ra_serf : Module for accessing a repository via WebDAV protocol using serf. - handles 'http' scheme - handles 'https' scheme $
Sep 13, 2008
[Apple] MacPorts のアップデートに失敗する
Mac OS X 10.4 で久しぶりに MacPorts のアップデートを行ったところ、"error: Broken X11 install. No X11 headers" というエラーが発生した。 X11SDK はインストール済みなので、"No X11 headers" ということは無いはずなのだけれど。 X11SDk を再インストールして再挑戦することに。
"Mac OS X Instal Disc 1" から X11SDK を再インストールしたところ、$ sudo port selfupdate Password: MacPorts base version 1.520 installed Downloaded MacPorts base version 1.600 Configuring, Building and Installing new MacPorts base Error: /opt/local/bin/port: selfupdate failed: Error installing new MacPorts base: shell command "cd /opt/local/var/macports/sources/rsync.macports.org/release/base && ./configure --prefix=/opt/local --with-install-user=root --with-install-group=admin --with-tclpackage=/Library/Tcl && make && make install" returned error 1 Command output: checking for working vfork... (cached) yes checking whether strerror_r is declared... yes checking for strerror_r... yes checking whether strerror_r returns char *... no checking for bzero... yes (略) checking for openssl/md5.h... yes checking for X... no checking for XOpenDisplay in -lX11... yes Please install the X11 SDK packages from the Xcode Developer Tools CD configure: error: Broken X11 install. No X11 headers $
![[X11SDKインストールに失敗]](/blog/entries/Apple/20080913_01/x11_install.png)
というエラーでインストールできない。 X11SDK が既にインストールされているのが原因の様だ。
X11SDK をインストーラが検知できない様に上記の通り pkg ファイルを削除して再度実行したところ正常にインストールが終了した。 続いて MacPorts のアップデートに再挑戦。$ rm /Library/Receipts/X11SDK.pkg
今度は上手くいった。やれやれ。$ sudo port selfupdate Password: MacPorts base version 1.520 installed Downloaded MacPorts base version 1.600 Configuring, Building and Installing new MacPorts base selfupdate done! $ sudo port version Version: 1.600
Sep 12, 2008
[Apple] フォルダアクションで docbook を PDF に変換する
Mac OS X 上に Docbook 環境を構築してみた。 やりたいのは、フォルダアクションで docbook を PDF 化すること。
docbook 環境のインストール
まずは MacPorts を使用して docbook 関連のライブラリと Apache FOP をインストールする。
$ sudo port install docbook-xml docbook-xsl libxslt fop Password: ---> Fetching xmlcatmgr (略) ---> Installing xmlcatmgr 2.2_1 ---> Activating xmlcatmgr 2.2_1 ---> Cleaning xmlcatmgr ---> Fetching docbook-xml-4.1.2 (略) ---> Installing docbook-xml-4.1.2 4.1.2_1 ---> Activating docbook-xml-4.1.2 4.1.2_1 ---> Cleaning docbook-xml-4.1.2 (略) ---> Installing docbook-xml-4.2 4.2_0 ---> Activating docbook-xml-4.2 4.2_0 ---> Cleaning docbook-xml-4.2 ---> Fetching docbook-xml-4.3 (略) ---> Installing docbook-xml-4.3 4.3_0 ---> Activating docbook-xml-4.3 4.3_0 ---> Cleaning docbook-xml-4.3 ---> Fetching docbook-xml-4.4 (略) ---> Installing docbook-xml-4.4 4.4_0 ---> Activating docbook-xml-4.4 4.4_0 ---> Cleaning docbook-xml-4.4 ---> Fetching docbook-xml-4.5 (略) ---> Installing docbook-xml-4.5 4.5_0 ---> Activating docbook-xml-4.5 4.5_0 ---> Cleaning docbook-xml-4.5 ---> Fetching docbook-xml (略) ---> Installing docbook-xml 4.5_1 ---> Activating docbook-xml 4.5_1 ---> Cleaning docbook-xml ---> Fetching docbook-xsl (略) ---> Installing docbook-xsl 1.72.0_0 ---> Activating docbook-xsl 1.72.0_0 ---> Cleaning docbook-xsl ---> Fetching libxslt (略) ---> Installing libxslt 1.1.22_0 ---> Activating libxslt 1.1.22_0 ---> Cleaning libxslt ---> Fetching fop (略) ---> Installing fop 0.94_0 ---> Activating fop 0.94_0 ---> Cleaning fop $
シングルバイトの docbook ファイルを PDF 化してみる
PDF の Font 周りは面倒なので、とりあえずはシングルバイト文字のみで PDF 化を試してみる。 用意したデータはこんな感じ。
<?xml version="1.0" encoding="UTF-8"?>
<book id="my_test_book">
<title>my test book</title>
<chapter id="chapter1">
<title>Chapter 1</title>
<para>Hello docbook!</para>
</chapter>
<chapter id="chapter2">
<title>Chapter 2</title>
<para>This is single byte docbook document.</para>
</chapter>
</book>
docbook xml → (XSLT) → FO → (Apache FOP) → PDF という様に docbook を PDF に変換する。
何事もなく PDF が生成された。$ /opt/local/bin/xsltproc -o ./test.fo /opt/local/share/xsl/docbook-xsl/fo/docbook.xsl ./test.xml Making portrait pages on USletter paper (8.5inx11in) $ fop -fo ./test.fo -pdf ./test.pdf 2008/09/10 11:45:21 org.apache.fop.hyphenation.Hyphenator getHyphenationTree 致命的: Couldn't find hyphenation pattern en $
マルチバイトの docbook ファイルを PDF 化してみる
次に本命のマルチバイト docbook ファイルの変換に挑戦してみる。 FOP のフォント設定は以下のサイトを参考にさせていただいた。感謝。
- Apache FOP: Fonts
- http://xmlgraphics.apache.org/fop/0.95/fonts.html#basics
- DocBook メモ
- http://cueplot.sourceforge.jp/wiki/index.php?DocBook%20%E3%83%A1%E3%83%A2
<?xml version="1.0" encoding="UTF-8"?>
<book id="my_test_book_ja">
<title>テストブック</title>
<chapter id="chapter1">
<title>第一章</title>
<para>やぁ! Docbook</para>
</chapter>
<chapter id="chapter2">
<title>第二章</title>
<para>日本語は上手く表示できるかな?</para>
</chapter>
</book>
当然駄目だと分かっているが、とりあえずそのまま PDF 化してみる。
手順はシングルバイトのときと全く同様。結果は
やはり Font を設定しなければ化けることが分かったので、仕方なく Font を設定する。 手順は上記のサイトに記載がある通り。
$ cd /opt/local/share/java/fop/0.94/
$ java -cp ./build/fop.jar:./lib/commons-logging-1.0.4.jar:./lib/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -d -fn "HiraginoMinchoProW3" "/System/Library/Fonts/\343\203\222\343\203\251\343\202\255\343\202\231\343\203\216\346\230\216\346\234\235 Pro W3.otf" ./hiraginominchoprow3.xml
TTF Reader for Apache FOP 0.94
Parsing font...
Reading /System/Library/Fonts/?q???L??m???? Pro W3.otf...
sfnt version: OpenType with CFF data
(略)
Font Family: Hiragino Mincho Pro
Error while building XML font metrics file.
java.lang.UnsupportedOperationException: OpenType fonts with CFF data are not supported, yet
at org.apache.fop.fonts.apps.TTFReader.loadTTF(TTFReader.java:214)
at org.apache.fop.fonts.apps.TTFReader.main(TTFReader.java:163)
・・・ ヒラギノは現時点の Apache FOP では扱えないらしい。
では、ということで、MS 明朝を試してみた。
MS 明朝は正常に読み込むことができた。$ java -cp ./build/fop.jar:./lib/commons-logging-1.0.4.jar:./lib/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -d -fn "MSMINCHO" "./fonts/MSMINCHO.TTF" ./fonts/msmincho.xml TTF Reader for Apache FOP 0.94 Parsing font... Reading /fonts/MSMINCHO.TTF... sfnt version: OpenType 1.0 (略) Font Family: MS Mincho Creating xml font file... Creating CID encoded metrics... Writing xml font file /fonts/msmincho.xml... This font contains no embedding license restrictions. XML font metrics file successfully created. $
後は FOP の設定ファイル fop.xconf を作成するだけ。
<?xml version="1.0"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font metrics-url="/fonts/msmincho.xml" kerning="yes" embed-url="/fonts/MSMINCHO.ttf">
<font-triplet name="MSMINCHO" style="normal" weight="100"/>
<font-triplet name="MSMINCHO" style="normal" weight="200"/>
<font-triplet name="MSMINCHO" style="normal" weight="300"/>
<font-triplet name="MSMINCHO" style="normal" weight="400"/>
<font-triplet name="MSMINCHO" style="normal" weight="500"/>
<font-triplet name="MSMINCHO" style="normal" weight="600"/>
<font-triplet name="MSMINCHO" style="normal" weight="700"/>
<font-triplet name="MSMINCHO" style="normal" weight="800"/>
<font-triplet name="MSMINCHO" style="normal" weight="900"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
ではマルチバイト docbook の PDF 化に再挑戦。 今回は MS 明朝を使用するので、docbook から FO を作成した後で FO 内の Font 設定を変更する処理を入れる。 docbook → (XSLT) → fo → (sed) → fo → (FOP) → PDF という感じになる。 また、Apache FOP 実行時に上で作成した設定ファイルを指定する必要がある。
マルチバイト docbook の PDF 化に成功!!$ /opt/local/bin/xsltproc -o ./test_ja.fo /opt/local/share/xsl/docbook-xsl/fo/docbook.xsl ./test_ja.xml Making portrait pages on USletter paper (8.5inx11in) $ sed -e "s/font-family=\"/font-family=\"MSMINCHO,/g" ./test_ja.fo > ./test_ja_2.fo $ fop -fo ./test_ja_2.fo -pdf ./test_ja_2.pdf -c ./fop.xconf 2008/09/10 13:14:28 org.apache.fop.hyphenation.Hyphenator getHyphenationTree ?v???I: Couldn't find hyphenation pattern en $
AppleScript で docbook → PDF の変換を行う
docbook の PDF 化に成功したところで、念願の AppleScript での変換を行う。 まずはシェルスクリプトを用意。
#!/bin/sh
DOCBOOK_XML=$1
DOCBOOK_PDF=$2
XSLTPROC=/opt/local/bin/xsltproc
DOCBOOK_XSLT=/opt/local/share/xsl/docbook-xsl/fo/docbook.xsl
FOP=/opt/local/bin/fop
FOP_CONFIG=/fonts/fop.xconf
WORKDIR=`pwd`
WORK_FO=$WORKDIR/tmp.fo
WORK_FO_CONVERTED=$WORKDIR/tmp_converted.fo
echo "Converting docbook -> PDF : $DOCBOOK_XML -> $DOCBOOK_PDF"
if [ ! -f "$DOCBOOK_XML" ];
then
echo "No docbook file found. : $DOCBOOK_XML"
exit;
fi
rm "$WORK_FO" 2> /dev/null
rm "$WORK_FO_CONVERTED" 2> /dev/null
$XSLTPROC -o "$WORK_FO" "$DOCBOOK_XSLT" "$DOCBOOK_XML"
sed -e "s/font-family=\"/font-family=\"MSMINCHO,/g" "$WORK_FO" > "$WORK_FO_CONVERTED"
$FOP -fo "$WORK_FO_CONVERTED" -pdf "$DOCBOOK_PDF" -c "$FOP_CONFIG"
rm "$WORK_FO" 2> /dev/null
rm "$WORK_FO_CONVERTED" 2> /dev/null
次にこのシェルスクリプトを呼び出す AppleScript を用意する。
この AppleScript は "/Library/Scripts/Folder Action Scripts/Image - Duplicate as JPEG.scpt" を参考にさせていただいた(「参考に」と言うより、ほぼそのまま)。
property doneFoldername : "PDF"
property originalsFoldername : "Docbook"
property pdfExtension : "pdf"
property typeList : {"XML"}
property extensionList : {"xml"}
on adding folder items to thisFolder after receiving theseItems
tell application "Finder"
if not (exists folder doneFoldername of thisFolder) then
make new folder at thisFolder with properties {name:doneFoldername}
end if
set the resultsFolder to (folder doneFoldername of thisFolder) as alias
if not (exists folder originalsFoldername of thisFolder) then
make new folder at thisFolder with properties {name:originalsFoldername}
set current view of container window of thisFolder to list view
end if
set the originalsFolder to folder originalsFoldername of thisFolder
end tell
try
repeat with i from 1 to number of items in theseItems
set thisItem to item i of theseItems
set the itemInfo to the info for thisItem
if (alias of the itemInfo is false and the file type of the itemInfo is in the typeList) or (the name extension of the itemInfo is in the extensionList) then
tell application "Finder"
my resolveConflicts(thisItem, originalsFolder, "")
set the newName to my resolveConflicts(thisItem, resultsFolder, pdfExtension)
set the SourceFile to (move thisItem to the originalsFolder with replacing) as alias
end tell
processItem(SourceFile, newName, resultsFolder)
end if
end repeat
on error errorMessage number errorNumber
if the errorNumber is not -128 then
tell application "Finder"
activate
display dialog errorMessage buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end adding folder items to
on resolveConflicts(thisItem, targetFolder, newExtension)
tell application "Finder"
set the fileName to the name of thisItem
set fileExtension to the name extension of thisItem
if the fileExtension is "" then
set the trimmedName to the fileName
else
set the trimmedName to text 1 thru -((length of fileExtension) + 2) of the fileName
end if
if the newExtension is "" then
set targetName to fileName
set targetExtension to fileExtension
else
set targetExtension to newExtension
set targetName to (the trimmedName & "." & targetExtension) as string
end if
if (exists document file targetName of targetFolder) then
set the nameIncrement to 1
repeat
set the newName to (the trimmedName & "." & (nameIncrement as string) & "." & targetExtension) as string
if not (exists document file newName of the targetFolder) then
set the name of document file targetName of the targetFolder to the newName
exit repeat
else
set the nameIncrement to the nameIncrement + 1
end if
end repeat
end if
end tell
return the targetName
end resolveConflicts
on processItem(SourceFile, newName, resultsFolder)
try
set the targetPath to ((resultsFolder as string) & newName) as string
with timeout of 900 seconds
do shell script "/Scripts/convert-docbook.sh ¥"" & POSIX path of SourceFile & "¥" ¥"" & POSIX path of targetPath & "¥""
end timeout
on error errorMessage
tell application "Finder"
activate
display dialog errorMessage buttons {"Cancel"} default button 1 giving up after 120
end tell
end try
end processItem
この AppleScript をフォルダに関連付けて今回の作業は終了。
Sep 11, 2008
[Dolphin] J2SE 7.0 の closure で遊んでみた
先日構築した J2SE 7.0 EA で closure の動作環境で早速遊んでみた。
サンプルコード(0)
まずは引数を受け取って戻り値を返す closure。
public class Test2 {
public Test2(){
super();
}
public static void main(final String[] args) {
int result = {int arg => arg * arg}.invoke(3);
System.out.println(result);
}
}
>java.bat Test2 9
サンプルコード(1)
次に、参照型の引数を受け取って、参照型の戻り値を返す closure。
public class Test3 {
public Test3(){
super();
}
public static void main(final String[] args) {
Comparee c0 = new Comparee(0);
Comparee c1 = new Comparee(1);
Comparee result = {Comparee c0, Comparee c1 =>
c0.getValue() >= c1.getValue() ? c0 : c1}.invoke(c0, c1);
System.out.println("" + result.getValue());
}
public static class Comparee {
private final int value;
public Comparee(final int value){
super();
this.value = value;
}
public int getValue(){
return this.value;
}
}
}
>java.bat Test3 1
サンプルコード(2)
既存のインタフェース(Comparable)を暗黙で実装したとみなされる closure。 簡単な Comparable の実装は楽になるな。
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Test4 {
public Test4(){
super();
}
public static void main(final String[] args) {
List<Comparee> list = new ArrayList<Comparee>();
list.add(new Comparee(1));
list.add(new Comparee(3));
list.add(new Comparee(0));
list.add(new Comparee(2));
Comparator<Comparee> comparator =
{Comparee c0, Comparee c1 => c0.getValue() - c1.getValue()};
System.out.println("" + list);
Collections.sort(list, comparator);
System.out.println("" + list);
}
public static class Comparee {
private final int value;
public Comparee(final int value){
super();
this.value = value;
}
public int getValue(){
return this.value;
}
public String toString(){
return "" + this.value;
}
}
}
>java.bat Test4 [1, 3, 0, 2] [0, 1, 2, 3]
サンプルコード(3)
closure を引数で受け取るメソッド。
public class Test5 {
public Test5(){
super();
}
public static void main(final String[] args) {
invoker({String message, int count =>
for(int i = 0; i < count; i++){
System.out.print("" + message);
}
System.out.println();
});
invoker({String message, int count =>
for(int i = 0; i < count; i++){
System.out.print("-" + message);
}
System.out.println();
});
}
public static void invoker({String, int => void} invokee){
invokee.invoke("*", 5);
}
}
>java.bat Test5 ***** -*-*-*-*-*
サンプルコード(4)
closure を実装するクラス。
public class Test6 {
public Test6(){
super();
}
public static void main(final String[] args) {
check(new MyChecker(), 5);
check(new MyChecker(), -1);
}
public static void check(final {int => boolean} f, final int i) {
System.out.println("" + f.invoke(i));
}
public static class MyChecker implements {int => boolean} {
public MyChecker(){
super();
}
public boolean invoke(final int i) {
return i < 0;
}
}
}
>java.bat Test6 false true
Sep 10, 2008
[Misc] Putty の鍵 (*.ppk) を OpenSSH 形式に変換する方法をメモ
Windows 時代は Putty を愛用していたが、Mac OS X に移行して Putty を使わなくなった。 手元には大量の ppk ファイルが orz。 Mac OS X の ssh でも使用出来るように OpenSSH 形式に変換しておいた。
変換方法
Putty に付属の PUTTYGEN.EXE で ppk を OpenSSH 形式に変換できる。
PUTTYGEN.EXE を起動して、ppk を読み込み、OpenSSH でエクスポートするだけ。
Sep 09, 2008
[Dolphin] J2SE 7.0 EA で closure 環境を用意する。
そろそろ closure を実際に使用しておこうかと思い、JDK 7.0 EA をダウンロードして closure 環境を用意してみた。 現時点(2008/09/09)では JDK 単体では closure は利用できず、別途 closure ライブラリを用意する必要がある様だ。
- Closures for the Java Programming Language (aka BGGA)
- http://javac.info/
- JSR Proposal: Closures for Java
- http://www.javac.info/consensus-closures-jsr.html
- JDK 7 Project
- https://jdk7.dev.java.net/
- Java Platform, Standard Edition 7 Binary Snapshot Releases
- http://download.java.net/jdk7/binaries/
closure 環境の準備
まずは JDK 7.0 EA をダウンロードする。 今回使用したのは現時点で最新と思われる jdk-7-ea-bin-b34-windows-i586-28_aug_2008.exe。 closure ライブラリは javac.info から closures.tar.gz をダウンロードする。
JDK 7.0 EA 単体では closure は利用できないらしいが、とりあえず試してみる。>set JAVA_HOME=C:\_java\jdk\1.7.0-ea-28_aug_2008 >set PATH=%PATH%;%JAVA_HOME%\bin >java -version java version "1.7.0-ea" Java(TM) SE Runtime Environment (build 1.7.0-ea-b34) Java HotSpot(TM) Client VM (build 14.0-b03, mixed mode, sharing) >javac -version javac 1.7.0-ea
>md test
>cd test
>javac Test.java
Test.java:7: 式の開始が不正です。
int value = { => 1 + 2 }.invoke();
^
Test.java:7: 式の開始が不正です。
int value = { => 1 + 2 }.invoke();
^
Test.java:7: ';' がありません。
int value = { => 1 + 2 }.invoke();
^
エラー 3 個
>javac -source 7 -target 7 Test.java
Test.java:7: 式の開始が不正です。
int value = { => 1 + 2 }.invoke();
^
Test.java:7: 式の開始が不正です。
int value = { => 1 + 2 }.invoke();
^
Test.java:7: ';' がありません。
int value = { => 1 + 2 }.invoke();
^
エラー 3 個
やはり無理だった。で、closure ライブラリを導入してみる。
先程と同じテストコードを実行してみる。>xcopy /S \closures-2008-08-11\* \_java\jdk\1.7.0-ea-28_aug_2008 \closures-2008-08-11\CHANGES \closures-2008-08-11\DISTRIBUTION C:\_java\jdk\1.7.0-ea-28_aug_2008\LICENSE を上書きしますか (Yes/No/All)? y \closures-2008-08-11\LICENSE \closures-2008-08-11\bin\java \closures-2008-08-11\bin\java.bat \closures-2008-08-11\bin\javac \closures-2008-08-11\bin\javac.bat \closures-2008-08-11\bin\javadoc \closures-2008-08-11\bin\javadoc.bat \closures-2008-08-11\lib\closures.jar 10 個のファイルをコピーしました
動いた。今回はここまで。>javac.bat Test.java >java.bat Test 3 >
使用したテストコード
上で使用したテストコード(Test.java)はこれ。
public class Test{
public Test(){
super();
}
public static void main(final String[] args){
int value = { => 1 + 2 }.invoke();
System.out.println(value);
}
}
Sep 08, 2008
[Apple] AppleScript から rsync を実行
rsync にはいつもお世話になっている。 コマンドラインで叩いてもさほど面倒というわけでもないのだけれど、ブログの更新の様に何度も繰り返して行う作業は自動化しておきたい。 今まではシェルスクリプトを利用していたのだけれど、何となく AppleScript 化してみた。
rsync.expect
rsync に AppleScript からパスワードを渡すために expect を使用する。 少々面倒だけれど、とりあえず expect で 汎用的な rsync 制御用の関数を用意しておく。 何かで使い回せるかもしれないし。 ・・・といって使い回した試しはないが。
#!/usr/bin/expect
proc Rsync {RsyncServer RsyncPort RemoteUser RemotePassword RemoteDirectory LocalDirectory} {
set timeout 10;
spawn rsync -av --port=$RsyncPort $LocalDirectory $RemoteUser@$RsyncServer:$RemoteDirectory
expect {
password: {send "$RemotePassword¥r";}
timeout {puts stderr "rsync timeout."; return 1;}
}
expect {
sent {return 0;}
Permission {puts stderr "login failed."; return 2;}
}
return 0
}
set ARG0 [lindex $argv 0]
set ARG1 [lindex $argv 1]
set ARG2 [lindex $argv 2]
set ARG3 [lindex $argv 3]
set ARG4 [lindex $argv 4]
set ARG5 [lindex $argv 5]
set Result [Rsync $ARG0 $ARG1 $ARG2 $ARG3 $ARG4 $ARG5]
exit $Result
bloguploader.scpt
次に、rsync.expect を呼び出す AppleScript を作成する。 Password はスクリプト内には埋め込みたくないので、ダイアログで入力するようにしておいた。 このスクリプトはこのまま Automator で使用しても OK。
display dialog "Enter password: " default answer "" set RsyncPassword to text returned of result do shell script "/usr/bin/expect -f /Users/me/Documents/rsync.expect www.example.com 873 me " & RsyncPassword & " /home/me/blog /Users/me/Documents/Blog/"
Sep 07, 2008
[Linux] CentOS 5 に PostgreSQL をインストール
CentOS 5 に PostgreSQL をインストールしたときのメモ。 CentOS 5 にデフォルト状態で設定されている yum のリポジトリには 2008/09/07 現在 PostgreSQL 8.1.11 しか登録されていない。 今回は 8.1 ではなく 8.2 をインストールしたいので、8.2 をインストール出来るよう設定をしてみた。
- RepoView: PostgreSQL PGDG Repository RPMs - Letter P
- http://yum.pgsqlrpms.org/reporpms/repoview/letter_p.group.html
- pgdg-centos - PostgreSQL 8.4.X PGDG RPMs for CentOS - Yum Repository Configuration
- http://yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html
CentOS 5 のデフォルト状態
CentOS 5 をクリーンインストールした直後はこんな感じ。
# yum search postgresql postgresql-server.i386 : The programs needed to create and run a PostgreSQL server. postgresql-docs.i386 : Extra documentation for PostgreSQL perl-DBD-Pg.i386 : A PostgresSQL interface for perl qt4-postgresql.i386 : PostgreSQL drivers for Qt's SQL classes postgresql-test.i386 : The test suite distributed with PostgreSQL. libdbi-dbd-pgsql.i386 : PostgreSQL plugin for libdbi postgresql-devel.i386 : PostgreSQL development header files and libraries. php-pdo.i386 : A database access abstraction module for PHP applications freeradius-postgresql.i386 : postgresql bindings for freeradius postgresql-contrib.i386 : Contributed source and binaries distributed with PostgreSQL php-pgsql.i386 : A PostgreSQL database module for PHP. qt-PostgreSQL.i386 : PostgreSQL drivers for Qt's SQL classes. php-pgsql.i386 : A PostgreSQL database module for PHP. postgresql-libs.i386 : The shared libraries required for any PostgreSQL clients. postgresql-pl.i386 : The PL procedural languages for PostgreSQL. postgresql-libs.i386 : The shared libraries required for any PostgreSQL clients. rhdb-utils.i386 : Miscellaneous utilities for PostgreSQL - CentOS Edition. mod_auth_pgsql.i386 : Basic authentication for the Apache web server using a PostgreSQL database. unixODBC.i386 : A complete ODBC driver manager for Linux. mono-data-postgresql.i386 : Postgresql database connectivity for Mono postgresql-jdbc.i386 : JDBC driver for PostgreSQL php-pdo.i386 : A database access abstraction module for PHP applications postgresql.i386 : PostgreSQL client programs and libraries. bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. pdns-backend-postgresql.i386 : PostgreSQL backend for pdns bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. postgresql-python.i386 : Development module for Python code to access a PostgreSQL DB. postgresql-odbc.i386 : PostgreSQL ODBC driver. postgresql-tcl.i386 : A Tcl client library for PostgreSQL. # yum install postgresql-server Setting up Install Process Parsing package install arguments Resolving Dependencies --> Running transaction check ---> Package postgresql-server.i386 0:8.1.11-1.el5_1.1 set to be updated --> Processing Dependency: postgresql = 8.1.11-1.el5_1.1 for package: postgresql-server --> Running transaction check ---> Package postgresql.i386 0:8.1.11-1.el5_1.1 set to be updated --> Finished Dependency Resolution Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: postgresql-server i386 8.1.11-1.el5_1.1 base 3.9 M Installing for dependencies: postgresql i386 8.1.11-1.el5_1.1 base 2.9 M Transaction Summary ============================================================================= Install 2 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 6.7 M Is this ok [y/N]: N Exiting on user Command Complete!
yum の設定
yum に PostgreSQL のリポジトリを登録する。 今回は訳あって 8.3 ではなく 8.2 が必要なので、8.2 用のリポジトリを登録する。
# wget http://yum.pgsqlrpms.org/reporpms/8.2/pgdg-centos-8.2-4.noarch.rpm --17:44:40-- http://yum.pgsqlrpms.org/reporpms/8.2/pgdg-centos-8.2-4.noarch.rpm (略) 17:44:40 (2.88 MB/s) - `pgdg-centos-8.2-4.noarch.rpm' saved [4311/4311] # rpm -ivh ./pgdg-centos-8.2-4.noarch.rpm Preparing... ########################################### [100%] 1:pgdg-centos ########################################### [100%]
PostgreSQL のインストール
リポジトリの登録が終わったので、早速 PostgreSQL 8.2 をインストールしてみる。
# yum search postgresql pgdg82 100% |=========================| 1.9 kB 00:00 primary.sqlite.bz2 100% |=========================| 45 kB 00:00 python-psycopg2-doc.i386 : Documentation for psycopg python PostgreSQL database adapter slony1-docs.i386 : Documentation for Slony-I python-psycopg2-doc.i386 : Documentation for psycopg python PostgreSQL database adapter pgpool-II-debuginfo.i386 : Debug information for package pgpool-II pgpool-II-devel.i386 : The development files for pgpool-II pgpool-debuginfo.i386 : Debug information for package pgpool pgpool-II.i386 : Pgpool is a connection pooling/replication server for PostgreSQL perl-DBD-Pg.i386 : A PostgresSQL interface for perl postgresql-plpython.i386 : The Python procedural language for PostgreSQL postgresql-jdbc.i386 : JDBC driver for PostgreSQL postgresql-libs.i386 : The shared libraries required for any PostgreSQL clients. postgresql-libs.i386 : The shared libraries required for any PostgreSQL clients. dbi-link.noarch : Partial implementation of the SQL/MED portion of the SQL:2003 specification postgresql-test.i386 : The test suite distributed with PostgreSQL. skytools.i386 : PostgreSQL database management tools from Skype libpqxx.i386 : C++ client API for PostgreSQL pgsphere.i386 : R-Tree implementation using GiST for spherical objects bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. pdns-backend-postgresql.i386 : PostgreSQL backend for pdns pgdg-redhat.noarch : PostgreSQL 8.2.X PGDG RPMs for RHEL - Yum Repository Configuration postgresql-odbc.i386 : PostgreSQL ODBC driver phpPgAdmin.noarch : Web-based PostgreSQL administration postgresql-docs.i386 : Extra documentation for PostgreSQL pgpool.i386 : Pgpool is a connection pooling/replication server for PostgreSQL qt4-postgresql.i386 : PostgreSQL drivers for Qt's SQL classes postgresql-pltcl.i386 : The Tcl procedural language for PostgreSQL python-psycopg2.i386 : A PostgreSQL database adapter for Python odbcng.i386 : PostgreSQL ODBCng driver postgresql-libs.i386 : The shared libraries required for any PostgreSQL clients postgresql-test.i386 : The test suite distributed with PostgreSQL postgresql-python.i386 : Development module for Python code to access a PostgreSQL DB postgresql-tcl-debuginfo.i386 : Debug information for package postgresql-tcl php-pgsql.i386 : A PostgreSQL database module for PHP. postgresql-plperl.i386 : The Perl procedural language for PostgreSQL postgresql-tcl.i386 : Tcl client library for PostgreSQL ptop.i386 : 'top' for PostgreSQL process ip4r.i386 : IPv4 and IPv4 range index types for PostgreSQL postgresql-contrib.i386 : Contributed source and binaries distributed with PostgreSQL table_log.i386 : Log data changes in a PostgreSQL table unixODBC.i386 : A complete ODBC driver manager for Linux. postgis.i386 : Geographic Information Systems Extensions to PostgreSQL python-psycopg2.i386 : A PostgreSQL database adapter for Python pgfouine.noarch : PgFouine PostgreSQL log analyzer postgresql-devel.i386 : PostgreSQL development header files and libraries. postgresql-server.i386 : The programs needed to create and run a PostgreSQL server postgresql-jdbc-debuginfo.i386 : Debug information for package postgresql-jdbc postgresql-devel.i386 : PostgreSQL development header files and libraries pgdg-centos.noarch : PostgreSQL 8.2.X PGDG RPMs for CentOS - Yum Repository Configuration postgresql-odbc.i386 : PostgreSQL ODBC driver. postgresql-tcl.i386 : A Tcl client library for PostgreSQL. postgis.i386 : Geographic Information Systems Extensions to PostgreSQL postgresql-odbc-debuginfo.i386 : Debug information for package postgresql-odbc postgresql-python-debuginfo.i386 : Debug information for package postgresql-python slony1-docs.i386 : Documentation for Slony-I pgplsh.i386 : Sh shell procedural language handler for PostgreSQL postgresql-contrib.i386 : Contributed source and binaries distributed with PostgreSQL usda-r18.noarch : The USDA Food Database Sample for PostgreSQL qt-PostgreSQL.i386 : PostgreSQL drivers for Qt's SQL classes. php-pgsql.i386 : A PostgreSQL database module for PHP. postgresql-debuginfo.i386 : Debug information for package postgresql pgadmin3.i386 : Graphical client for PostgreSQL rhdb-utils.i386 : Miscellaneous utilities for PostgreSQL - CentOS Edition. mono-data-postgresql.i386 : Postgresql database connectivity for Mono pgpool-II.i386 : Pgpool is a connection pooling/replication server for PostgreSQL pgdg-centos.noarch : PostgreSQL 8.2.X PGDG RPMs for CentOS - Yum Repository Configuration bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. python-psycopg2-zope.i386 : Zope Database Adapter ZPsycopgDA postgresql-server.i386 : The programs needed to create and run a PostgreSQL server. plruby.i386 : PostgreSQL Ruby Procedural Language slony1.i386 : A "master to multiple slaves" replication system with cascading and failover libdbi-dbd-pgsql.i386 : PostgreSQL plugin for libdbi php-pdo.i386 : A database access abstraction module for PHP applications freeradius-postgresql.i386 : postgresql bindings for freeradius postgresql-pl.i386 : The PL procedural languages for PostgreSQL. postgresql-docs.i386 : Extra documentation for PostgreSQL compat-postgresql-libs-debuginfo.i686 : Debug information for package compat-postgresql-libs pagila.noarch : A sample database for PostgreSQL slony1.i386 : A "master to multiple slaves" replication system with cascading and failover python-psycopg2-zope.i386 : Zope Database Adapter ZPsycopgDA mod_auth_pgsql.i386 : Basic authentication for the Apache web server using a PostgreSQL database. pgpool-II-devel.i386 : The development files for pgpool-II postgresql-jdbc.i386 : JDBC driver for PostgreSQL php-pdo.i386 : A database access abstraction module for PHP applications postgresql.i386 : PostgreSQL client programs and libraries. bind-sdb.i386 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server with database backends. postgresql.i386 : PostgreSQL client programs and libraries postgresql-python.i386 : Development module for Python code to access a PostgreSQL DB. compat-postgresql-libs.i686 : PostgreSQL client programs and libraries pgpool-II-debuginfo.i386 : Debug information for package pgpool-II # yum install postgresql-server Setting up Install Process Parsing package install arguments Resolving Dependencies --> Running transaction check ---> Package postgresql-server.i386 0:8.2.9-1PGDG.rhel5 set to be updated --> Processing Dependency: postgresql = 8.2.9 for package: postgresql-server --> Processing Dependency: libpq.so.5 for package: postgresql-server --> Running transaction check ---> Package postgresql-libs.i386 0:8.2.9-1PGDG.rhel5 set to be updated --> Processing Dependency: libpq.so.4 for package: apr-util ---> Package postgresql.i386 0:8.2.9-1PGDG.rhel5 set to be updated --> Running transaction check ---> Package compat-postgresql-libs.i686 0:4-1PGDG.rhel5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: postgresql-server i386 8.2.9-1PGDG.rhel5 pgdg82 4.0 M Updating: postgresql-libs i386 8.2.9-1PGDG.rhel5 pgdg82 196 k Installing for dependencies: compat-postgresql-libs i686 4-1PGDG.rhel5 pgdg82 63 k postgresql i386 8.2.9-1PGDG.rhel5 pgdg82 1.6 M Transaction Summary ============================================================================= Install 3 Package(s) Update 1 Package(s) Remove 0 Package(s) Total download size: 5.9 M Is this ok [y/N]: y Downloading Packages: (1/4): postgresql-server- 100% |=========================| 4.0 MB 00:12 (2/4): postgresql-8.2.9-1 100% |=========================| 1.6 MB 00:02 (3/4): compat-postgresql- 100% |=========================| 63 kB 00:00 (4/4): postgresql-libs-8. 100% |=========================| 196 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Updating : postgresql-libs ######################### [1/5] Installing: postgresql ######################### [2/5] Installing: compat-postgresql-libs ######################### [3/5] Installing: postgresql-server ######################### [4/5] Cleanup : postgresql-libs ######################### [5/5] Installed: postgresql-server.i386 0:8.2.9-1PGDG.rhel5 Dependency Installed: compat-postgresql-libs.i686 0:4-1PGDG.rhel5 postgresql.i386 0:8.2.9-1PGDG.rhel5 Updated: postgresql-libs.i386 0:8.2.9-1PGDG.rhel5 Complete! # psql --version psql (PostgreSQL) 8.2.9 contains support for command-line editing #
Sep 04, 2008
[Misc] Google Chrome on Mac OS X のビルドにチャレンジ
とりあえず Windows XP Professional では Google Chrome が動作したので、次は Mac OS X で動かないか調べてみた。 現時点(2008/09/04)では、 Google Chrome のサイトでは Mac OS X 用のバイナリは公開されていない。 が、ドキュメントを見ていたら Mac OS X でのビルド方法が公開されていた。 というわけで、さっそくチャレンジ。
- Chrome Developer Documentation - Build Instructions (Mac OS X)
- http://dev.chromium.org/developers/how-tos/build-instructions-os-x
Google Chrome のソースコードを入手
まずは depot_tools をダウンロードして実行できる様にする。
次に、depot_tools 内にある gclient を使用して Chrome のソースコードをダウンロードする。$ tar zxvf ./depot_tools_mac.tar.gz depot_tools/.svn/ depot_tools/.svn/text-base/ depot_tools/.svn/text-base/gcl.svn-base depot_tools/.svn/text-base/gclient.svn-base depot_tools/.svn/text-base/hammer.svn-base depot_tools/.svn/text-base/README.svn-base depot_tools/.svn/prop-base/ (略) $ export PATH=`pwd`/depot_tools:$PATH
Chrome のソースコードがダウンロードできたら、XCode を使用してビルドを行う。$ mkdir -p ./src/trunk $ cd ./src/trunk/ $ gclient config http://src.chromium.org/svn/trunk/src checking out latest depot_tools... $ gclient sync ________ running 'svn checkout http://src.chromium.org/svn/trunk/src src' in '/chrome/src/trunk' A src/sdch A src/sdch/using_sdch.vsprops A src/sdch/open_vcdiff A src/sdch/open_vcdiff/depot A src/sdch/open_vcdiff/depot/opensource A src/sdch/open_vcdiff/depot/opensource/open-vcdiff (略) $
ビルド失敗 orz コマンドラインではなく XCode の GUI からもビルドしてみたが、結果は同じ。 Chrome のソースコードを gclient でダウンロードしたものではなく、tar.gz で公開されているものにしてみたが、それでもだめ。$ xcodebuild -version Component versions: DevToolsCore-921.0; DevToolsSupport-893.0 $ xcodebuild -project ./src/trunk/src/webkit/tools/test_shell/mac/TestShell.xcodeproj 2008-09-04 00:50:54.203 xcodebuild[22183:613] NOTE: Referenced project Skia was written by a newer Xcode version (45) -- temporarily downgrading it (without modifying project file) 2008-09-04 00:50:54.254 xcodebuild[22183:613] NOTE: Referenced project net was written by a newer Xcode version (45) -- temporarily downgrading it (without modifying project file) (略) /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:75: error: ‘v8’ has not been declared /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:75: error: expected constructor, destructor, or type conversion before ‘<’ token /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:82: error: ‘v8’ has not been declared /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:82: error: ‘char**’ is not a template /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:82: error: ‘v8’ has not been declared /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:82: error: ‘Value’ was not declared in this scope /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp: In static member function ‘static bool WebCore::V8BarInfo::HasInstance(char**)’: /chrome/src/trunk/src/webkit/build/Release/DerivedSources/v8/bindings/V8BarInfo.cpp:83: error: ‘GetRawTemplate’ was not declared in this scope ** BUILD FAILED ** $
・・・で。
結局現時点では Mac OS X 版をビルドすることはできない様だ。 中の人がブログで Mac OS X 版の現状を説明していた。 モジュール単位ではビルドできるらしいが、全体のビルドは無理とのこと。 残念。 早く Mac OS X 版が出て欲しいものだ。
- Google Mac Blog - Platforms and Priorities
- http://googlemac.blogspot.com/2008/09/platforms-and-priorities.html
When it comes to Mac and Linux versions, this means that our goal is not to just "port" a Windows application to these other platforms--rather, our goal is to deliver Chromium's innovative, Google-style user interface without rough edges on any of them. Chromium's overall design has been multi-platform from the start, but we are also committed to getting the details right for users on each platform.
(略)
Right now, both are in the "pieces build and pass tests, but there's no Chromium application yet." While we're working hard and fast on catching up to the Windows version, we're not setting an artificial date for when they'll be ready--we simply can't predict enough to make a solid estimate, and we expect to learn a lot from the Windows public beta as well. On the plus side, since the project is now public, you'll be able to watch (and maybe even contribute to) the progress from week to week. As these versions stabilize, we will create official betas, much as we are now for the Windows version. While we can't give any dates yet, we'll keep everyone informed as we get closer.
[Misc] Google Chrome のタスクマネージャの Always on top を解除する方法
Google Chrome をぼーっと眺めていたら、タスクマネージャの Always on top を解除する方法を見つけた。 ・・・だから何だ、と言われても困るが。
編集するファイルは
C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\User Data\Local State
task_manager の always_on_top がデフォルトで "true" になっているので、"false" に変えて Google Chrome を再起動する。
{
"task_manager": {
"window_placement": {
"always_on_top": true,
"bottom": 599,
"left": 452,
"maximized": false,
"right": 920,
"top": 300
}
},
}
[Misc] Google Chrome の User-Agent
Google Chrome の User-Agent を調べてみた。 2008/09/03 にダウンロードした Windows 用のバイナリでは以下の User-Agent が使用される。
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
Sep 03, 2008
[Misc] Google Chrome にチャレンジ
Google が Chrome という独自 Web ブラウザを公開した。 インストールしてみないことには始まらないので、とりあえずインストールしてみた。
- Google Chrome
- http://www.google.com/chrome/
- Google Chrome - 機能
- http://www.google.com/chrome/intl/ja/features.html
インストールの風景
Google Chrome を使ってみた
Sep 01, 2008
[Misc] web.xml を分割する方法
久しぶりに Servlet を書くことになった。 Servlet ベースで Web アプリケーションを書くと web.xml がすぐにカオスになってしまうのが難点。 Servlet Specification 2.4 では XMLSchema が導入されたので、DTD を使用していた Servlet Specification 2.3 以前に比べると web.xml を分割し易くなっている。 というわけで、混沌としてくる前に web.xml を分割していくことにした。
web.xml の分割方法
web.xml の分割は非常に簡単。 web.xml 用の特別な方法があるわけではなく、XML の実体参照を使用するだけ。
web.xml はこんな感じ。
web.xml 内で参照されている web-function0.xml はこんな感じ。 Servlet 2.3 までの <servlet> と <servlet-mapping> との順序の制約が無くなったので、web-funcion0.xml が読み易い。<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app [ <!ENTITY function0 SYSTEM "web-function0.xml"> <!ENTITY function1 SYSTEM "web-function1.xml"> ]> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version="2.5"> &function0; &function1; </web-app>
<servlet> <servlet-name>jp.in_vitro.function0.FooServlet</servlet-name> <servlet-class>jp.in_vitro.function0.FooServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>jp.in_vitro.function0.FooServlet</servlet-name> <url-pattern>/function0/foo</url-pattern> </servlet-mapping> <servlet> <servlet-name>jp.in_vitro.function0.BarServlet</servlet-name> <servlet-class>jp.in_vitro.function0.BarServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>jp.in_vitro.function0.BarServlet</servlet-name> <url-pattern>/function0/bar</url-pattern> </servlet-mapping>
それにしても <url-pattern> の表現能力の貧弱さは何とかならないものか。 今時 Servlet ベースの開発はつらい。

![[Chrome をダウンロード]](/blog/entries/Misc/20080903_01/chrome_0.png)
![[Chrome をインストール中]](/blog/entries/Misc/20080903_01/chrome_1.png)
![[Chrome のインストール準備完了]](/blog/entries/Misc/20080903_01/chrome_2.png)
![[Chrome が起動した]](/blog/entries/Misc/20080903_01/chrome_3.png)
![[とりあえずここを表示できた]](/blog/entries/Misc/20080903_01/chrome_4.png)
![[シークレットモード]](/blog/entries/Misc/20080903_01/chrome_5.png)
![[タスクマネージャ]](/blog/entries/Misc/20080903_01/chrome_6.png)


