git リモートリポジトリを立てるの巻 ~ mac to mac ~

今使ってるmacの様子がおかしい...
重い...(長年の想いがたくさん詰まっているので)


Androidエミュレータを起動しようもんなら風呂入って一服出来るぐらい時間がかかる


んで友達のmacにvncで繋いでごそごそしている。
# vncがデフォルトで入っているmacはやはり最高だ。
# Adminパスワードを教えてmacを貸してくれる友達も最高だ!!


ここで問題。自分のmacと友達macの変更たちをどうやって管理していこうかと。


答えは簡単。gitがあるじゃないかと。


前置きが長くなりましたが、mac to macでsshを使ったgitリモートリポジトリ環境の構築

  • 以下自分mac:macA、友達mac:macBとします。
  • ssh接続は macB -> macA のみ

とりあえずssh接続

  1. macAの「システム環境設定」>「共有」>「リモートログイン」にチェック
    • sshもデフォルトで用意してくれてるmac
  2. macBのターミナルからssh
macB > ssh <macA.user>@<macA.IPAddress>

gitリモートリポジトリ作成

macA > mkdir <git-repo>
macA > cd <git-repo>
macA > git --bare init
  • の名前の最後は「.git」にすると男前
  • 「.git」を付けてもcloneで反映されません。

macA側のprojectをpush

は既にgitで管理しています。

macA > cd <macA.project>
macA > git add .
macA > git commit -a m "とりあえずコミットしとく"
macA > git remote add origin ssh://<macA.user>@<git-repo>
macA > git push origin master

macB側でclone

もgit管理していましたが一旦造り直します。

macA > cd <macB.project>
macA > git clone ssh://<macA.user>@<git-repo>
...

ここで問題発生。


↓のエラーが出る。

bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly


むむむ。


ssh上では「git-upload-pack」が見つからないと。


こちらを参考にさせて頂き解決。
↑の中で3点の解決法が紹介されていますが、3番目のシンボリックリンク法で対応することにした。

sshで通ってるパスの確認
macB > ssh <macA.user>@<macA.IPAddress> echo \$PATH
  • $PATHの前に「\」がないとダメ
git-upload-packの配置パス確認
macA > which git-upload-pack
シンボリックリンク作成
macA > ln -s <git-upload-packの配置パス> <sshで通ってるパス>/git-upload-pack

改め。macB側でclone

macB > cd <macB.project>
macB > git clone ssh://<macA.user>@<git-repo>


出来た。


# ついでにmacBでpushするとまた「git-xxxがない」って怒られるのでそれもmacA側でシンボリックリンクを造る


以上。

slim3 archetype:generateで造ったプロジェクトでmvn test失敗。。。

slim3 archetype:generateで造ったプロジェクトをhudsonでテスト実行したら失敗してた。
コンソールでmvn testしてもこける...
アノテーションあたりでcast exceptionが出てるみたいなので↓のアノテーションをコメントアウトしたら通った。

@Attribute(listener = CreationDate.class)
private Date createdAt;

@Attribute(listener = ModificationDate.class)
private Date updatedAt;

でも↑使いたい。解決策はないものか...

slim3 archetype:generatemaven - Slim3 日本語サイト(非公式)

GAEでWordPress

WordPresspython版(GAE対応版)があるようなので動かしてみる。
http://github.com/mdmcginn/pp4gae

# ↑のREADMEをそのままやっただけなんですが。

1. ↑からpp4gaeをダウンロード

git clone http://github.com/mdmcginn/pp4gae.git

2. http://www.web2py.com/examples/static/web2py_src.zipからweb2pyのsrcをダウンロードしてunzip

3. pp4gaeからweb2pyへもろもろコピー

cp -r pp4gae web2py/applications/
cp web2py/applications/pp4gae/app.yaml web2py/
cp web2py/applications/pp4gae/routes.py web2py/

4. pp4gae/app.yamlの1行目を編集

application: <GAEのアプリ名を設定>

5. GAEにアップロード

できた。
http://kiyoshiro-weblog.appspot.com/

結論。もっさりし過ぎ。。。

# 初回はemail:admin, password:adminでログインしてから「Edit User Info」でログイン情報編集

Trac-Agiloをインストールしてみる

macにtracとagiloプラグインをインストールして使ってみようと思う。

目的
最近[Scrum]に興味がある。agiloを使ってScrum感を試してみる。
目標
agiloを操作する。

mac:mac os x 10.5.8
trac:0.11.7
agilo:0.9-r2911-20100527

  • tracの実行方法は一旦スタンドアローン実行を想定(設定がややこしそうなので)

いってみましょ。

trac

macportでインストール

sudo port trac install

tracにひっついていろいろインストールされる。
[python]とか[svn]とか


とりあえずインストール出来たか確認

tracd --version

バージョンが表示されるはず。


trac プロジェクト用svnリポジトリ作成

mkdir <svn_dir_path>
svnadmin create <svn_dir_path>


tracプロジェクト作成

trac-admin <project_dir_path> initenv

はプロジェクト自体のdirパス。dirはプロジェクト作成実行時に作成される為、事前に作成不要。

コマンド内で以下を聞かれるので適宜入力

Project Name [My Project]> プロジェクト名
Database connection string [sqlite:db/trac.db]> (DBにsqlite:dbを使用するなら入力不要)
Repository type [svn]> (バージョン管理にsvnを使用するなら入力不要)
Path to repository [/path/to/repos]> ↑で作成したsvnリポジトリ

結果が出力される。


※結果出力を見るとtracが使っているpythonがmacデフォルトと違う!

Installing default wiki pages
CamelCase imported from /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/trac/wiki/default-pages/CamelCase
...

→デフォルトで設定されているpythonパスを変更(~/.bash_profileとかを変更)


とりあえずtracを実行してみる

tracd --port <port> <project_dir_path>

は適宜変更

http://127.0.0.1:

へアクセス。
→表示された画面中央のプロジェクト名をクリックしてtrac画面が表示さればOK。


TracAdminアカウント作成

↓を参考にしました。
http://tach.arege.net/trac/wiki/TracStandalone
※今回はBASIC認証の設定を行います。

  • htpasswd作成
htpasswd -c <htpasswd_file_path> <user_name>

→パスワード入力を求められるので適宜入力
※「-c」:ファイル作成オプション

  • permission設定
trac-admin <project_dir_path> permission add <user_name> TRAC_ADMIN
  • 認証ありで起動
tracd -p <port> --basic-auth <project_name>,<htpasswd_filepath> <project_dir_path>

tracにアクセスして画面上メニュー「login」からで作成したアカウントでログイン出来たらOK!

agilo

普通のとProがある。
Proは有償なので普通の(srcバージョン)をhttp://www.agile42.com/cms/pages/agilo/からDL
 →ページ真ん中の「Download」をフォーカスすると出てくる噴出しで「Agilo source code」を選択


解凍。


プラグインをインストール

cd <agilo dirpath>
sudo python setup.py install

※↑でpythonパスを変更してるので変更後の/lib/python2.6/site-packagesへインストールされる


tracの設定
/conf/trac.iniに↓を追加

[components]
agilo.* = enabled


upgrade

trac-admin <project_dir_path> upgrade


tracにアクセスする。画面デザインが変わってたらOK


できた。

applescript⇒perl連携

applescript内でperl実行
そんなことが出来る。
やってみました。

#! applescript
--UpdateMailLabel
--メールアドレスからラベルを判定し設定する
--create date: 2009/08/20 auth:koizumi ver 1.0

property MAX_COUNT : 10000 --ループ最大値

tell application "Address Book"
	activate
	--アドレス毎ループ
	repeat with i from 1 to MAX_COUNT
		if i > (count of every person) then exit repeat
		set tmp_person to item i of every person
		
		--メールアドレス毎ループ
		repeat with j from 1 to MAX_COUNT
			if j > (count of emails of tmp_person) then exit repeat
			set tmp_email to item j of emails of tmp_person
			log "befor:" & label of tmp_email as string
			
			--メールラベル取得
			set tmp_label to get_email_label(value of tmp_email as string) of me
			
			if (tmp_label ≠ "") then
				--ラベルが空文字以外⇒ラベル設定
				set label of tmp_email to tmp_label
			end if
			
			log "after:" & label of tmp_email as string
		end repeat
	end repeat
end tell

--メールアドレスに対応するラベルを取得
--str_email:メールアドレス[String]
--returns:ラベル[String]
--remarks:
--	以下の場合は空文字返却場合、空文字返却
--	[判定出来ない, ラベルがstr_emailと同一]
on get_email_label(str_email)
	
	set label to ""
	
	if regex_match("/ezweb/", str_email) of me then
		set label to "au"
	else if regex_match("/i.softbank.jp$/", str_email) of me then
		set label to "iphone"
	else if regex_match("/mac.com$/", str_email) of me then
		set label to ".mac"
	else if regex_match("/.com$/", str_email) of me then
		set label to regex_replace("/.+@(.+).com$/$1/", str_email) of me
	else if regex_match("/[a-z]{2,2}.jp$/", str_email) of me then
		set label to regex_replace("/.+@(.+).[a-z]{2,2}.[a-z]{2,2}$/$1/", str_email) of me
	end if
	
	--str_emailと同一の場合は空文字
	if label = str_email then set label to ""
	
	return label
	
end get_email_label

--targetがregexにマッチするか判定
--regex:正規表現[String]
--target:対象となる文字列[String]
--returns:判定結果[bool]
--remarks:perl実行で判定、regexはperl正規表現に対応する文字列
on regex_match(regex, target)
	set command to "$target = q/" & target & "/; if ($target =~ " & regex & "){ print q/1/; }else{ print q/0/; }" --※引数を使用してperlコマンド生成
	set str_result to exec_perl(command) of me
	return (str_result = "1")
end regex_match

--targetをregexで置換
--regex:正規表現[String]
--target:対象となる文字列[String]
--returns:置換後文字列[String]
--remarks:perl実行で判定、regexはperl正規表現に対応する文字列
on regex_replace(regex, target)
	set command to "$target = q/" & target & "/; $target =~ s" & regex & "; print $target;" --※引数を使用してperlコマンド生成
	set str_result to exec_perl(command) of me
	return str_result
end regex_replace

--commandをperlで実行
--command:perl実行コマンド[String]
--returns:実行結果[String]
on exec_perl(command)
	set one_liner to "perl -e '" & command & "'" as Unicode text
	set str_result to do shell script one_liner --※shell実行
	--TODO:エラー処理
	return str_result
end exec_perl
set result to do shell script command

でshellでcommandを実行してresultに返ってくる
> commandをperlワンライナーにして実行
てな。

# ただ、applescript内でエスケープ記号が使えない。(構文エラーになってしまう...)

↑普通に重ねたらいけるようだ。
http://developer.apple.com/jp/technotes/tn2065.html
# 昨日いけなかった気がしたんだけども...

blessされたオブジェクトをJSONに変換

#!/usr/local/bin/perl -w
use strict;
use warnings;
use utf8;
use JSON;

my $obj  = new Target('hounobouno');    # 変換対象インスタンス生成
my $json = new JSON;                    # JSONインスタンス生成

$json->convert_blessed;

# blessedObjectが渡されたらTO_JSONを呼ぶように設定

my $json_text = $json->encode($obj);

# 変換

# こう書くことも可能と
#my $json_text = $json->allow_blessed->convert_blessed->encode( $obj );

print $json_text;

exit;

# 変換対象obj
package Target;

use strict;
use warnings;
use utf8;

sub new
{
	my $class = shift;    # パッケージ名

	# プロパティ初期化
	my $self = { text => shift, };

	return bless $self, $class;
}

# 変換時に呼ばれる
sub TO_JSON               
{
	my $self = shift;
	my %h_self = map { $_ => $self->{$_} } keys(%$self);

	# インスタンスをhashに変換

	return { ref($self) => \%h_self };    # パッケージ名を付与して返却
}

1;

もっといい方法があるような気がする...