kdwatch 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50e6ea6a1e81ab7f17173c1251395a6fbeb1a4b4c236d1c9c6fd1731f3118ca8
4
- data.tar.gz: 31235eb66b35d5c39ebd1f124e938dfcc9b3f305a020ddf05dc610b7e8832707
3
+ metadata.gz: 78de5f5fc93f9cab8290038be3ef8671ad55616aa894a1adc8065ddaee91afe5
4
+ data.tar.gz: 8bbc03a04d4924a48ba6b44f911ae7e081f5e5c01d5e18bfd7b181efb50afeb7
5
5
  SHA512:
6
- metadata.gz: 39e2d6062ef4adf87ce11d05c2d18e4d305de91e8212d1c204bc7bd0b8c8086f3c662e59deeaa284779f326bebdbd3c06af6ec993c4bc3ad4ad0dea0a468ee80
7
- data.tar.gz: 9db4d837a11aea7413de4362bc418cb56fb2f987dc926ab722bd1b8be06850a2a2e51110e78dd75caebec5b2b7280e0b14592910f00478879b127e8724d0b070
6
+ metadata.gz: c1401f0029d6a39e348d22c35a53e541f70400300dcf2fd0ddf60474733ca4871039a8e3890a16c5ba70dcf48e3a823ed6acf5f1248ebb2fa80af49f0ce8ec06
7
+ data.tar.gz: 4bd5673bb06462c267ff344509c6ec9c280a2d9856d8fe31cb98503de0a544b1ade1b4f6c095e558487b572e2f8482599bc958856814a5a95a48077386b67d5c
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Carsten Bormann
3
+ Copyright (c) 2021, 2022 Carsten Bormann
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -51,9 +51,11 @@ There can only be one kdwatch active on each host and port. You will
51
51
  need to specify a different port (or host!) to run more than one
52
52
  kdwatch at the same time.
53
53
 
54
- * `-p port` to select a port number (default: 7991)
55
- * `-1` to `6` as a shortcut for `-p 7991` (default) to `-p 7996` (must be last
54
+ * `-p port` to select a specific port number
55
+ * `-1` to `6` as a shortcut for `-p 7991` to `-p 7996` (must be last
56
56
  option because of an idiosyncrasy of the optionparser library)
57
+ * if no port number is given, `kdwatch` will hunt for a port number
58
+ that doesn't have a listener, starting with 7991.
57
59
 
58
60
  kdwatch has two flags to simplify handling servers that might be
59
61
  accumulating on one host/port:
@@ -64,18 +66,19 @@ accumulating on one host/port:
64
66
  So the most likely use is going to be:
65
67
 
66
68
  ```
67
- kdwatch -r
69
+ kdwatch
68
70
  ```
69
71
 
70
- or maybe
72
+ to start a new server on a new port number.
73
+
74
+ These tend to accumulate a bit, so sometimes you'll want to replace an
75
+ existing one (here: port number 7992):
71
76
 
72
77
  ```
73
78
  kdwatch -r2
74
79
  ```
75
80
 
76
- for the second draft you are editing at the same time,
77
-
78
- or, if your drafts are weirdly named or you need to select one out of
81
+ If your drafts are weirdly named or you need to select one out of
79
82
  many
80
83
 
81
84
  ```
@@ -118,6 +121,35 @@ another laptop), and save some screen real-estate on your laptop.
118
121
  With a globally routable address, kdwatch even can be used for joint
119
122
  viewing in a team.
120
123
 
124
+ ### Finding and accessing kdwatch servers
125
+
126
+ The `kds` tool can list active local (127.0.0.1) kdwatch servers and
127
+ optionally quickly open the page for a selected kdwatch server.
128
+
129
+ ```
130
+ Usage: kds [options] [match...]
131
+ Version: n.m.l (from kdwatch)
132
+ -v, --version Show version and exit
133
+ -h, --help Show option summary and exit
134
+ -f, --from=NUM Search from port number (7991)
135
+ -t, --to=NUM Search to port number (7999)
136
+ ```
137
+
138
+ ```
139
+ $ kds
140
+ http://127.0.0.1:7991 Packed CBOR
141
+ http://127.0.0.1:7992 Concise Problem Details For CoAP APIs
142
+ $ kds prob
143
+ http://127.0.0.1:7991 Packed CBOR
144
+ http://127.0.0.1:7992 Concise Problem Details For CoAP APIs
145
+ (...web page http://127.0.0.1:7992 opens...)
146
+ $
147
+ ```
148
+
149
+ Any match arguments are concatenated with spaces; for servers that
150
+ offer a page with the match string in the title (case insensitive), a
151
+ window is opened in the default browser.
152
+
121
153
  ## Feedback, please
122
154
 
123
155
  This has only been tested on macOS and briefly on Linux. No idea about WSL.
data/bin/kds ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ require 'socket'
3
+ require 'uri'
4
+ require 'open-uri'
5
+ require 'optparse'
6
+
7
+ KDWATCH_VERSION=Gem.loaded_specs["kdwatch"].version rescue "unknown-version"
8
+
9
+ loport = 7991
10
+ hiport = 7999
11
+ match = nil
12
+
13
+ op = OptionParser.new do |opts|
14
+ opts.banner = <<BANNER
15
+ Usage: kds [options] [match...]
16
+ Version: #{KDWATCH_VERSION} (from kdwatch)
17
+ BANNER
18
+ opts.on("-v", "--version", "Show version and exit") do |v|
19
+ puts "kds, from kdwatch #{KDWATCH_VERSION}"
20
+ exit
21
+ end
22
+ opts.on("-h", "--help", "Show option summary and exit") do |v|
23
+ puts opts
24
+ exit
25
+ end
26
+ opts.on("-fNUM", "--from=NUM", Integer, "Search from port number (#{loport})") do |v|
27
+ loport = v
28
+ end
29
+ opts.on("-tNUM", "--to=NUM", Integer, "Search to port number (#{hiport})") do |v|
30
+ hiport = v
31
+ end
32
+ end
33
+ op.parse!
34
+
35
+ if ARGV.size != 0
36
+ match = ARGV.join(" ")
37
+ end
38
+
39
+ (loport..hiport).each do |p|
40
+ url = "http://127.0.0.1:#{p}"
41
+ URI(url).open do |f|
42
+ s = f.readpartial(40000)
43
+ sc = s.scan(/id="title".*?<|Internal server error/)
44
+ sc.each do |scl|
45
+ scl.sub!(/id="title">/, "")
46
+ scl.chomp!('<')
47
+ puts "#{url} #{scl}"
48
+ if match && scl.downcase.include?(match.downcase)
49
+ spawn("open #{url} || xdg-open #{url} || echo @@@ Please open #{url}")
50
+ end
51
+ break
52
+ end
53
+ end rescue nil
54
+ end
data/bin/kdwatch CHANGED
@@ -6,11 +6,24 @@ ENV["KRAMDOWN_PERSISTENT"]="yes"
6
6
 
7
7
  require 'optparse'
8
8
  require 'ostruct'
9
+ require 'socket'
9
10
 
10
11
  require_relative "../lib/kdwatch/version"
11
12
 
12
13
  KDWATCH_PORT = 7991 # currently unregistered...
13
14
 
15
+ def socket_is_free(host, port, uri)
16
+ begin
17
+ TCPSocket.new(host, port, connect_timeout: 1)
18
+ rescue Errno::ECONNREFUSED => e
19
+ return true
20
+ rescue => e
21
+ warn "*** #{uri} -- #{e.inspect}"
22
+ return nil # break, but don't use
23
+ end
24
+ return false
25
+ end
26
+
14
27
  options = OpenStruct.new
15
28
 
16
29
  op = OptionParser.new do |opts|
@@ -30,7 +43,7 @@ BANNER
30
43
  opts.on("-r", "--[no-]replace", "Replace existing server")
31
44
  opts.on("-oNAME", "--host=NAME", String, "Server host (127.0.0.1)")
32
45
  opts.on("-i", "--internet", 'Abbr. "on the Internet" (host = "::")')
33
- opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT})")
46
+ opts.on("-pNUM", "--port=NUM", Integer, "Port number (#{KDWATCH_PORT}...)")
34
47
  opts.on("-[1-6]", "--[1-6]", Integer, "Abbr. port number (#{KDWATCH_PORT/10}x), must be last")
35
48
  end
36
49
  begin
@@ -52,7 +65,26 @@ if short_port = options[""]
52
65
  warn "** overriding port #{options.port} with #{port}" if options.port
53
66
  options.port = port
54
67
  else
55
- options.port ||= KDWATCH_PORT
68
+ unless options.port
69
+ port = KDWATCH_PORT
70
+ host = options.host
71
+ host = "[#{host}]" if host =~ /:/
72
+ uri = nil
73
+ found = false
74
+ 100.times do
75
+ uri = "http://#{host}:#{port}"
76
+ # warn "Trying URI #{uri}"
77
+ found = socket_is_free(options.host, port, uri)
78
+ break unless found == false
79
+ port += 1
80
+ end
81
+ unless found
82
+ warn "*** Cannot find port number available to serve from!"
83
+ exit 1
84
+ end
85
+ warn "*** Using URI: #{uri}"
86
+ options.port = port
87
+ end
56
88
  end
57
89
 
58
90
  # p options
data/kdwatch.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
25
  end
26
- spec.executables = ['kdwatch']
26
+ spec.executables = ['kdwatch', 'kds']
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "bundler", '~> 2.2'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdwatch
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,6 +127,7 @@ email:
127
127
  - cabo@tzi.org
128
128
  executables:
129
129
  - kdwatch
130
+ - kds
130
131
  extensions: []
131
132
  extra_rdoc_files: []
132
133
  files:
@@ -134,6 +135,7 @@ files:
134
135
  - Gemfile
135
136
  - LICENSE.txt
136
137
  - README.md
138
+ - bin/kds
137
139
  - bin/kdwatch
138
140
  - kdwatch.gemspec
139
141
  - lib/kdwatch-app.rb
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  - !ruby/object:Gem::Version
158
160
  version: '0'
159
161
  requirements: []
160
- rubygems_version: 3.2.32
162
+ rubygems_version: 3.3.11
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: 'kdwatch: open auto-reloaded HTML for kramdown-rfc in a browser.'