raykit 0.0.309 → 0.0.310

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.
@@ -1,89 +1,89 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
3
+ require 'pathname'
4
4
 
5
5
  module Raykit
6
6
  # Provides functionality related to the development environment
7
7
  class Environment
8
8
  # Normalize a directory or filename to use forward slashes
9
9
  def self.normalize_path(name)
10
- name.gsub('\\', "/")
10
+ name.gsub('\\', '/')
11
11
  end
12
12
 
13
13
  # The root directory for the development environment.
14
14
  # May be set using the environment variable DEV_ROOT,
15
15
  # otherwise defaults to the user home directory
16
16
  def self.root_dir
17
- if ENV["DEV_ROOT"].nil?
17
+ if ENV['DEV_ROOT'].nil?
18
18
  Environment.home_dir
19
19
  else
20
- normalize_path(ENV["DEV_ROOT"])
20
+ normalize_path(ENV['DEV_ROOT'])
21
21
  end
22
22
  end
23
23
 
24
24
  # The user home directory
25
25
  def self.home_dir
26
- return normalize_path(ENV["USERPROFILE"]) if ENV.include?("USERPROFILE")
26
+ return normalize_path(ENV['USERPROFILE']) if ENV.include?('USERPROFILE')
27
27
 
28
- normalize_path(ENV["HOME"])
28
+ normalize_path(ENV['HOME'])
29
29
  end
30
30
 
31
31
  def self.log_dir
32
- get_dev_dir("log")
32
+ get_dev_dir('log')
33
33
  end
34
34
 
35
35
  # Get, and create if it does not exist, a specific development directory
36
36
  def self.get_dev_dir(name)
37
37
  dir = Pathname.new("#{Environment.root_dir}/#{name}")
38
38
  dir.mkpath
39
- dir.to_s.gsub("//", "/")
39
+ dir.to_s.gsub('//', '/')
40
40
  end
41
41
 
42
42
  def self.get_work_dir(url)
43
- "#{Raykit::Environment.get_dev_dir("work")}/#{url.gsub("://", "/").gsub(".git", "")}"
43
+ "#{Raykit::Environment.get_dev_dir('work')}/#{url.gsub('://', '/').gsub('.git', '')}"
44
44
  end
45
45
 
46
46
  # Get the size of a directory and its contents
47
47
  def self.get_dir_size(dir)
48
- Dir.glob(File.join(dir, "**", "*"))
48
+ Dir.glob(File.join(dir, '**', '*'))
49
49
  .map { |f| File.size(f) }
50
50
  .inject(:+)
51
51
  end
52
52
 
53
53
  def self.machine
54
- return ENV["COMPUTERNAME"] unless ENV["COMPUTERNAME"].nil?
54
+ return ENV['COMPUTERNAME'] unless ENV['COMPUTERNAME'].nil?
55
55
 
56
56
  machine = `hostname`
57
- machine = machine.split(".")[0] if machine.include?(".")
57
+ machine = machine.split('.')[0] if machine.include?('.')
58
58
  machine.strip
59
59
  end
60
60
 
61
61
  def self.user
62
- ENV["USERNAME"]
62
+ ENV['USERNAME']
63
63
  end
64
64
 
65
65
  def self.local_application_data
66
- "#{ENV["USERPROFILE"]}/AppData/Local".gsub('\\', "/")
66
+ "#{ENV['USERPROFILE']}/AppData/Local".gsub('\\', '/')
67
67
  end
68
68
 
69
69
  def self.admin?
70
70
  rights = `whoami /priv`
71
- rights.include?("SeCreateGlobalPrivilege")
71
+ rights.include?('SeCreateGlobalPrivilege')
72
72
  end
73
73
 
74
74
  def self.which(name)
75
75
  return name if File.exist?(name)
76
76
 
77
- ["", ".exe", ".bat", ".cmd"].each do |ext|
77
+ ['', '.exe', '.bat', '.cmd'].each do |ext|
78
78
  aname = name + ext
79
79
  return aname if File.exist?(aname)
80
80
 
81
- ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
82
- apath = "#{path.gsub('\\', "/")}/#{aname}".gsub("//", "/")
81
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
82
+ apath = "#{path.gsub('\\', '/')}/#{aname}".gsub('//', '/')
83
83
  return apath if File.exist?(apath)
84
84
  end
85
85
  end
86
- ""
86
+ ''
87
87
  end
88
88
  end
89
89
  end
@@ -16,7 +16,7 @@ module Raykit
16
16
  def outstanding_commit?
17
17
  Dir.chdir(directory) do
18
18
  if user_can_commit
19
- return !`git status`.include?("nothing to commit,")
19
+ return !`git status`.include?('nothing to commit,')
20
20
  else
21
21
  return false
22
22
  end
@@ -26,7 +26,7 @@ module Raykit
26
26
  def detached?
27
27
  Dir.chdir(directory) do
28
28
  status = `git status`.strip
29
- if status.include?("detached")
29
+ if status.include?('detached')
30
30
  true
31
31
  else
32
32
  false
@@ -38,43 +38,43 @@ module Raykit
38
38
  Dir.chdir(directory) do
39
39
  diff = `git diff`.strip
40
40
  status = `git status`.strip
41
- PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
41
+ PROJECT.run('git pull', false) if diff.length.zero? && status.include?('nothing to commit')
42
42
  end
43
43
  end
44
44
 
45
45
  def rake(task)
46
46
  unless Dir.exist?(@directory)
47
- puts "directory not found."
47
+ puts 'directory not found.'
48
48
  return 1
49
49
  end
50
50
  debug = false
51
- sub_dir = "work"
52
- sub_dir = "make" if @directory.include?("/make/")
53
- rake_log = repository.get_dev_dir("log") + "/#{sub_dir}.rake.#{task}.json"
51
+ sub_dir = 'work'
52
+ sub_dir = 'make' if @directory.include?('/make/')
53
+ rake_log = repository.get_dev_dir('log') + "/#{sub_dir}.rake.#{task}.json"
54
54
 
55
55
  puts "log filename #{rake_log}" if debug
56
56
  if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
57
- puts "using logged data" if debug
57
+ puts 'using logged data' if debug
58
58
  cmd = Raykit::Command.parse(File.read(rake_log))
59
59
  cmd.summary
60
60
  return
61
61
  end
62
62
 
63
63
  Dir.chdir(@directory) do
64
- if File.exist?("rakefile.rb")
64
+ if File.exist?('rakefile.rb')
65
65
  cmd = Raykit::Command.new("rake #{task}")
66
66
  cmd.summary
67
67
  FileUtils.mkdir_p(File.dirname(rake_log))
68
- File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
68
+ File.open(rake_log, 'w') { |f| f.write(JSON.generate(cmd.to_hash)) }
69
69
  else
70
- puts "rakefile.rb not found"
70
+ puts 'rakefile.rb not found'
71
71
  end
72
72
  end
73
73
  end
74
74
 
75
75
  def last_modified_time
76
76
  Dir.chdir(@directory) do
77
- File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
77
+ File.mtime(Dir.glob('**/*.*').select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
78
78
  end
79
79
  end
80
80
 
@@ -83,15 +83,24 @@ module Raykit
83
83
  Dir.chdir(directory) do
84
84
  return `git describe --abbrev=0`.strip
85
85
  end
86
- ""
86
+ ''
87
87
  end
88
88
 
89
89
  def get_tag_commit_id(name)
90
90
  cmd = Raykit::Command.new("git rev-parse \"#{name}\"", 0, nil, false)
91
- if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
91
+ if !cmd.output.include?('fatal') && !cmd.error.include?('fatal')
92
92
  cmd.output.strip
93
93
  else
94
- ""
94
+ ''
95
+ end
96
+ end
97
+
98
+ def has_tag(name)
99
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"", 0, nil, false)
100
+ if !cmd.output.include?('fatal') && !cmd.error.include?('fatal')
101
+ true
102
+ else
103
+ false
95
104
  end
96
105
  end
97
106
 
@@ -124,7 +133,7 @@ module Raykit
124
133
  scan = `git branch`.scan(/\*\s([\w.-]+)/)
125
134
  return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
126
135
  end
127
- "master"
136
+ 'master'
128
137
  end
129
138
 
130
139
  def repository
@@ -135,10 +144,10 @@ module Raykit
135
144
  def remote
136
145
  if Dir.exist?(directory)
137
146
  Dir.chdir(directory) do
138
- return Command.new("git config --get remote.origin.url").output.strip if Dir.exist?(".git")
147
+ return Command.new('git config --get remote.origin.url').output.strip if Dir.exist?('.git')
139
148
  end
140
149
  end
141
- ""
150
+ ''
142
151
  end
143
152
  end
144
153
  end
@@ -6,7 +6,6 @@ module Raykit
6
6
  class Files
7
7
  @url
8
8
  @commit_id
9
-
10
9
  def initialize(url, commit_id)
11
10
  @url = url
12
11
  @commit_id = commit_id
@@ -19,7 +18,7 @@ module Raykit
19
18
  def get(name)
20
19
  puts "commit_path(): #{commit_path}"
21
20
  unless Dir.exist?(commit_path)
22
- puts "cloning commit path..."
21
+ puts 'cloning commit path...'
23
22
  clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
24
23
  puts clone.output
25
24
  puts clone.error
@@ -30,12 +29,12 @@ module Raykit
30
29
 
31
30
  return filename(name) if File.exist?(filename(name))
32
31
 
33
- ""
32
+ ''
34
33
  end
35
34
 
36
35
  def commit_path
37
- Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
38
- ".") + File::SEPARATOR + @commit_id
36
+ Dir.tmpdir + File::SEPARATOR + 'Raykit.Git.Files' + File::SEPARATOR + @url.gsub('://',
37
+ '.') + File::SEPARATOR + @commit_id
39
38
  end
40
39
 
41
40
  def filename(name)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative("./directory")
3
+ require_relative('./directory')
4
4
 
5
5
  module Raykit
6
6
  module Git
@@ -24,7 +24,7 @@ module Raykit
24
24
  end
25
25
 
26
26
  def save(_filename)
27
- File.open(@filename, "w") do |f|
27
+ File.open(@filename, 'w') do |f|
28
28
  # json = JSON.pretty_generate(self)
29
29
  f.write(JSON.pretty_generate(self))
30
30
  # f.write(self.to_json)
@@ -32,12 +32,12 @@ module Raykit
32
32
  end
33
33
 
34
34
  def work_dir
35
- Environment.get_dev_dir("work")
35
+ Environment.get_dev_dir('work')
36
36
  end
37
37
 
38
38
  def is_remote_url(pattern)
39
- return true if pattern.include?("http://")
40
- return true if pattern.include?("https://")
39
+ return true if pattern.include?('http://')
40
+ return true if pattern.include?('https://')
41
41
 
42
42
  false
43
43
  end
@@ -60,8 +60,8 @@ module Raykit
60
60
  else
61
61
  git_dirs = []
62
62
  Dir.chdir(work_dir) do
63
- Dir.glob("**/.git") do |git_dir|
64
- dir = File.expand_path("..", git_dir)
63
+ Dir.glob('**/.git') do |git_dir|
64
+ dir = File.expand_path('..', git_dir)
65
65
  git_dirs.insert(0, dir) if dir.length.positive?
66
66
  end
67
67
  end
@@ -10,22 +10,22 @@ module Raykit
10
10
 
11
11
  def initialize(url)
12
12
  @url = url
13
- @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
14
- @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
13
+ @clone_directory = Raykit::Git::Directory.new(get_dev_dir('clone'))
14
+ @work_directory = Raykit::Git::Directory.new(get_dev_dir('work'))
15
15
  end
16
16
 
17
17
  def to_json(*_args)
18
- JSON.generate({ "url" => @url })
18
+ JSON.generate({ 'url' => @url })
19
19
  end
20
20
 
21
21
  def self.parse(json)
22
22
  hash = JSON.parse(json)
23
- Repository.new(hash["url"])
23
+ Repository.new(hash['url'])
24
24
  end
25
25
 
26
26
  # The relative path is a valid local path name derived from the url
27
27
  def relative_path
28
- @url.gsub("https://", "").gsub(".git", "").gsub("http://", "")
28
+ @url.gsub('https://', '').gsub('.git', '').gsub('http://', '')
29
29
  end
30
30
 
31
31
  def get_dev_dir(dir)
@@ -49,7 +49,7 @@ module Raykit
49
49
  if Dir.exist?(local_clone_directory)
50
50
  Dir.chdir(local_clone_directory) do
51
51
  `git branch`.split('\n').each do |line|
52
- branch = line.gsub("*", "").strip
52
+ branch = line.gsub('*', '').strip
53
53
  results.insert(-1, branch) if branch.length.positive?
54
54
  end
55
55
  end
@@ -64,24 +64,24 @@ module Raykit
64
64
  scan = text.scan(/commit (\w+)\s/)
65
65
  return scan[0][0].to_s
66
66
  end
67
- ""
67
+ ''
68
68
  end
69
69
 
70
70
  # The latest tag for a branch of the repository
71
71
  def latest_tag(branch)
72
72
  return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
73
73
 
74
- ""
74
+ ''
75
75
  end
76
76
 
77
77
  private def local_clone_directory
78
- clone_dir = "#{Environment.get_dev_dir("clone")}/#{relative_path}"
78
+ clone_dir = "#{Environment.get_dev_dir('clone')}/#{relative_path}"
79
79
  end
80
80
 
81
81
  private def update_local_clone_directory
82
82
  if Dir.exist?(local_clone_directory)
83
83
  Dir.chdir(local_clone_directory) do
84
- Raykit::Command.new("git pull")
84
+ Raykit::Command.new('git pull')
85
85
  # t = `git pull`
86
86
  end
87
87
  else
data/lib/raykit/log.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
-
3
+ require 'json'
5
4
  module Raykit
6
5
  class Log < Hash
7
6
  @filename
8
-
9
7
  def initialize(filename)
10
8
  @filename = filename
11
9
  dir = File.dirname(@filename)
@@ -22,21 +20,21 @@ module Raykit
22
20
  end
23
21
 
24
22
  def save
25
- File.open(@filename, "w") { |f| f.write(JSON.generate(self)) }
23
+ File.open(@filename, 'w') { |f| f.write(JSON.generate(self)) }
26
24
  end
27
25
 
28
26
  def update_command_time(command, timestamp)
29
27
  command_times = {}
30
- command_times = self["command_times"] if key?("command_times")
28
+ command_times = self['command_times'] if key?('command_times')
31
29
  command_times.delete(command) if command_times.key?(command)
32
30
  command_times[command] = timestamp.iso8601
33
- self["command_times"] = command_times
31
+ self['command_times'] = command_times
34
32
  save
35
33
  end
36
34
 
37
35
  def get_command_time(command)
38
- if key?("command_times")
39
- command_times = self["command_times"]
36
+ if key?('command_times')
37
+ command_times = self['command_times']
40
38
  return DateTime.parse(command_times[command]) if command_times.key?(command)
41
39
  end
42
40
  nil
@@ -1,27 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
-
3
+ require 'json'
5
4
  module Raykit
6
5
  # :verbose, :debug, :information, :error, :fatal
7
6
  class LogEvent < Hash
8
7
  def initialize(level, messageTemplate, properties)
9
- self["Timestamp"] = DateTime.now.iso8601
10
- self["Level"] = level
11
- self["Message"] = messageTemplate
12
- self["MessageTemplate"] = messageTemplate
13
- properties["MachineName"] = Raykit::Environment.machine unless properties.key?("MachineName")
14
- properties["UserName"] = Raykit::Environment.user unless properties.key?("UserName")
15
- properties["RakeDirectory"] = ::Rake.application.original_dir
16
- self["Properties"] = properties
8
+ self['Timestamp'] = DateTime.now.iso8601
9
+ self['Level'] = level
10
+ self['Message'] = messageTemplate
11
+ self['MessageTemplate'] = messageTemplate
12
+ properties['MachineName'] = Raykit::Environment.machine unless properties.key?('MachineName')
13
+ properties['UserName'] = Raykit::Environment.user unless properties.key?('UserName')
14
+ properties['RakeDirectory'] = ::Rake.application.original_dir
15
+ self['Properties'] = properties
17
16
  end
18
17
 
19
18
  def to_seq
20
19
  # puts '---to_seq---'
21
20
  # puts self['Message']
22
- unless ENV["SEQ_SERVER"].nil?
23
- cmd_str = "seqcli log -m \"#{self["Message"].gsub('"', "")}\" -l #{self["Level"]} -s #{ENV["SEQ_SERVER"]}"
24
- self["Properties"].each do |k, v|
21
+ unless ENV['SEQ_SERVER'].nil?
22
+ cmd_str = "seqcli log -m \"#{self['Message'].gsub('"', '')}\" -l #{self['Level']} -s #{ENV['SEQ_SERVER']}"
23
+ self['Properties'].each do |k, v|
25
24
  cmd_str += " -p \"#{k}=#{v}\""
26
25
  end
27
26
  # puts '---executing---'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
- require "logger"
3
+ require 'json'
4
+ require 'logger'
5
5
 
6
6
  module Raykit
7
7
  class Logging
@@ -18,15 +18,15 @@ module Raykit
18
18
  end
19
19
 
20
20
  def set_severity_as_string(severity)
21
- @severity = Logger::Severity::DEBUG if severity == "debug"
22
- @severity = Logger::Severity::INFO if severity == "info"
23
- @severity = Logger::Severity::WARN if severity == "warn"
24
- @severity = Logger::Severity::ERROR if severity == "error"
21
+ @severity = Logger::Severity::DEBUG if severity == 'debug'
22
+ @severity = Logger::Severity::INFO if severity == 'info'
23
+ @severity = Logger::Severity::WARN if severity == 'warn'
24
+ @severity = Logger::Severity::ERROR if severity == 'error'
25
25
  end
26
26
 
27
27
  def get_logger(context)
28
28
  unless loggers.key?(context)
29
- Dir.chdir(Environment.get_dev_dir("log")) do
29
+ Dir.chdir(Environment.get_dev_dir('log')) do
30
30
  # start the log over whenever the log exceeds 100 megabytes in size
31
31
  loggers[context] = Logger.new("#{context}.log", 0, 100 * 1024 * 1024)
32
32
  end
@@ -3,20 +3,14 @@
3
3
  module Raykit
4
4
  class MsBuild
5
5
  def self.msbuild_path
6
- ["2022/Community/MSBuild/Current/Bin",
7
- "2019/Enterprise/MSBuild/Current/Bin",
8
- "2019/Professional/MSBuild/Current/Bin",
9
- "2019/Community/MSBuild/Current/Bin",
10
- "2017/BuildTools/MSBuild/15.0/Bin"].each do |relative_path|
11
- ["C:/Program Files/Microsoft Visual Studio/",
12
- "C:/Program Files (x86)/Microsoft Visual Studio/"].each do |prog_path|
13
- path = "#{prog_path}#{relative_path}"
14
- return path if Dir.exist?(path)
15
- end
16
- #path = "C:/Program Files (x86)/Microsoft Visual Studio/#{relative_path}"
17
- #return path if Dir.exist?(path)
6
+ ['2019/Enterprise/MSBuild/Current/Bin',
7
+ '2019/Professional/MSBuild/Current/Bin',
8
+ '2019/Community/MSBuild/Current/Bin',
9
+ '2017/BuildTools/MSBuild/15.0/Bin'].each do |relative_path|
10
+ path = "C:/Program Files (x86)/Microsoft Visual Studio/#{relative_path}"
11
+ return path if Dir.exist?(path)
18
12
  end
19
- ""
13
+ ''
20
14
  end
21
15
  end
22
16
  end