xrefresh-server 0.1.0 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.6
data/bin/xrefresh-server CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -rubygems
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  # This script watches modifications on the given directories, using the new # FSEvents API in Leopard.
4
4
  # Depends on rubycocoa!
@@ -7,38 +7,27 @@
7
7
  # Based on code by Dave Dribin
8
8
  # http://www.dribin.org/dave/blog/archives/2008/01/04/fswatch/
9
9
 
10
+ require "rubygems"
10
11
  require 'set'
11
12
  require 'optparse'
12
13
  require 'ostruct'
13
14
  require "yaml"
14
- begin
15
- require 'xrefresh-server'
16
- rescue LoadError
17
- require '../lib/xrefresh-server.rb'
18
- end
19
- begin
20
- require 'json'
21
- rescue LoadError
22
- die 'You must "sudo gem install json" to get xrefresh monitor running'
23
- end
15
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'xrefresh-server.rb') # this form is important for local development
24
16
 
25
17
  module XRefreshServer
26
18
 
27
19
  ################################################################################
28
20
  # command-line parsing
29
21
 
30
- $COMMAND = File.basename($0)
31
- $USAGE = "Usage: #{$COMMAND} [OPTIONS]"
32
- $VERSION = XRefreshServer::VERSION
33
- $AGENT = "OSX xrefresh-server"
34
- CONFIG_FILE = ".xrefresh-server.yml"
22
+ COMMAND = File.basename($0)
23
+ USAGE = "Usage: #{COMMAND} [OPTIONS]"
35
24
 
36
25
  options = OpenStruct.new
37
26
  options.output = "-"
38
27
  options.config = nil
39
28
 
40
29
  opts = OptionParser.new do |o|
41
- o.banner = $USAGE
30
+ o.banner = USAGE
42
31
  o.separator ""
43
32
  o.separator "Specific options:"
44
33
 
@@ -62,7 +51,7 @@ module XRefreshServer
62
51
  end
63
52
 
64
53
  o.on_tail("-v", "--version", "Show version") do
65
- puts $VERSION
54
+ puts XRefreshServer::VERSION
66
55
  exit
67
56
  end
68
57
  end
@@ -75,9 +64,9 @@ module XRefreshServer
75
64
 
76
65
  # initialize output handle
77
66
  if options.output == "-"
78
- $out = $stdout.clone
67
+ OUT = $stdout.clone
79
68
  else
80
- $out = File.open(options.output, "w")
69
+ OUT = File.open(options.output, "w")
81
70
  end
82
71
 
83
72
  ################################################################################
@@ -125,7 +114,6 @@ module XRefreshServer
125
114
 
126
115
  ################################################################################
127
116
  # run server
128
- $out.puts "Starting server on #{CONFIG["host"]}:#{CONFIG["port"]} (max #{CONFIG["max_connections"]} clients)"
129
117
  server = Server.new(CONFIG["port"], CONFIG["host"], CONFIG["max_connections"], $stderr, CONFIG["audit"], CONFIG["debug"])
130
118
  server.start
131
119
 
@@ -140,5 +128,4 @@ module XRefreshServer
140
128
  ################################################################################
141
129
  # leave in peace
142
130
  $out.flush
143
- exit(0)
144
131
  end
@@ -1,8 +1,24 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ require 'json'
2
+ begin
3
+ require 'term/ansicolor'
4
+ include Term::ANSIColor
5
+ rescue LoadError
6
+ raise 'Run "sudo gem install term-ansicolor"'
7
+ end
8
+ # http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/
9
+ if PLATFORM =~ /win32/ then
10
+ begin
11
+ require 'win32console'
12
+ include Win32::Console::ANSI
13
+ rescue LoadError
14
+ raise 'Run "sudo gem install win32console" to use terminal colors on Windows'
15
+ end
16
+ end
3
17
 
4
18
  module XRefreshServer
5
- VERSION = '0.1.0'
19
+ VERSION = File.read(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'VERSION'))
20
+ AGENT = "OSX xrefresh-server"
21
+ CONFIG_FILE = ".xrefresh-server.yml"
6
22
 
7
23
  def self.die(s)
8
24
  $stderr.puts s
@@ -27,7 +43,7 @@ paths:
27
43
  dir_include:
28
44
  dir_exclude: ^#{File.expand_path('~')}/Library|/\\.(svn|framework|app|pbproj|pbxproj|xcode(proj)?|bundle)/
29
45
  file_include:
30
- file_exclude: ^(CVS|SCCS|vssver.?.scc|\\.(cvsignore|svn|DS_Store)|_svn|Thumbs\\.db)$|~$|^(\\.(?!htaccess)[^/]*|\\.(tmproj|o|pyc)|svn-commit(\\.[2-9])?\\.tmp)$ # merged TextMate and Netbeans patterns
46
+ file_exclude: ^(CVS|SCCS|vssver.?.scc|\\.(cvsignore|git|svn|DS_Store)|_svn|Thumbs\\.db)$|~$|^(\\.(?!htaccess)[^/]*|\\.(tmproj|o|pyc)|svn-commit(\\.[2-9])?\\.tmp)$ # merged TextMate and Netbeans patterns
31
47
 
32
48
  # xpert settings
33
49
  host: #{GServer::DEFAULT_HOST}
@@ -43,6 +59,7 @@ CONFIG
43
59
 
44
60
  end
45
61
 
46
- require 'client.rb'
47
- require 'server.rb'
48
- require 'monitor.rb'
62
+ LIB_DIR = File.expand_path(File.dirname(__FILE__))
63
+ require File.join(LIB_DIR, 'xrefresh-server/client.rb')
64
+ require File.join(LIB_DIR, 'xrefresh-server/server.rb')
65
+ require File.join(LIB_DIR, 'xrefresh-server/monitor.rb')
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+
3
+ module XRefreshServer
4
+
5
+ # client representation on server side
6
+ class Client
7
+ attr_accessor :id, :dead, :type, :agent
8
+
9
+ def initialize(id, socket)
10
+ @id = id
11
+ @socket = socket
12
+ @dead = false
13
+ @type = '?'
14
+ @agent = '?'
15
+ end
16
+
17
+ def name
18
+ green("#{@type}(#{@id})")
19
+ end
20
+
21
+ def send(data)
22
+ return if @dead
23
+ begin
24
+ @socket << data.to_json
25
+ rescue
26
+ OUT.puts "Client #{name} #{red("is dead")}"
27
+ @dead = true
28
+ end
29
+ end
30
+
31
+ def send_about(version, agent)
32
+ send({
33
+ "command" => "AboutMe",
34
+ "version" => version,
35
+ "agent" => agent
36
+ })
37
+ end
38
+
39
+ def send_do_refresh(root, name, type, date, time, files)
40
+ send({
41
+ "command" => "DoRefresh",
42
+ "root" => root,
43
+ "name" => name,
44
+ "date" => date,
45
+ "time" => time,
46
+ "type" => type,
47
+ "files" => files
48
+ })
49
+ end
50
+ end
51
+
52
+ end
@@ -20,13 +20,13 @@ module XRefreshServer
20
20
  root = FSEventStreamCopyPathsBeingWatched(stream).first
21
21
  paths.regard_as('*')
22
22
  numEvents.times do |n|
23
- $out.puts "Event: #{paths[n]}" if @config["debug"]
23
+ OUT.puts "Event: #{paths[n]}" if @config["debug"]
24
24
  @modified_dirs.add({:root=>root, :dir=>paths[n]})
25
25
  end
26
26
  end
27
27
 
28
28
  @config["paths"].each do |path|
29
- $out.puts " monitoring #{path}"
29
+ OUT.puts " monitoring #{yellow(path)}"
30
30
  # need to create new stream for every supplied path
31
31
  # because we want to report registered sources of the changes
32
32
  stream = FSEventStreamCreate(
@@ -54,14 +54,14 @@ module XRefreshServer
54
54
  # blocking call
55
55
  def run_loop(start_time)
56
56
 
57
- activities = {"changed" => '*', "deleted" => '-', "created" => '+', "renamed" => '>'}
57
+ activities = {"changed" => blue('*'), "deleted" => red('-'), "created" => green('+'), "renamed" => magenta('>')}
58
58
 
59
59
  # main loop
60
- $out.puts "Waiting for file system events ..."
60
+ OUT.puts "Waiting for file system events ..."
61
61
  not_first_time = false
62
62
  loop do
63
63
  if @server.stopped?
64
- $out.puts "Server stopped"
64
+ OUT.puts "Server stopped"
65
65
  break
66
66
  end
67
67
  @streams.each do |stream|
@@ -74,23 +74,23 @@ module XRefreshServer
74
74
  dir = dir_info[:dir]
75
75
  root = dir_info[:root]
76
76
  unless dir=~@config["dir_include"]
77
- $out.puts "debug: #{dir} rejected because dir_include" if @config["debug"]
77
+ OUT.puts "debug: #{dir} rejected because dir_include" if @config["debug"]
78
78
  next
79
79
  end
80
80
  if dir=~@config["dir_exclude"]
81
- $out.puts "debug: #{dir} rejected because dir_exclude" if @config["debug"]
81
+ OUT.puts "debug: #{dir} rejected because dir_exclude" if @config["debug"]
82
82
  next
83
83
  end
84
84
 
85
85
  if File.exists?(dir)
86
- $out.puts "debug: checking dir #{dir}" if @config["debug"]
86
+ OUT.puts "debug: checking dir #{dir}" if @config["debug"]
87
87
  Dir.foreach(dir) do |file|
88
88
  unless file=~@config["file_include"]
89
- $out.puts "debug: #{file} rejected because file_include" if @config["debug"]
89
+ OUT.puts "debug: #{file} rejected because file_include" if @config["debug"]
90
90
  next
91
91
  end
92
92
  if file=~@config["file_exclude"]
93
- $out.puts "debug: #{file} rejected because file_exclude" if @config["debug"]
93
+ OUT.puts "debug: #{file} rejected because file_exclude" if @config["debug"]
94
94
  next
95
95
  end
96
96
 
@@ -98,17 +98,17 @@ module XRefreshServer
98
98
  next if File.directory?(full_path)
99
99
  begin
100
100
  stat = File.stat(full_path)
101
- $out.puts "debug: stat #{full_path}" if @config["debug"]
101
+ OUT.puts "debug: stat #{full_path}" if @config["debug"]
102
102
  rescue
103
103
  # file may not exist
104
- $out.puts "debug: stat failed #{full_path}" if @config["debug"]
104
+ OUT.puts "debug: stat failed #{full_path}" if @config["debug"]
105
105
  next # keep silence
106
106
  end
107
107
  current_time = stat.mtime.to_i
108
108
  original_time = @paths_info[full_path] || start_time
109
109
 
110
110
  if (current_time > original_time)
111
- $out.puts "debug: reported #{full_path}" if @config["debug"]
111
+ OUT.puts "debug: reported #{full_path}" if @config["debug"]
112
112
  relative_path = full_path[root.size+1..-1]
113
113
  buckets[root]||=[]
114
114
  buckets[root]<< {
@@ -129,7 +129,7 @@ module XRefreshServer
129
129
  }
130
130
  end
131
131
  rescue
132
- $out.puts "debug: exception! #{dir}" if @config["debug"]
132
+ OUT.puts "debug: exception! #{dir}" if @config["debug"]
133
133
  raise if @config["debug"]
134
134
  next #keep silence
135
135
  end
@@ -140,9 +140,9 @@ module XRefreshServer
140
140
 
141
141
  if buckets.size
142
142
  buckets.each do |root, files|
143
- $out.puts " activity in #{root}:"
143
+ OUT.puts " activity in #{yellow(root)}:"
144
144
  files.each do |file|
145
- $out.puts " #{activities[file["action"]]} #{file["path1"]}"
145
+ OUT.puts " #{activities[file["action"]]} #{blue(file["path1"])}"
146
146
  end
147
147
  date = nil
148
148
  time = nil
@@ -5,12 +5,13 @@ module XRefreshServer
5
5
 
6
6
  # server
7
7
  class Server < GServer
8
- attr :clients
8
+ attr_accessor :clients
9
9
 
10
- def initialize(*args)
11
- super(*args)
10
+ def initialize(port, host, max_connections, *args)
11
+ super
12
12
  @clients = Set.new
13
13
  @last_client_id = 0
14
+ OUT.puts "#{green('Started server')} on #{blue("#{host}:#{port}")} (max #{max_connections} clients)"
14
15
  end
15
16
 
16
17
  def serve(socket)
@@ -41,19 +42,19 @@ module XRefreshServer
41
42
  end
42
43
 
43
44
  def process(client, msg)
44
- # see windows implementation in src/winmonitor/Server.cs#ProcessMessage
45
+ # see windows implementation in http://github.com/darwin/xrefresh/tree/master/src/winmonitor/Server.cs#ProcessMessage
45
46
  case msg["command"]
46
- when "Hello"
47
- type = msg["type"] || '?'
48
- agent = msg["agent"] || '?'
49
- $out.puts "Client ##{client.id} connected: #{type} (#{agent})"
50
- client.send_about($VERSION, $AGENT)
51
- when "Bye"
52
- @clients.delete(client)
53
- $out.puts "Client ##{client.id} disconnected"
54
- when "SetPage"
55
- url = msg["url"] || '?'
56
- $out.puts "Client ##{client.id} changed page to #{url}"
47
+ when "Hello"
48
+ client.type = msg["type"] || '?'
49
+ client.agent = msg["agent"] || '?'
50
+ OUT.puts "Client #{client.name} [#{magenta(client.agent)}] has connected"
51
+ client.send_about(VERSION, AGENT)
52
+ when "Bye"
53
+ @clients.delete(client)
54
+ OUT.puts "Client #{client.name} has disconnected"
55
+ when "SetPage"
56
+ url = msg["url"] || '?'
57
+ OUT.puts "Client #{client.name} changed page to #{blue(url)}"
57
58
  end
58
59
  end
59
60
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Antonin Hildebrand
1
+ Copyright (c) 2008-2009 Antonin Hildebrand
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -11,10 +11,10 @@ the following conditions:
11
11
  The above copyright notice and this permission notice shall be
12
12
  included in all copies or substantial portions of the Software.
13
13
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHout WARRANTY OF ANY KIND,
15
15
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, out OF OR IN CONNECTION
20
20
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # XRefresh Server for OSX
2
+
3
+ XRefresh is refresh automation for web developers. This is OSX filesystem monitor.
4
+
5
+ ## Visit [xrefresh.binaryage.com](http://xrefresh.binaryage.com)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrefresh-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonin Hildebrand
@@ -9,63 +9,53 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-19 00:00:00 +02:00
13
- default_executable:
14
- dependencies: []
15
-
16
- description: XRefresh filesystem monitor - browser refresh automation tool for web developers
17
- email:
18
- - antonin@hildebrand.cz
12
+ date: 2009-05-26 00:00:00 +02:00
13
+ default_executable: xrefresh-server
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: term-ansicolor
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: XRefresh is browser refresh automation for web developers
36
+ email: antonin@hildebrand.cz
19
37
  executables:
20
38
  - xrefresh-server
21
39
  extensions: []
22
40
 
23
- extra_rdoc_files:
24
- - History.txt
25
- - License.txt
26
- - Manifest.txt
27
- - PostInstall.txt
28
- - README.txt
29
- - website/index.txt
41
+ extra_rdoc_files: []
42
+
30
43
  files:
31
- - History.txt
32
- - License.txt
33
- - Manifest.txt
34
- - PostInstall.txt
35
- - README.txt
36
- - Rakefile
44
+ - VERSION
37
45
  - bin/xrefresh-server
38
- - config/hoe.rb
39
- - config/requirements.rb
40
- - lib/client.rb
41
- - lib/monitor.rb
42
- - lib/server.rb
43
46
  - lib/xrefresh-server.rb
44
- - script/console
45
- - script/destroy
46
- - script/generate
47
- - script/txt2html
48
- - setup.rb
49
- - tasks/deployment.rake
50
- - tasks/environment.rake
51
- - tasks/website.rake
52
- - website/index.html
53
- - website/index.txt
54
- - website/javascripts/rounded_corners_lite.inc.js
55
- - website/stylesheets/screen.css
56
- - website/template.html.erb
47
+ - lib/xrefresh-server/client.rb
48
+ - lib/xrefresh-server/monitor.rb
49
+ - lib/xrefresh-server/server.rb
50
+ - license.txt
51
+ - readme.md
57
52
  has_rdoc: true
58
- homepage: http://xrefresh-server.rubyforge.org
59
- post_install_message: |-
60
- ---
61
- To run monitoring server launch:
62
- xrefresh-server
63
- (when first launched, you will be asked to setup config file)
64
- For more information see http://xrefresh-server.rubyforge.org
65
- ---
53
+ homepage: http://github.com/darwin/xrefresh-server
54
+ licenses: []
55
+
56
+ post_install_message:
66
57
  rdoc_options:
67
- - --main
68
- - README.txt
58
+ - --charset=UTF-8
69
59
  require_paths:
70
60
  - lib
71
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -83,9 +73,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
73
  requirements: []
84
74
 
85
75
  rubyforge_project: xrefresh-server
86
- rubygems_version: 1.1.1
76
+ rubygems_version: 1.3.3
87
77
  signing_key:
88
- specification_version: 2
89
- summary: XRefresh filesystem monitor - browser refresh automation tool for web developers
78
+ specification_version: 3
79
+ summary: XRefresh filesystem monitor for OSX
90
80
  test_files: []
91
81