hacking at stuff

This commit is contained in:
John Bintz 2012-05-07 06:44:25 -04:00
parent dedff60119
commit 88400268c5
3 changed files with 50 additions and 48 deletions

View File

@ -1,57 +1,11 @@
#!/usr/bin/env ruby
require 'bundler/setup'
require 'Qt4'
require 'thread'
require 'atomic'
require 'thor'
class UnisonProfile
def self.process(profiles)
profiles.collect { |profile| new(profile) }
end
def initialize(which)
@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
return @lines if @lines
@lines = File.readlines(File.expand_path("~/.unison/#{@which}.prf"))
includes = []
@lines.each do |line|
if file = line[%r{^include (.*)}, 1]
includes += File.readlines(File.expand_path("~/.unison/#{file}"))
end
end
@lines += includes
end
def paths
@paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) }
end
def paths_with_local_root
paths.collect { |path| File.join(local_root, path) }
end
def value_of(line)
line[%r{=(.*)$}, 1].strip
end
end
require 'unison/profile'
class UnisonWatcher < Qt::Application
TRANSFER_LOG = '~/unison.log'
@ -74,7 +28,7 @@ class UnisonWatcher < Qt::Application
end
def processed_profiles
@processed_profiles ||= UnisonProfile.process(@profiles)
@processed_profiles ||= Unison::Profile.process(@profiles)
end
def watch

48
lib/unison/profile.rb Normal file
View File

@ -0,0 +1,48 @@
module Unison
class Profile
def self.process(profiles)
profiles.collect { |profile| new(profile) }
end
def initialize(which)
@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
return @lines if @lines
@lines = File.readlines(File.expand_path("~/.unison/#{@which}.prf"))
includes = []
@lines.each do |line|
if file = line[%r{^include (.*)}, 1]
includes += File.readlines(File.expand_path("~/.unison/#{file}"))
end
end
@lines += includes
end
def paths
@paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) }
end
def paths_with_local_root
paths.collect { |path| File.join(local_root, path) }
end
def value_of(line)
line[%r{=(.*)$}, 1].strip
end
end
end

0
unison-watch.gemfile Normal file
View File