ruby-macrodroid 0.9.9 → 0.9.10

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: 11509c0f7448ef65211af5a07e3191f4292eecfe6c8aa19d79a520b4aaf04f21
4
- data.tar.gz: '08960e2e07bf7c467233be373ae1ae8978302122cba7ab6dfca3c5e28cfe7c46'
3
+ metadata.gz: cfb8dbf1cb2f5796722de69e98afcb6d7058ba6faf743740a989589fd3d72fc5
4
+ data.tar.gz: 4b6ff72308bae85939e3eadf7776a3b56d2b8084103633dbb7754f496fb7c037
5
5
  SHA512:
6
- metadata.gz: 0dd2c7ef1a69f05eb9eb235aac3a8805522f68731c2f980fd730eb0b34ee15066d23ead4f74c3dbd762fc3bfb31d852bdfb5f637d362a4a4cbe0b4e5de17c338
7
- data.tar.gz: 2483d3e4901eb5a839ab3c716674f0fbf0fe925bb94bfa99a71ec5803aab0472235be98dd5773bbb5fd57ee7c8c1c77d242d5e7fbcf5f5bb4dfd09580a24f96a
6
+ metadata.gz: 722fc170955c3ee925821859e87c3380b5769db34081c8318ee043218e2bb36ae43e104d6c701238ef887405c30c8d05ab3cba32a040e6430392bc60dd6dbce1
7
+ data.tar.gz: 2343b75872d051e055d3dd6955dcf03c7c236ef5f77e1b43b5618515b8f0170728878336fe8a2aed5eac51ddce9361c751f3d9170418ee289d2e5522b18ff472
@@ -1,2 +1,3 @@
1
-
2
- 0Ch��b֏��j�X��.��g$�}�PU"O��P]�tSE}�E�a�|'?�]1�
1
+ ��-��TCc������(M
2
+ n+F��
3
+ vkG EE ��A��m��<��dB$%����7j}i]�<ڴ��s��&΃|\n���e����W�"�T6A���ҎC� �'H�oq}���Pԅ˭�S�)�D�J��[�ٳFa#��PE�hby^�1׋b����wO"��Qʢ�g� ha����������`*��6/��G�}�Y�Z�u���wu��+�g</4�>$�D����.��XU���`q-
data.tar.gz.sig CHANGED
Binary file
@@ -122,6 +122,7 @@ class MacroDroid
122
122
  @picture_path = picture_path
123
123
 
124
124
  @geofences = {}
125
+ @macros = []
125
126
 
126
127
  if obj then
127
128
 
@@ -145,34 +146,7 @@ class MacroDroid
145
146
 
146
147
  if s =~ /m(?:acro)?:\s/ then
147
148
 
148
- puts 'before RowX.new' if @debug
149
-
150
- s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
151
- .gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
152
- .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
153
- .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
154
-
155
- a = s2.split(/(?=^macro:)/)
156
-
157
- raw_geofences = a.shift if a.first =~ /^geofence/
158
- raw_macros = a.join
159
- #raw_macros, raw_geofences .reverse
160
-
161
- puts 'raw_macros: ' + raw_macros.inspect if @debug
162
-
163
- if raw_geofences then
164
-
165
- geoxml = RowX.new(raw_geofences).to_xml
166
-
167
- geodoc = Rexle.new(geoxml)
168
- geofences = geodoc.root.xpath('item/geofence')
169
- @geofences = fetch_geofences(geofences) if geofences.any?
170
-
171
- end
172
-
173
- xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
174
- puts 'xml: ' + xml if @debug
175
- import_rowxml(xml)
149
+ import_txt(s)
176
150
 
177
151
  elsif s =~ /^# /
178
152
  xml = pc_to_xml(s)
@@ -229,6 +203,10 @@ class MacroDroid
229
203
  def export(filepath)
230
204
  FileX.write filepath, to_json
231
205
  end
206
+
207
+ def import(s)
208
+ import_txt(s)
209
+ end
232
210
 
233
211
  def to_json()
234
212
 
@@ -337,7 +315,7 @@ class MacroDroid
337
315
 
338
316
  m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
339
317
  remote_url: @remote_url, picture_path: @picture_path,
340
- debug: @debug )
318
+ parent: self, debug: @debug )
341
319
  m.import_h(macro)
342
320
  m
343
321
 
@@ -356,15 +334,50 @@ class MacroDroid
356
334
  puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
357
335
  geofences = @geofences
358
336
 
359
- @macros = doc.root.xpath('item').map do |node|
337
+ a = doc.root.xpath('item').map do |node|
360
338
  puts ('geofences: ' + geofences.inspect).highlight if @debug
361
339
  Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
362
340
  remote_url: @remote_url, picture_path: @picture_path,
363
- debug: @debug).import_xml(node)
341
+ parent: self, debug: @debug).import_xml(node)
364
342
 
365
343
  end
344
+
345
+ @macros.concat a
366
346
 
367
- end
347
+ end
348
+
349
+ def import_txt(s)
350
+
351
+ puts 'before RowX.new' if @debug
352
+
353
+ s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
354
+ .gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
355
+ .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
356
+ .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
357
+
358
+ a = s2.split(/(?=^macro:)/)
359
+
360
+ raw_geofences = a.shift if a.first =~ /^geofence/
361
+ raw_macros = a.join
362
+ #raw_macros, raw_geofences .reverse
363
+
364
+ puts 'raw_macros: ' + raw_macros.inspect if @debug
365
+
366
+ if raw_geofences then
367
+
368
+ geoxml = RowX.new(raw_geofences).to_xml
369
+
370
+ geodoc = Rexle.new(geoxml)
371
+ geofences = geodoc.root.xpath('item/geofence')
372
+ @geofences = fetch_geofences(geofences) if geofences.any?
373
+
374
+ end
375
+
376
+ xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
377
+ puts 'xml: ' + xml if @debug
378
+ import_rowxml(xml)
379
+
380
+ end
368
381
 
369
382
  def import_xml(raws)
370
383
 
@@ -384,7 +397,8 @@ class MacroDroid
384
397
  @macros = doc.root.xpath('macro').map do |node|
385
398
  puts 'node: ' + node.inspect if @debug
386
399
  Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
387
- picture_path: @picture_path, debug: @debug).import_xml(node)
400
+ picture_path: @picture_path, parent: self, debug: @debug)\
401
+ .import_xml(node)
388
402
 
389
403
  end
390
404
  end
@@ -150,7 +150,7 @@ class OpenWebPageAction < ApplicationAction
150
150
 
151
151
  def initialize(obj={}, macro=nil)
152
152
 
153
- $debug = true
153
+ $debug = false
154
154
  puts ('obj: ' + obj.inspect).debug if $debug
155
155
 
156
156
  h = if obj.is_a? Hash then
@@ -190,9 +190,9 @@ class OpenWebPageAction < ApplicationAction
190
190
  #h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
191
191
 
192
192
  options = {
193
- variable_to_save_response: {:string_value=>"", :name=>"coords",
194
- decimal_value: 0.0, isLocal: true, m_boolean_value: false,
195
- excludeFromLog: false, int_value: 0, type: 2},
193
+ #variable_to_save_response: {:string_value=>"", :name=>"coords",
194
+ #decimal_value: 0.0, isLocal: true, m_boolean_value: false,
195
+ #excludeFromLog: false, int_value: 0, type: 2},
196
196
  url_to_open: '',
197
197
  http_get: true,
198
198
  disable_url_encode: false,
@@ -298,7 +298,7 @@ class TakePictureAction < CameraAction
298
298
 
299
299
  e, macro = obj
300
300
 
301
- puts 'e: ' + e.xml.inspect
301
+ #puts 'e: ' + e.xml.inspect
302
302
 
303
303
  a = e.xpath('item/*')
304
304
 
@@ -312,7 +312,7 @@ class TakePictureAction < CameraAction
312
312
 
313
313
  desc = h2[:description]
314
314
  h2.delete :description
315
- puts 'desc: ' + desc.inspect
315
+ #puts 'desc: ' + desc.inspect
316
316
 
317
317
  if desc.length > 1 then
318
318
 
@@ -469,10 +469,14 @@ end
469
469
 
470
470
  # Conditions/Loops
471
471
  #
472
- class IfConditionAction < Action
473
472
 
473
+ class IfAction < Action
474
+ using ColouredText
475
+
474
476
  def initialize(obj=nil)
475
-
477
+
478
+ $debug = false
479
+
476
480
  options = {
477
481
  a: true,
478
482
  constraint_list: []
@@ -492,10 +496,10 @@ class IfConditionAction < Action
492
496
  super()
493
497
  puts 'e.xml: ' + e.xml if $debug
494
498
  puts 'e.text: ' + e.text.to_s.strip if $debug
495
- raw_txt = e.text.to_s.strip[/^if [^$]+/i] || e.text('item/description')
499
+ raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description')
496
500
  puts 'raw_txt: ' + raw_txt.inspect if $debug
497
501
 
498
- clause = raw_txt[/^If (.*)/i,1]
502
+ clause = raw_txt[/^#{@label}(.*)/i,1]
499
503
  puts 'clause: ' + clause.inspect if $debug
500
504
  conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
501
505
  puts 'conditions: ' + conditions.inspect if $debug
@@ -514,6 +518,7 @@ class IfConditionAction < Action
514
518
 
515
519
  # find any nested actions
516
520
  item = e.element('item')
521
+ #puts ('item: ' + item.xml.inspect).debug if $debug
517
522
 
518
523
  if item then
519
524
 
@@ -534,19 +539,13 @@ class IfConditionAction < Action
534
539
 
535
540
  end
536
541
 
537
-
538
-
539
-
540
-
541
- @label = 'If '
542
-
543
542
  end
544
-
543
+
545
544
  def to_s(colour: false, indent: 0)
546
545
 
547
546
  h = @h.clone
548
547
  #h.delete :macro
549
- @s = 'If '
548
+ @s = @label
550
549
  operator = @h[:is_or_condition] ? 'OR' : 'AND'
551
550
  constraints = @constraints.map \
552
551
  {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
@@ -557,7 +556,18 @@ class IfConditionAction < Action
557
556
  out << s + constraints
558
557
  out.join("\n")
559
558
 
560
- end
559
+ end
560
+
561
+ end
562
+
563
+ class IfConditionAction < IfAction
564
+
565
+ def initialize(obj=nil)
566
+
567
+ @label = 'If '
568
+ super(obj)
569
+
570
+ end
561
571
 
562
572
  end
563
573
 
@@ -605,41 +615,15 @@ class ElseAction < Action
605
615
 
606
616
  end
607
617
 
608
- class ElseIfConditionAction < Action
618
+ class ElseIfConditionAction < IfAction
609
619
 
610
- def initialize(h={})
611
-
612
- options = {
613
- constraint_list: ''
614
- }
615
-
616
- super(options.merge h)
617
- @label = 'Else If '
620
+ def initialize(obj=nil)
618
621
 
619
- end
620
-
621
- def to_s(colour: false, indent: 0)
622
-
623
- h = @h.clone
624
- h.delete :macro
625
- @s = 'Else If '
626
- operator = @h[:is_or_condition] ? 'OR' : 'AND'
627
- constraints = @constraints.map \
628
- {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
629
-
630
- out = []
631
- out << "; %s" % @h[:comment] if @h[:comment]
632
- s = @s.lines.map {|x| (' ' * indent) + x}.join
633
- out << s + constraints
634
- out.join("\n")
622
+ @label = 'Else If '
623
+ super(obj)
635
624
 
636
- end
637
-
638
- def to_summary(colour: false)
639
- 'foo'
640
625
  end
641
-
642
-
626
+
643
627
  end
644
628
 
645
629
 
@@ -1722,6 +1706,49 @@ class ConfirmNextAction < Action
1722
1706
 
1723
1707
  end
1724
1708
 
1709
+ class DisableMacroAction < Action
1710
+
1711
+ def initialize(obj=nil)
1712
+
1713
+ h = if obj.is_a? Hash then
1714
+
1715
+ obj
1716
+
1717
+ elsif obj.is_a? Array
1718
+
1719
+ e, macro = obj
1720
+
1721
+ # find the macro guid for the given name
1722
+ name = e.text('item/description').to_s
1723
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1724
+
1725
+ if found then
1726
+ {macro_name: found.title, GUID: found.guid}
1727
+ else
1728
+ {macro_name: name}
1729
+ end
1730
+
1731
+ end
1732
+
1733
+ # state: 0 = enable, 1 = disable, 2 = toggle
1734
+
1735
+ options = {macro_name: "Change brightness", state: 1, GUID: nil}
1736
+ super(options.merge h)
1737
+
1738
+ end
1739
+
1740
+ def to_s(colour: false, indent: 0)
1741
+
1742
+ state = %w(Enable Disable Toggle)[@h[:state]]
1743
+ @s = state + ' macro'# + @h.inspect
1744
+ @s += "\n" + @h[:macro_name]
1745
+ super()
1746
+
1747
+ end
1748
+
1749
+ alias to_summary to_s
1750
+ end
1751
+
1725
1752
  # MacroDroid Specific
1726
1753
  #
1727
1754
  class ExportMacrosAction < Action
@@ -34,7 +34,9 @@ module ObjectX
34
34
  r = ap.find_action action
35
35
  puts 'r: ' + r.inspect if debug
36
36
 
37
- if r[1].any? then
37
+ nested = description.element('item/description')
38
+
39
+ if r[1].any? and not nested then
38
40
 
39
41
  macro.add r[0].new(r[1])
40
42
 
@@ -194,11 +196,11 @@ class MacroObject
194
196
  private
195
197
 
196
198
  def hashify(h)
197
- puts 'h: ' + h.inspect
199
+ #puts 'h: ' + h.inspect
198
200
  h2 = h.inject({}) do |r,x|
199
- puts 'x: ' + x.inspect #if $debug
201
+ #puts 'x: ' + x.inspect #if $debug
200
202
  key, value = x
201
- puts 'key: ' + key.inspect #if $debug
203
+ #puts 'key: ' + key.inspect #if $debug
202
204
  new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
203
205
  new_key = new_key.prepend 'm_' unless @list.include? new_key
204
206
  new_key = 'm_SIGUID' if new_key == 'm_siguid'
@@ -181,7 +181,29 @@ class ActionsNlp
181
181
 
182
182
  end
183
183
 
184
- def actions(params)
184
+ def actions(params)
185
+
186
+ # -- Conditions/Loops ---------------------------------------------
187
+ #
188
+
189
+ get /else if (.*)/i do
190
+ [ElseIfConditionAction, {}]
191
+ end
192
+
193
+ #e.g a: if Airplane mode enabled
194
+ #
195
+ get /if (.*)/i do
196
+ [IfConditionAction, {}]
197
+ end
198
+
199
+ get /else/i do
200
+ [ElseAction, {}]
201
+ end
202
+
203
+ get /End If/i do
204
+ [EndIfAction, {}]
205
+ end
206
+
185
207
 
186
208
  # -- Connectivity ------------------------------------------------------
187
209
 
@@ -195,7 +217,7 @@ class ActionsNlp
195
217
  end
196
218
 
197
219
  # e.g. message popup: hello world!
198
- get /^message popup: (.*)/i do |msg|
220
+ get /^(?:message popup|popup message): (.*)/i do |msg|
199
221
  [ToastAction, {msg: msg}]
200
222
  end
201
223
 
@@ -357,22 +379,15 @@ class ActionsNlp
357
379
  [KeepAwakeAction, {enabled: false, screen_option: 0}]
358
380
  end
359
381
 
360
- #e.g a: if Airplane mode enabled
361
- #
362
- get /if (.*)/i do
363
- [IfConditionAction, {}]
364
- end
365
-
366
- get /else/i do
367
- [ElseAction, {}]
368
- end
369
-
370
- get /End If/i do
371
- [EndIfAction, {}]
372
- end
373
382
 
374
383
  # -- MacroDroid Specific ------------------------------------------------
375
384
  #
385
+
386
+ get /^((?:En|Dis)able) Macro$/i do |rawstate|
387
+ state = %w(enable disable toggle).index(rawstate.downcase)
388
+ [DisableMacroAction, {state: state}]
389
+ end
390
+
376
391
  get /^Set Variable$/i do
377
392
  [SetVariableAction, {}]
378
393
  end
@@ -421,7 +436,7 @@ class ConstraintsNlp
421
436
 
422
437
  # -- MacroDroid specific -----------------------------------------------------------------------
423
438
 
424
- get /^(\w+) (=) (\[?\w+\]?)/i do |loperand, operator, roperand|
439
+ get /^(\w+) (=) (.*)/i do |loperand, operator, roperand|
425
440
 
426
441
  h = {
427
442
  loperand: loperand,
@@ -475,19 +490,20 @@ class Macro
475
490
  include ObjectX
476
491
 
477
492
  attr_reader :local_variables, :triggers, :actions, :constraints,
478
- :guid, :deviceid
493
+ :guid, :deviceid, :parent
479
494
  attr_accessor :title, :description, :remote_url, :picture_path
480
495
 
481
496
  def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil, \
482
- picture_path: nil, debug: false)
497
+ picture_path: nil, parent: nil, debug: false)
483
498
 
484
499
  @title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
485
- @remote_url, @picture_path = remote_url, picture_path
500
+ @remote_url, @picture_path, @parent = remote_url, picture_path, parent
486
501
 
487
502
  puts 'inside Macro#initialize' if @debug
488
503
 
489
504
  @local_variables, @triggers, @actions, @constraints = {}, [], [], []
490
505
  @h = {}
506
+ @guid = generate_guid()
491
507
 
492
508
  end
493
509
 
@@ -529,7 +545,7 @@ class Macro
529
545
  m_description: '',
530
546
  m_name: title(),
531
547
  m_excludeLog: false,
532
- m_GUID: guid(),
548
+ m_GUID: @guid,
533
549
  m_isOrCondition: false,
534
550
  m_enabled: true,
535
551
  m_descriptionOpen: false,
@@ -548,6 +564,7 @@ class Macro
548
564
  puts 'h:' + h.inspect
549
565
  end
550
566
 
567
+ @guid = h[:guid]
551
568
  @category = h[:category]
552
569
  @title = h[:name]
553
570
  @description = h[:description]
@@ -1036,8 +1053,8 @@ EOF
1036
1053
 
1037
1054
  private
1038
1055
 
1039
- def guid()
1040
- '-' + rand(1..9).to_s + 18.times.map { rand 9 }.join
1056
+ def generate_guid()
1057
+ ('-' + rand(1..9).to_s + 18.times.map { rand 9 }.join).to_i
1041
1058
  end
1042
1059
 
1043
1060
  def object(h={})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-macrodroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
36
36
  SBHno3GEuuD8ZWj24IMJpfbp
37
37
  -----END CERTIFICATE-----
38
- date: 2020-10-17 00:00:00.000000000 Z
38
+ date: 2020-10-18 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
metadata.gz.sig CHANGED
Binary file