From 9be434c7c0c1659038da3068033ce1486bb88187 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 2 May 2012 19:40:16 -0400 Subject: [PATCH] initial commit for my cool thing --- .gitignore | 2 + Gemfile | 7 ++ assets/idle.png | Bin 0 -> 3330 bytes assets/working-1.png | Bin 0 -> 3719 bytes assets/working-2.png | Bin 0 -> 3697 bytes bin/unison-watch | 157 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 assets/idle.png create mode 100644 assets/working-1.png create mode 100644 assets/working-2.png create mode 100755 bin/unison-watch diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80e3957 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Gemfile.lock + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e44a59d --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source :rubygems + +gem 'qtbindings' +gem 'rb-fsevent' +gem 'atomic' +gem 'daemons' + diff --git a/assets/idle.png b/assets/idle.png new file mode 100644 index 0000000000000000000000000000000000000000..7b5aa4f56d9ecf846ffc53e8ed40ad42aa7f77c0 GIT binary patch literal 3330 zcmV+d4gKEX>4Tx0C?J+Q+HUC_ZB|i_hk=OLfG)Jmu!ImA|tE_$Pihg5Rw34gb)%y#f69p zRumNxoJdu~g4GI0orvO~D7a@qiilc^Ra`jkAKa(4eR}Wh?fcjJyyu+f{LXpL4}cL8 zCXwc%Y5+M>g*-agACFH+#L2yY0u@N$1RxOR%fe>`#Q*^C19^CUbg)1C0k3ZW0swH; zE+i7i;s1lWP$pLZAdvvzA`<5d0gzGv$SzdK6adH=0I*ZDWC{S3003-xd_p1ssto|_ z^hrJi0NAOM+!p}Yq8zCR0F40vnJ7mj0zkU}U{!%qECRs70HCZuA}$2Lt^t5qwlYTo zfV~9(c8*w(4?ti5fSE!p%m5%b0suoE6U_r4Oaq`W(!b!TUvP!ENC5!A%azTSOVTqG zxRuZ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9 z`>&DS+aY?CS$uiOO*=7f@Ib`z0NKE@-GW&)VnB)6=t7XlWkD1O-mma~UCWZ%fq;~& P00000NkvXXu0mjf(rPF~ literal 0 HcmV?d00001 diff --git a/bin/unison-watch b/bin/unison-watch new file mode 100755 index 0000000..00cc23f --- /dev/null +++ b/bin/unison-watch @@ -0,0 +1,157 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' + +require 'Qt4' +require 'rb-fsevent' +require 'thread' +require 'atomic' +require 'daemons' + + +ENV['PROFILE'] ||= 'default' + + +TRANSFER_LOG = '~/unison.log' +SYNC_CHECK_COUNT = 600 +SYNC_CHECK_TIME = 0.1 + +@queue = Atomic.new([]) + +def <<(dirs) + @queue.update { |q| q += dirs ; q } +end +public :<< + +def check + remote_sync_check = SYNC_CHECK_COUNT + + Thread.new do + while true do + begin + if @queue.value.length > 0 || remote_sync_check == 0 + dir = nil + @queue.update { |q| ; dir = q.shift ; q } + + @status.text = "Syncing..." + + animation = Thread.new do + while !Thread.current[:done] do + @current_icon = 'working-1' + sleep 0.25 + @current_icon = 'working-2' + sleep 0.25 + end + + @current_icon = 'idle' + end + + system %{bash -c 'unison -batch default'} + + animation[:done] = true + + remote_sync_check = SYNC_CHECK_COUNT + end + rescue => e + puts e.message + puts e.backtrace.join("\n") + exit + end + + remote_sync_check -= 1 + check_text = "Next check in #{sprintf("%.0d", SYNC_CHECK_TIME * remote_sync_check)} secs." + @status.text = check_text + + sleep SYNC_CHECK_TIME + end + end +end + +class UnisonProfile + def initialize(which = ENV['PROFILE']) + @which = which + end + + def local_root + roots.find { |root| root[%r{^/}] } + end + + def roots + @roots ||= lines.find_all { |line| line[%r{^root}] }.collect { |line| value_of(line) } + end + + def lines + @lines ||= File.readlines(File.expand_path("~/.unison/#{@which}.prf")) + end + + def paths + @paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) } + end + + def value_of(line) + line[%r{=(.*)$}, 1].strip + end +end + +profile = UnisonProfile.new + +watcher = Thread.new do + while !Thread.current[:app]; sleep 0.1; end + + begin + watch = FSEvent.new + watch.watch Thread.current[:paths], :latency => 0.25 do |directories| + Thread.current[:app] << directories + end + watch.run + rescue => e + puts e.message + puts e.backtrace.join("\n") + exit + end +end + +app = Qt::Application.new(ARGV) + +watcher[:paths] = profile.paths.collect { |path| File.join(profile.local_root, path) } +watcher[:app] = self + +menu = Qt::Menu.new + +@status = Qt::Action.new("Unison watch idle.", menu) +@status.enabled = false + +log = Qt::Action.new("View transfer log", menu) +log.connect(SIGNAL :triggered) { system %{open #{TRANSFER_LOG}} } + +exiting = false + +quit = Qt::Action.new("Quit", menu) +quit.connect(SIGNAL :triggered) { exiting = true } + +menu.addAction @status +menu.addSeparator +menu.addAction log +menu.addAction quit + +icon = Qt::SystemTrayIcon.new +icon.contextMenu = menu + +@current_icon = 'idle' +@prior_icon = nil + +check + +while !exiting + log.enabled = File.file?(File.expand_path(TRANSFER_LOG)) + if @current_icon != @prior_icon + icon.icon = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__)) + + icon.show if !@prior_icon + @prior_icon = @current_icon + end + + app.processEvents + sleep 0.1 +end +