epitools 0.5.73 → 0.5.74

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
  SHA1:
3
- metadata.gz: ec37ccba9b3b090251f5a096ed57ef7ee4c4e769
4
- data.tar.gz: 9abd4684561e30e28bb23094fd2606e9ef1d8a24
3
+ metadata.gz: aa961c91eff30c2d7caa3240c9e13c3357f56ccb
4
+ data.tar.gz: 9cb7a50ae1a80cd54305c1c182fa45d1d576f0f6
5
5
  SHA512:
6
- metadata.gz: 80a9d929bd6fda00c1fa766af8cee4ebbbfc92dc0fba752c772976ed412c3a5fa1707f64944ebdb5bb2ff1ccb2f7977a9c00b5ddaaddc7de272ad796f6f3c1a4
7
- data.tar.gz: c2d51d16d96359830af2ea2532708ed6362dff0b60610a709641e66d6718dcfadfafb6f28ba06ce7b4f7dde23bc6ad67fb8b741e04eb0e91cfc24cb3a160dcbe
6
+ metadata.gz: 9e51e7eed16a96a82c2ae58589152623157d069f5e7fa096a14985b2cc5a2fb7960ecf3e10ca183ed55c953efd85f3cd414218d514de8800055387fe01b6cf66
7
+ data.tar.gz: 31a6dbe284c4c0544a093ce2d2937ca8751bf9f71e241911e0ca65e3536ed2fca4216dd20b42021b7e714190d930465fdc86ccc10a462a2d69ebb940c71df08c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.73
1
+ 0.5.74
@@ -27,6 +27,16 @@ module Digest
27
27
  autoload :MD5, 'digest/md5'
28
28
  end
29
29
 
30
+ # Network Sockets
31
+ ['IP', 'Basic', 'TCP', 'UDP', 'UNIX', ''].each do |type|
32
+ autoload :"#{type}Socket", 'socket'
33
+ end
34
+
35
+ # Network Servers
36
+ ['TCP', 'UNIX'].each do |type|
37
+ autoload :"#{type}Server", 'socket'
38
+ end
39
+
30
40
  if RUBY_VERSION["1.8.7"]
31
41
  autoload :Prime, 'mathn'
32
42
  else
@@ -58,6 +68,7 @@ autoreq :Mechanize, 'mechanize'
58
68
  autoreq :ANSI, 'ansi'
59
69
  autoreq :BSON, 'bson'
60
70
  autoreq :JSON, 'json'
71
+ autoreq :GeoIP, 'geoip'
61
72
 
62
73
  autoreq :AwesomePrint do
63
74
  require 'awesome_print'
@@ -68,19 +79,6 @@ autoreq :AwesomePrint do
68
79
  end
69
80
  end
70
81
 
71
- ## Network stuff
72
-
73
- # Sockets
74
- ['IP', 'Basic', 'TCP', 'UDP', 'UNIX', ''].each do |type|
75
- autoload :"#{type}Socket", 'socket'
76
- end
77
-
78
- # Servers
79
- ['TCP', 'UNIX'].each do |type|
80
- autoload :"#{type}Server", 'socket'
81
- end
82
-
83
-
84
82
  ## YAML hacks (sometimes the module is loaded improperly)
85
83
 
86
84
  if defined? YAML and not defined? YAML.parse
@@ -169,3 +169,25 @@ def sudoifnotroot
169
169
  exit system("sudo", $PROGRAM_NAME, *ARGV)
170
170
  end
171
171
  end
172
+
173
+
174
+ GEOIP_COUNTRY_DATA = '/usr/share/GeoIP/GeoIP.dat'
175
+ GEOIP_CITY_DATA = '/usr/share/GeoIP/GeoIPCity.dat'
176
+
177
+ def geoip(addr)
178
+ $geoip ||= begin
179
+ if File.exists? GEOIP_CITY_DATA
180
+ geo = GeoIP.new GEOIP_CITY_DATA
181
+ proc { |addr| geo.city(addr) }
182
+
183
+ elsif File.exists? GEOIP_COUNTRY_DATA
184
+ geo = GeoIP.new GEOIP_COUNTRY_DATA
185
+ proc { |addr| geo.country(addr) }
186
+
187
+ else
188
+ raise "Can't find GeoIP data in /usr/share/GeoIP."
189
+ end
190
+ end
191
+
192
+ $geoip.call(addr)
193
+ end
@@ -49,7 +49,7 @@ module WM
49
49
  current
50
50
  end
51
51
 
52
- alias_method :active?, :current?
52
+ alias_method :active?, :current?
53
53
 
54
54
  def windows
55
55
  @windows ||= WM.windows.select { |w| w.desktop_id == num }
@@ -102,8 +102,17 @@ module WM
102
102
  end
103
103
 
104
104
  def activate!
105
- #system "wmctrl", "-i", "-a", window_id
106
- system "xdotool", "windowactivate", window_id
105
+ system "wmctrl", "-i", "-a", window_id
106
+ end
107
+
108
+ #
109
+ # string is made up of regular text, plus <>'d keypresses
110
+ # eg: "Hello<Ctrl-T><Ctrl-L><Ctrl-Shift-K><Return>!!!"
111
+ #
112
+ # TODO: add `xdotool` support
113
+ #
114
+ def send_keys(keys)
115
+ xse(keys)
107
116
  end
108
117
 
109
118
  #
@@ -309,8 +318,8 @@ module WM
309
318
  # thorn 0x00fe /* U+00FE LATIN SMALL LETTER THORN */
310
319
  # ydiaeresis 0x00ff /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
311
320
  #
321
+ if Path.which("xse")
312
322
 
313
- if Path.which("xdotool")
314
323
  KEYMAP = {
315
324
  "`" => "grave",
316
325
  " " => "space",
@@ -319,49 +328,63 @@ module WM
319
328
  "\[" => "Escape",
320
329
  '"' => "quotedbl",
321
330
  }
331
+ def keys_to_events(keys)
322
332
 
323
- def string_to_keys(s)
333
+ tokens = keys.scan(/(<[^>]+>|.+?)/)
324
334
 
325
- tokens = s.scan(/(<[^>]+>|.)/).flatten
335
+ tokens.flatten.map do |key|
336
+ mods = []
337
+
338
+ if key =~ /^<(.+)>$/
339
+
340
+ specials = $1.split("-")
341
+ key = specials.pop
342
+
343
+ key.downcase! if key =~ /^[A-Z]$/
344
+
345
+ specials.each do |special|
346
+ if special =~ /^(Ctrl|Shift|Alt)$/i
347
+ mods << $1
348
+ else
349
+ raise "Error: unknown modifier #{special}"
350
+ end
351
+ end
326
352
 
327
- tokens.map do |token|
328
- if token =~ /^<(.+)>$/
329
- mods = $1.split(/[-+]/)
330
- key = mods.pop
331
- # mods.each { |mod| raise "Error: unknown modifier #{mod}" unless mod =~ /^(Ctrl|Shift|Alt)$/i }
332
- else
333
- mods = []
334
- key = token
335
353
  end
336
354
 
355
+ mods << "Shift" if key =~ /^[A-Z\~\!\@\#\$\%\^\&\*\(\)\_\+]$/
356
+
337
357
  if key =~ /^[A-Z0-9]$/i or key.size > 1
338
- # key is good!
358
+ keyname = key
339
359
  else
340
- key = KEYMAP[key] || ("0x%x" % key.ord)
360
+ keyname = KEYMAP[key] || ("0x%x" % key.ord)
341
361
  end
342
362
 
343
- [*mods, key].join("+")
363
+ "#{mods.join(" ")}<Key>#{keyname}"
344
364
  end
345
365
  end
346
366
 
347
- #
348
- # Send keypresses to this window, using xdotool.
349
- # (`delay` specifies how long to pause between each keystroke, default: 12ms)
350
- #
351
- # Examples:
352
- # > window.send_keys("Hello Everybo<Ctrl-W>World!<Return>!!!")
353
- # > browser.send_keys("<Ctrl-T>http://google.com/<Return>")
354
- #
355
- def send_keys(keystring, delay=nil)
356
- keys = string_to_keys(keystring)
357
- cmd = ["xdotool", "key", "--clearmodifiers", "--window", window_id]
358
- cmd += ["--delay", delay.to_s] if delay
359
- cmd += keys
360
-
361
- system(*cmd)
367
+ def xse(keys)
368
+ temp = Tempfile.new("xse")
369
+ events = keys_to_events(keys)
370
+
371
+ # p events
372
+ eventstring = events.map { |e| e + "\n" }.join("")
373
+
374
+ temp.write eventstring
375
+ temp.flush
376
+ temp.seek 0
377
+ # p [:temp, temp.read]
378
+
379
+ cmd = "xse", "-window", window_id, "-file", temp.path
380
+ # p [:cmd, cmd]
381
+ unless system(*cmd)
382
+ raise "Error: couldn't send key commands to 'xse'. (Is xsendevents installed?)"
383
+ end
362
384
  end
363
- end
364
385
 
365
- end
386
+ end # Path.which('xse')
387
+
388
+ end # class Window
366
389
 
367
390
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.73
4
+ version: 0.5.74
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec