Created
August 17, 2010 13:17
-
-
Save shenqi/529885 to your computer and use it in GitHub Desktop.
sync everything at start-up and growl the result
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
#!/usr/bin/env ruby -Ku | |
require 'rbconfig' | |
require 'rubygems' | |
require 'meow' | |
#絶対パスで指定。 '/'でクローズ | |
REPODIR = '/Users/shenqi/src/' | |
PERLDIR = '/Users/shenqi/perl5/' | |
$appname = 'ruby-updater' | |
$image = '/Applications/iSync.app/Contents/Resources/iSyncApplicationicon.icns' | |
def growl(title, message, option = 'default', command = 'default') | |
growl = Meow.new($appname) | |
icon = Meow.import_image($image) | |
opt = { :icon => icon } | |
case option | |
when 'default' | |
when 'impact' then opt.merge!( { :priority => '1' } ) | |
when 'sticky' then opt.merge!( { :sticky => 'true' } ) | |
when 'error' then opt.merge!( { :sticky => 'true', :priority => '1' } ) | |
else #その他の処理 | |
opt.merge!( { :sticky => 'true' } ) | |
warn "invalid option '#{option}' given." | |
end | |
growl.notify(title, message.chomp, opt) | |
end | |
def get_names(repo) | |
dir = Dir::chdir(REPODIR) | |
path = File::expand_path(repo) | |
repo = File::basename(path) | |
return [path, repo] | |
dir.close | |
end | |
def gisty_sync | |
message = `gisty sync_delete` | |
growl('gisty', message.split(/\n/).last) | |
message = `gisty pull_all` | |
growl('gisty', message.split(/\n/).last) | |
end | |
def svn_up(repo) | |
hoge = get_names(repo) | |
svnpath, modname = hoge[0], hoge[1] | |
message = `svn up '#{svnpath}'` | |
title = 'svn: ' + modname | |
growl(title, message) | |
if /updated/ =~ message then | |
return message | |
else | |
return false | |
end | |
end | |
def git_pull(repo) | |
hoge = get_names(repo) | |
gitpath, modname = hoge[0] + '/.git', hoge[1] | |
message = `git --git-dir='#{gitpath}' pull` | |
title = 'git: ' + modname | |
growl(title, message) | |
if /up-to-date/ =~ message then | |
return false | |
else | |
return message | |
end | |
end | |
def cpanm_self_upgrade | |
app = 'cpan-minus: self-upgrade' | |
message = `cpanm --self-upgrade 2>&1 1>/dev/null` | |
if /up\ to\ date/ =~ message then | |
growl(app, message) | |
return false | |
elsif /Successfully\ installed/ =~ message then | |
growl(app, message.gsub(/.*(Successfully\ installed.*)/m) { $1 }) | |
else | |
growl(app, message, 'error') | |
warn message | |
end | |
end | |
#local::lib環境前提 | |
def cpanm_install(installstr, modname) | |
app = 'cpan-minus: ' + modname | |
growl(app, 'fetching...') | |
message = `cpanm -L #{PERLDIR} #{installstr} 2>&1 1>/dev/null` #stdinに何も入らないのでstderrで処理 | |
if /Successfully\ installed/ =~ message then | |
growl(app, 'successfully installed.') | |
else | |
if Config::CONFIG['host_os'] == 'darwin10.0' then | |
warn message | |
growl(app, 'installation failed. try again with 32-bit.', 'impact') | |
mes = `VERSIONER_PERL_PREFER_32_BIT=yes cpanm -L #{PERLDIR} #{installstr} 2>&1 1>/dev/null` | |
if /Successfully\ installed/ =~ mes then | |
growl(app, 'successfully installed.') | |
else | |
growl(app, 'installation falied with 32-bit-compilation.', 'error') | |
warn mes | |
return mes | |
end | |
else | |
warn message | |
growl(app, 'installation falied.', 'error') | |
return message | |
end | |
end | |
end | |
def cpan_update | |
command = PERLDIR + 'bin/cpan-outdated' | |
modules = `#{command}` | |
puts 'following modules have been found outdated:' | |
puts modules | |
repos = modules.split #配列に格納 | |
n = repos.size | |
message = n.to_s + ' modules have been found outdated.' | |
growl('cpan-outdated', message) | |
growl('cpan-minus', 'Now updating...') | |
err = Array.new | |
repos.each do |repo| | |
name = repo.sub(/.\/.*\/(.*)-\d\..*/) { $1 } #アーカイブ名を取得 File.basenameみたいなのでやったほうがスマートかも。 | |
if /\.tar\.gz/ =~ name then | |
name = name.sub(/.\/.*\/(.*)\.tar.*/) { $1 } #バージョン番号がないモノを別処理 | |
else | |
end | |
modname = name.gsub(/-/, '::') #クラス名に変換 | |
foo = cpanm_install(repo, modname) | |
err.push(foo) unless foo.to_s.empty? | |
end | |
en = err.length | |
sn = n - en | |
if en == 0 then | |
growl('cpan-minus', sn.to_s + ' modules have successfully updated.', 'sticky') | |
else | |
growl('cpan-minus', sn.to_s + " modules have successfully updated. \n" + en.to_s + " modules weren\'t updated due to some error.", 'error') | |
end | |
end | |
def git_cpan(repo) | |
result = git_pull(repo) | |
unless result then | |
else | |
hoge = get_names(repo) | |
path, modname = hoge[0], hoge[1] | |
cpanm_install(path, modname) | |
end | |
end | |
gisty_sync | |
git_pull('/Users/shenqi/src/remedie') #絶対パスで指定 | |
git_cpan('plagger') #REPODIR以下を指定 | |
git_cpan('vimana') | |
svn_up('vimperator-plugins') | |
cpanm_self_upgrade | |
cpan_update |
cpanmで、successfully installedの時もgrowlさせるようにした。
うまくいかないところは直した。
fetched growl() from sokuho.rb
growl周りをシンプルに。
loggerでcpan modulesのアップデートがfailしたときに、error.logに保存。
cpan moduelsがアップデートした時は、最後に全部通知することに。
executeするところは全部threadを立てるようにした。どれほど意味があるかはわからない
todo: もうちょっとloggerを活用する。
threadの意味があるかわかんなかったので消した。
ただ、時々こけるのはなぜかわからないので、場合によったら復活するかも。
snow leopardなら、64ビットで failした場合、32ビットでインストールしなおすように改良。
同時にlogger廃止。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gisty addした。
cpanm関連でどうもうまくいかないところがあるみたいなのでとりあえずコメントアウトしておく治ったはず