evertils 0.3.7 → 0.3.8

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/bin/evertils +7 -38
  3. data/evertils.gemspec +1 -1
  4. data/lib/evertils/config.rb +55 -0
  5. data/lib/evertils/controller.rb +69 -0
  6. data/lib/{controllers → evertils/controllers}/convert.rb +1 -1
  7. data/lib/evertils/controllers/firstrun.rb +24 -0
  8. data/lib/{controllers → evertils/controllers}/generate.rb +11 -27
  9. data/lib/{controllers → evertils/controllers}/get.rb +3 -3
  10. data/lib/{controllers → evertils/controllers}/status.rb +2 -2
  11. data/lib/{helper.rb → evertils/helper.rb} +3 -3
  12. data/lib/{helpers → evertils/helpers}/api-enml-handler.rb +3 -10
  13. data/lib/{helpers → evertils/helpers}/evernote-markdown.rb +14 -14
  14. data/lib/{helpers → evertils/helpers}/formatting.rb +29 -27
  15. data/lib/evertils/request.rb +31 -0
  16. data/lib/evertils/router.rb +56 -0
  17. data/lib/{type.rb → evertils/type.rb} +8 -2
  18. data/lib/{types → evertils/types}/daily.rb +2 -5
  19. data/lib/{types → evertils/types}/monthly-task-summary.rb +2 -11
  20. data/lib/{types → evertils/types}/monthly.rb +3 -6
  21. data/lib/{types → evertils/types}/priority-queue.rb +3 -5
  22. data/lib/{types → evertils/types}/weekly.rb +4 -8
  23. data/lib/{utils.rb → evertils/utils.rb} +4 -4
  24. data/lib/evertils/version.rb +3 -0
  25. data/lib/evertils.rb +39 -0
  26. metadata +33 -34
  27. data/lib/command.rb +0 -179
  28. data/lib/config.rb +0 -65
  29. data/lib/controller.rb +0 -117
  30. data/lib/log.rb +0 -111
  31. data/lib/logs.rb +0 -34
  32. data/lib/request.rb +0 -23
  33. data/lib/router.rb +0 -67
  34. data/lib/version.rb +0 -3
  35. /data/lib/{configs → evertils/configs}/templates/daily.enml +0 -0
  36. /data/lib/{configs/templates/mts.enml → evertils/configs/templates/monthly-task-summaries.enml} +0 -0
  37. /data/lib/{configs → evertils/configs}/templates/monthly.enml +0 -0
  38. /data/lib/{configs → evertils/configs}/templates/pq.enml +0 -0
  39. /data/lib/{configs → evertils/configs}/templates/weekly.enml +0 -0
  40. /data/lib/{controllers → evertils/controllers}/new.rb +0 -0
  41. /data/lib/{helpers → evertils/helpers}/evernote-enml.rb +0 -0
  42. /data/lib/{helpers → evertils/helpers}/results.rb +0 -0
  43. /data/lib/{helpers → evertils/helpers}/time.rb +0 -0
  44. /data/lib/{kernel.rb → evertils/kernel.rb} +0 -0
data/lib/log.rb DELETED
@@ -1,111 +0,0 @@
1
- module Evertils
2
- class Log
3
- attr_accessor :path, :total_files_processed
4
- attr_reader :template
5
-
6
- def initialize(*args)
7
- if args.length == 0
8
- # default log
9
- @template = "#{Evertils::LOG_DIR}/%s"
10
- @path = sprintf(@template, "default.log")
11
- else
12
- @template = "#{Evertils::LOG_DIR}/%s/%s-%s.log"
13
-
14
- format(args)
15
- end
16
-
17
- @path
18
- end
19
-
20
- def stale?
21
- Time.now - last_write > 60
22
- end
23
-
24
- def exists?
25
- File.exist? @path
26
- end
27
-
28
- def delete
29
- if exists?
30
- File.delete @path
31
- end
32
-
33
- Notify.sinfo("Deleting truncated log file #{@path}")
34
- @path = nil
35
- end
36
-
37
- def num_lines
38
- File.foreach(@path).inject(0) {|c, line| c+1}
39
- end
40
-
41
- def faults
42
- matchdata = { :errors => 0, :warnings => 0, :total => 0 }
43
-
44
- begin
45
- case @log_type
46
- when :js
47
- last_line = IO.readlines(@path)[-5].chomp
48
- matches = last_line.match(/(\d+) example, (\d+) failure/)
49
-
50
- if matches
51
- matchdata[:errors] += matches[2].to_i
52
- end
53
- when :coffeelint
54
- total = 0
55
- File.foreach(@path) do |line|
56
- matches = line.match(/Lint\! » (\d+) errors and (\d+)/)
57
-
58
- if matches
59
- matchdata[:errors] += matches[1].to_i
60
- matchdata[:warnings] += matches[2].to_i
61
- end
62
- end
63
- when :ruby
64
- last_line = IO.readlines(@path)[-1].chomp
65
- matches = last_line.match(/(\d+) files inspected\, (\d+)/)
66
-
67
- if matches
68
- matchdata[:errors] += matches[2].to_i
69
- matchdata[:total] += matches[1].to_i
70
- end
71
- when :goliath
72
-
73
- else
74
- raise ArgumentError, "Unknown log type - #{log_type}"
75
- end
76
- rescue => e
77
- Notify.error(e.message)
78
- end
79
-
80
- matchdata
81
- end
82
-
83
- def to_s
84
- @path
85
- end
86
-
87
- private
88
- def format(args)
89
- @identifier = args[2]
90
-
91
- @path = sprintf(@template,
92
- @identifier,
93
- args[0],
94
- args[1].strftime('%Y-%m-%d-%T')
95
- )
96
-
97
- if !File.exists? @path
98
- Utils.generate_path(args[0], args[1].strftime('%Y-%m-%d-%T'), @identifier)
99
- end
100
-
101
- # create the log file, populate it with temporary data
102
- File.open(@path, 'w+') do |f|
103
- f.write("Command output will be logged below when it finishes running\n")
104
- end
105
- end
106
-
107
- def last_write
108
- File.mtime(@path)
109
- end
110
- end
111
- end
data/lib/logs.rb DELETED
@@ -1,34 +0,0 @@
1
- module Evertils
2
- class Logs
3
- MAX_LOGS_TO_STORE = 30
4
-
5
- @files = Dir["#{Evertils::LOG_DIR}/*/*.log"]
6
-
7
- def self.clean
8
- if @files.size > 0
9
- @files.each do |file|
10
- File.delete file if File.exist? file
11
- end
12
- Notify.info("Removed #{@files.size} old log files")
13
- end
14
- end
15
-
16
- def self.dirty?
17
- @files.size >= MAX_LOGS_TO_STORE
18
- end
19
-
20
- # Create a directory if required
21
- def self.mkdir(name)
22
- dir = "#{Evertils::LOG_DIR}/#{name.downcase}"
23
-
24
- if !Dir.exist? dir
25
- Dir.mkdir dir
26
- end
27
-
28
- # Create the default .gitignore
29
- File.open("#{dir}/.gitignore", "w+") do |file|
30
- file.write "# Ignore everything in this directory\n*\n# Except this file\n!.gitignore"
31
- end
32
- end
33
- end
34
- end
data/lib/request.rb DELETED
@@ -1,23 +0,0 @@
1
- module Evertils
2
- class Request
3
- attr_reader :controller, :command, :custom, :flags, :raw_flags
4
-
5
- def initialize
6
- @controller = nil
7
- @flags = ARGV.select { |f| f.start_with?('-') }.map { |f| f.split("=").map &:to_sym } || []
8
- @raw_flags = ARGV.select { |f| f.start_with?('-') } || []
9
-
10
- if ARGV.size > 0
11
- if !ARGV[0].start_with?('-')
12
- @controller = ARGV[0].to_sym rescue nil
13
- end
14
-
15
- @command = ARGV[1].to_sym rescue nil
16
-
17
- if ARGV.size > 2
18
- @custom = ARGV[2..ARGV.size].select { |p| !p.start_with?('-') }.map &:to_sym || []
19
- end
20
- end
21
- end
22
- end
23
- end
data/lib/router.rb DELETED
@@ -1,67 +0,0 @@
1
- module Evertils
2
- class Router
3
- def route
4
- pre_exec
5
-
6
- # Create object context and pass it the required command line arguments
7
- begin
8
- if !$request.controller.nil?
9
- controller = Evertils::Controller.const_get $request.controller.capitalize rescue false
10
-
11
- if !controller
12
- raise "Controller not found: #{$request.controller.capitalize}"
13
- end
14
-
15
- context = controller.new
16
-
17
- if context.can_exec? $request.controller, $request.command
18
- context.pre_exec
19
-
20
-
21
- if context.methods_require_internet.include? $request.command
22
- if !Utils.has_internet_connection?
23
- raise RuntimeError, "Command `#{Evertils::PACKAGE_NAME} #{$request.controller} #{$request.command}` requires a connection to the internet.\nPlease check your network configuration settings."
24
- end
25
- end
26
-
27
- # Run the controller
28
- # Call a default action for controllers which do not require a third
29
- # argument, i.e. evertils status
30
- if context.respond_to? :default
31
- context.default
32
- else
33
- context.exec
34
- end
35
-
36
- # Run cleanup commands
37
- context.post_exec
38
- end
39
- end
40
- rescue RuntimeError => e
41
- Notify.error("#{e.to_s}", {})
42
- rescue NameError => e
43
- Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}", {})
44
- end
45
- end
46
-
47
- def pre_exec
48
- # Populate request params
49
- $request = Request.new
50
-
51
- # include the controller
52
- if File.exists? "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
53
- require "#{Evertils::CONTROLLER_DIR}#{$request.controller}.rb"
54
- end
55
-
56
- # include helpers
57
- if File.exists? "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
58
- require "#{Evertils::HELPER_DIR}#{$request.controller}.rb"
59
- end
60
-
61
- # include models
62
- if File.exists? "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
63
- require "#{Evertils::MODEL_DIR}#{$request.controller}.rb"
64
- end
65
- end
66
- end
67
- end
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Evertils
2
- VERSION = '0.3.7'.freeze
3
- end
File without changes
File without changes
File without changes
File without changes
File without changes