ruby-macrodroid 0.8.4 → 0.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e37f4ab29dcdcd4c347d15cefb087663679ec7859094f94dc50a39dd66799b85
4
- data.tar.gz: 26896b3fdea9e794467abdd41e4898d80ff240c9464316e09513db2d6b7956f2
3
+ metadata.gz: b820bff4fbf40858e39fb86dcf5cca3c511fec1285c6ef642469f0222ae7858e
4
+ data.tar.gz: abea1d50f38024c84dcca885487915a6f878427d0f5504c98ce818976231eb8c
5
5
  SHA512:
6
- metadata.gz: 3f7da291c314b2cd03ac2704ea3c1fbd2380f7a85389747b559cc1e5106499f71d120ba935ee73f6078978744abd1f20d16cad941bbac597746769e83c2954df
7
- data.tar.gz: 8bae5ed2da5e357335f9720746b5bca7358e0a134fc8cf64b8fd5fcc8fc780137d2d4ae20baf2568f8771a467c283d16dc6fd0fa3dddf4cb7cdcd3927c4ff0d7
6
+ metadata.gz: 6f64c76e11c1b581e8e86bbddbcfec090e90c5673ecc72d64deeb542452a870252dc30a066f699f5ea1b682147f241d2518341b34cfefe6d5e70aacbe4cf22e6
7
+ data.tar.gz: b3e6b695cca7a0c10c14b4bde58c927504cc2f5e722ba2ca83fb9c905d51369b1a0912134a523ae4a3f6546dbf9e826585fddb6a56fa02799e2d72fcbd37a6d0
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,12 +7,7 @@
7
7
  # ## Nlp classes
8
8
  #
9
9
  # TriggersNlp ActionsNlp ConstraintsNlp
10
- #
11
- #
12
- # ## Macro class
13
- #
14
- # Macro
15
- #
10
+ #
16
11
  #
17
12
  # ## Error class
18
13
  #
@@ -31,11 +26,12 @@
31
26
  #
32
27
 
33
28
 
29
+
34
30
  require 'yaml'
35
31
  require 'rowx'
36
32
  require 'uuid'
37
- require 'glw'
38
- require 'geozone'
33
+ #require 'glw'
34
+ #require 'geozone'
39
35
  require 'geocoder'
40
36
  require 'subunit'
41
37
  require 'rxfhelper'
@@ -253,6 +249,11 @@ class ActionsNlp
253
249
  [KeepAwakeAction, {enabled: false, screen_option: 0}]
254
250
  end
255
251
 
252
+ #a: Disable Keep Awake
253
+ #
254
+ get /if (.*)/i do
255
+ [IfConditionAction, {}]
256
+ end
256
257
 
257
258
  end
258
259
 
@@ -340,464 +341,6 @@ end
340
341
 
341
342
 
342
343
 
343
- class Macro
344
- using ColouredText
345
- using Params
346
-
347
- attr_reader :local_variables, :triggers, :actions, :constraints,
348
- :guid, :deviceid
349
- attr_accessor :title, :description
350
-
351
- def initialize(name=nil, geofences: nil, deviceid: nil, debug: false)
352
-
353
- @title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
354
-
355
- puts 'inside Macro#initialize' if @debug
356
-
357
- @local_variables, @triggers, @actions, @constraints = [], [], [], []
358
- @h = {}
359
-
360
- end
361
-
362
- def add(obj)
363
-
364
- if obj.kind_of? Trigger then
365
-
366
- puts 'trigger found' if @debug
367
- @triggers << obj
368
-
369
- elsif obj.kind_of? Action
370
-
371
- puts 'action found' if @debug
372
- @actions << obj
373
-
374
- elsif obj.kind_of? Constraint
375
-
376
- puts 'constraint found' if @debug
377
- @constraints << obj
378
-
379
- end
380
-
381
- end
382
-
383
- def to_h()
384
-
385
- h = {
386
- local_variables: @local_variables,
387
- m_trigger_list: @triggers.map(&:to_h),
388
- m_action_list: @actions.map(&:to_h),
389
- m_constraint_list: @constraints.map(&:to_h),
390
- m_description: '',
391
- m_name: title(),
392
- m_excludeLog: false,
393
- m_GUID: guid(),
394
- m_isOrCondition: false,
395
- m_enabled: false,
396
- m_descriptionOpen: false,
397
- m_headingColor: 0
398
- }
399
-
400
- puts 'h: ' + h.inspect if @debug
401
-
402
- @h.merge(h)
403
- end
404
-
405
- def import_h(h)
406
-
407
- if @debug then
408
- puts 'inside import_h'
409
- puts 'h:' + h.inspect
410
- end
411
-
412
- @title = h[:name]
413
- @description = h[:description]
414
-
415
- # fetch the local variables
416
- if h[:local_variables].any? and h[:local_variables].first.any? then
417
-
418
- @local_variables = h[:local_variables].map do |var|
419
-
420
- val = case var[:type]
421
- when 0 # boolean
422
- var[:boolean_value]
423
- when 1 # integer
424
- var[:int_value]
425
- when 2 # string
426
- var[:string_value]
427
- when 3 # decimal
428
- var[:decimal_Value]
429
- end
430
-
431
- [var[:name], val]
432
-
433
- end.to_h
434
- end
435
-
436
- # fetch the triggers
437
- @triggers = h[:trigger_list].map do |trigger|
438
- puts 'trigger: ' + trigger.inspect
439
- #exit
440
- object(trigger.to_snake_case)
441
-
442
- end
443
-
444
- @actions = h[:action_list].map do |action|
445
- object(action.to_snake_case)
446
- end
447
-
448
- # fetch the constraints
449
- @constraints = h[:constraint_list].map do |constraint|
450
- object(constraint.to_snake_case)
451
- end
452
-
453
- @h = h
454
-
455
- %i(local_variables m_trigger_list m_action_list m_constraint_list)\
456
- .each {|x| @h[x] = [] }
457
-
458
- @h
459
-
460
- end
461
-
462
- def import_xml(node)
463
-
464
- if @debug then
465
- puts 'inside Macro#import_xml'
466
- puts 'node: ' + node.xml.inspect
467
- end
468
-
469
- if node.element('triggers') then
470
-
471
- # level 2
472
-
473
- @title = node.attributes[:name]
474
- @description = node.attributes[:description]
475
-
476
-
477
- # get all the triggers
478
- @triggers = node.xpath('triggers/*').map do |e|
479
-
480
- puts 'e.name: ' + e.name.inspect if @debug
481
- {timer: TimerTrigger}[e.name.to_sym].new(e.attributes.to_h)
482
-
483
- end
484
-
485
- # get all the actions
486
- @actions = node.xpath('actions/*').map do |e|
487
-
488
- if e.name == 'notification' then
489
-
490
- case e.attributes[:type].to_sym
491
- when :popup
492
- e.attributes.delete :type
493
- ToastAction.new e.attributes.to_h
494
- end
495
-
496
- end
497
-
498
- end
499
-
500
- # get all the constraints
501
- @constraints = node.xpath('constraints/*').map do |e|
502
-
503
- puts 'e.name: ' + e.name.inspect if @debug
504
- {airplanemode: AirplaneModeConstraint}[e.name.to_sym].new(e.attributes.to_h)
505
-
506
- end
507
-
508
- else
509
-
510
- # Level 1
511
-
512
- puts 'import_xml: inside level 1' if @debug
513
-
514
- @title = node.text('macro') || node.attributes[:name]
515
-
516
- #@description = node.attributes[:description]
517
-
518
- tp = TriggersNlp.new
519
-
520
- @triggers = node.xpath('trigger').map do |e|
521
-
522
- r = tp.find_trigger e.text
523
-
524
- puts 'found trigger ' + r.inspect if @debug
525
-
526
- if r then
527
- if r[0] == GeofenceTrigger then
528
- GeofenceTrigger.new(r[1], geofences: @geofences)
529
- else
530
- r[0].new(r[1])
531
- end
532
- end
533
-
534
- end
535
-
536
- ap = ActionsNlp.new
537
-
538
- @actions = node.xpath('action').map do |e|
539
-
540
- puts 'action e: ' + e.xml.inspect if @debug
541
- puts 'e.text ' + e.text if @debug
542
- r = ap.find_action e.text.strip
543
- puts 'found action ' + r.inspect if @debug
544
-
545
- if r then
546
-
547
- loose = e.element('item/description/text()')
548
-
549
- raw_attributes = if loose then
550
-
551
- puts 'do something ' + loose.to_s
552
- loose.to_s
553
-
554
- else
555
-
556
- a = e.xpath('item/*')
557
-
558
- h = if a.any? then
559
- a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
560
- else
561
- {}
562
- end
563
-
564
- r[1].merge(h)
565
-
566
- end
567
- r[0].new(raw_attributes)
568
- end
569
-
570
- end
571
-
572
- cp = ConstraintsNlp.new
573
-
574
- @constraints = node.xpath('constraint').map do |e|
575
-
576
- r = cp.find_constraint e.text
577
- puts 'found constraint ' + r.inspect if @debug
578
-
579
- if r then
580
- r[0].new(r[1])
581
- end
582
-
583
- end
584
-
585
- end
586
-
587
- self
588
-
589
- end
590
-
591
- def match?(triggerx, detail={time: $env[:time]}, model=nil )
592
-
593
- if @triggers.any? {|x| x.type == triggerx and x.match?(detail, model) } then
594
-
595
- if @debug then
596
- puts 'checking constraints ...'
597
- puts '@constraints: ' + @constraints.inspect
598
- end
599
-
600
- if @constraints.all? {|x| x.match?($env.merge(detail), model) } then
601
-
602
- true
603
-
604
- else
605
-
606
- return false
607
-
608
- end
609
-
610
- end
611
-
612
- end
613
-
614
- # invokes the actions
615
- #
616
- def run()
617
- @actions.map(&:invoke)
618
- end
619
-
620
- # prepares the environment in order for triggers to test fire successfully
621
- # Used for testing
622
- #
623
- def set_env()
624
- @triggers.each(&:set_env)
625
- end
626
-
627
- def to_pc()
628
-
629
- heading = '# ' + @title
630
- heading += '\n# ' + @description if @description
631
- condition = @triggers.first.to_pc
632
- actions = @actions.map(&:to_pc).join("\n")
633
-
634
- <<EOF
635
- #{heading}
636
-
637
- if #{condition} then
638
- #{actions}
639
- end
640
- EOF
641
- end
642
-
643
- def to_s(colour: false)
644
-
645
- indent = 0
646
- actions = @actions.map do |x|
647
-
648
- s = x.to_s(colour: colour)
649
- if s.lines.length > 1 then
650
- lines = s.lines
651
- s = lines[0] + lines[1..-1].map {|x| x.prepend (' ' * indent) }.join
652
- end
653
-
654
- r = if indent <= 0 then
655
-
656
- if colour then
657
- "a".bg_blue.gray.bold + ": %s" % s
658
- else
659
- "a: %s" % s
660
- end
661
-
662
- elsif indent > 0
663
-
664
- if s =~ /^Else/ then
665
- (' ' * (indent-1)) + "%s" % s
666
- elsif s =~ /^End/
667
- indent -= 1
668
- (' ' * indent) + "%s" % s
669
- else
670
- (' ' * indent) + "%s" % s
671
- end
672
-
673
- end
674
-
675
- if s =~ /^(?:If|WHILE \/ DO)/i then
676
-
677
- if indent < 1 then
678
-
679
- r = if colour then
680
- "a".bg_blue.gray.bold + ":\n %s" % s
681
- else
682
- "a:\n %s" % s
683
- end
684
-
685
- indent += 1
686
- else
687
- r = (' ' * indent) + "%s" % s
688
- end
689
-
690
- indent += 1
691
- end
692
-
693
- r
694
-
695
- end.join("\n")
696
-
697
- a = [
698
- (colour ? "m".bg_cyan.gray.bold : 'm') + ': ' + @title
699
- ]
700
-
701
- if @description and @description.length >= 1 then
702
- a << (colour ? "d".bg_gray.gray.bold : 'd') + ': ' \
703
- + @description.gsub(/\n/,"\n ")
704
- end
705
-
706
- if @local_variables.length >= 1 then
707
-
708
- vars = @local_variables.map do |k,v|
709
- label = colour ? 'v'.bg_magenta : 'v'
710
- label += ': '
711
- label + "%s: %s" % [k,v]
712
- end
713
-
714
- a << vars.join("\n")
715
- end
716
-
717
- a << @triggers.map {|x| (colour ? "t".bg_red.gray.bold : 't') \
718
- + ": %s" % x}.join("\n")
719
- a << actions
720
-
721
-
722
- if @constraints.any? then
723
- a << @constraints.map do |x|
724
- (colour ? "c".bg_green.gray.bold : 'c') + ": %s" % x
725
- end.join("\n")
726
- end
727
-
728
-
729
-
730
-
731
-
732
- a.join("\n") + "\n"
733
-
734
- end
735
-
736
- def to_summary(colour: false)
737
-
738
- if colour then
739
-
740
- a = [
741
- 'm'.bg_cyan.gray.bold + ': ' + @title,
742
- 't'.bg_red.gray.bold + ': ' + @triggers.map \
743
- {|x| x.to_summary(colour: false)}.join(", "),
744
- 'a'.bg_blue.gray.bold + ': ' + @actions.map \
745
- {|x| x.to_summary(colour: false)}.join(", ")
746
- ]
747
-
748
- if @constraints.any? then
749
- a << 'c'.bg_green.gray.bold + ': ' + @constraints.map \
750
- {|x| x.to_summary(colour: false)}.join(", ")
751
- end
752
-
753
- else
754
-
755
- a = [
756
- 'm: ' + @title,
757
- 't: ' + @triggers.map {|x| x.to_summary(colour: false)}.join(", "),
758
- 'a: ' + @actions.map {|x| x.to_summary(colour: false)}.join(", ")
759
- ]
760
-
761
- if @constraints.any? then
762
- a << 'c: ' + @constraints.map \
763
- {|x| x.to_summary(colour: false)}.join(", ")
764
- end
765
- end
766
-
767
-
768
-
769
- a.join("\n") + "\n"
770
-
771
- end
772
-
773
- private
774
-
775
- def guid()
776
- '-' + rand(1..9).to_s + 18.times.map { rand 9 }.join
777
- end
778
-
779
- def object(h={})
780
-
781
- puts ('inside object h:' + h.inspect).debug if @debug
782
- klass = Object.const_get h[:class_type]
783
- puts klass.inspect.highlight if $debug
784
-
785
- if klass == GeofenceTrigger then
786
- puts 'GeofenceTrigger found'.highlight if $debug
787
- GeofenceTrigger.new(h, geofences: @geofences)
788
- else
789
- puts 'before klass'
790
- h2 = h.merge( macro: self)
791
- puts 'h2: ' + h2.inspect
792
- r = klass.new h2
793
-
794
- r
795
-
796
- end
797
-
798
- end
799
-
800
- end
801
344
 
802
345
 
803
346
  class MacroDroidError < Exception
@@ -828,6 +371,7 @@ class MacroDroid
828
371
  if s[0] == '{' then
829
372
 
830
373
  import_json(s)
374
+ puts 'after import_json' if @debug
831
375
 
832
376
  elsif s[0] == '<'
833
377
 
@@ -859,6 +403,7 @@ class MacroDroid
859
403
  end
860
404
 
861
405
  xml = RowX.new(raw_macros).to_xml
406
+ puts 'xml: ' + xml if @debug
862
407
  import_rowxml(xml)
863
408
 
864
409
  elsif s =~ /^# /
@@ -920,7 +465,7 @@ class MacroDroid
920
465
  end
921
466
 
922
467
  alias to_json export_json
923
-
468
+
924
469
 
925
470
  def to_h()
926
471