raykit 0.0.304 → 0.0.305

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,109 +1,106 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Raykit
2
- module Git
3
- # Functionality to manage a remote git repository
4
- class Repository
5
- # The url of the remote repository
6
- attr_accessor :url
7
- attr_accessor :clone_directory
8
- attr_accessor :work_directory
4
+ module Git
5
+ # Functionality to manage a remote git repository
6
+ class Repository
7
+ # The url of the remote repository
8
+ attr_accessor :url
9
+ attr_accessor :clone_directory, :work_directory
9
10
 
10
- def initialize(url)
11
- @url=url
12
- @clone_directory = Raykit::Git::Directory.new(get_dev_dir('clone'))
13
- @work_directory = Raykit::Git::Directory.new(get_dev_dir('work'))
14
- end
11
+ def initialize(url)
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"))
15
+ end
15
16
 
16
- def to_json
17
- JSON.generate({"url" => @url})
18
- end
17
+ def to_json(*_args)
18
+ JSON.generate({ "url" => @url })
19
+ end
19
20
 
20
- def self.parse(json)
21
- hash=JSON.parse(json)
22
- repo=Repository.new(hash["url"])
23
- repo
24
- end
21
+ def self.parse(json)
22
+ hash = JSON.parse(json)
23
+ Repository.new(hash["url"])
24
+ end
25
25
 
26
- # The relative path is a valid local path name derived from the url
27
- def relative_path
28
- @url.gsub('https://','').gsub('.git','').gsub('http://','')
29
- end
26
+ # The relative path is a valid local path name derived from the url
27
+ def relative_path
28
+ @url.gsub("https://", "").gsub(".git", "").gsub("http://", "")
29
+ end
30
30
 
31
- def get_dev_dir(dir)
32
- dev_dir=Environment::get_dev_dir(dir)
33
- return "#{dev_dir}/#{relative_path}"
34
- end
31
+ def get_dev_dir(dir)
32
+ dev_dir = Environment.get_dev_dir(dir)
33
+ "#{dev_dir}/#{relative_path}"
34
+ end
35
35
 
36
- # Clone the repository to a specific directory
37
- def clone(directory,depth=0)
38
- if(depth == 0)
39
- PROJECT.run("git clone #{@url} #{directory}")
40
- else
41
- PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
42
- end
43
- end
36
+ # Clone the repository to a specific directory
37
+ def clone(directory, depth = 0)
38
+ if depth.zero?
39
+ PROJECT.run("git clone #{@url} #{directory}")
40
+ else
41
+ PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
42
+ end
43
+ end
44
44
 
45
- # The branches for the git repository
46
- def branches
47
- results = Array.new
48
- update_local_clone_directory
49
- if(Dir.exist?(local_clone_directory))
50
- Dir.chdir(local_clone_directory) do
51
- `git branch`.split('\n').each{|line|
52
- branch = line.gsub('*','').strip
53
- results.insert(-1,branch) if(branch.length > 0)
54
- }
55
- end
56
- end
57
- results
45
+ # The branches for the git repository
46
+ def branches
47
+ results = []
48
+ update_local_clone_directory
49
+ if Dir.exist?(local_clone_directory)
50
+ Dir.chdir(local_clone_directory) do
51
+ `git branch`.split('\n').each do |line|
52
+ branch = line.gsub("*", "").strip
53
+ results.insert(-1, branch) if branch.length.positive?
58
54
  end
55
+ end
56
+ end
57
+ results
58
+ end
59
59
 
60
- # The latest commit id for a branch of the repostiory
61
- def latest_commit(branch)
62
- if(checkout_local_clone_directory_branch(branch))
63
- text=`git log -n 1`
64
- scan=text.scan(/commit ([\w]+)\s/)
65
- return scan[0][0].to_s
66
- end
67
- ''
68
- end
60
+ # The latest commit id for a branch of the repostiory
61
+ def latest_commit(branch)
62
+ if checkout_local_clone_directory_branch(branch)
63
+ text = `git log -n 1`
64
+ scan = text.scan(/commit (\w+)\s/)
65
+ return scan[0][0].to_s
66
+ end
67
+ ""
68
+ end
69
69
 
70
- # The latest tag for a branch of the repository
71
- def latest_tag(branch)
72
- if(checkout_local_clone_directory_branch(branch))
73
- return `git describe --abbrev=0`.strip
74
- end
75
- ''
76
- end
70
+ # The latest tag for a branch of the repository
71
+ def latest_tag(branch)
72
+ return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
77
73
 
78
- private def local_clone_directory
79
- clone_dir="#{Environment::get_dev_dir('clone')}/#{relative_path}"
80
- end
74
+ ""
75
+ end
81
76
 
82
- private def update_local_clone_directory
83
- if(Dir.exist?(local_clone_directory))
84
- Dir.chdir(local_clone_directory) do
85
- Raykit::Command.new('git pull')
86
- #t = `git pull`
87
- end
88
- else
89
- PROJECT.run("git clone #{@url} #{local_clone_directory}")
90
- end
91
- end
77
+ private def local_clone_directory
78
+ clone_dir = "#{Environment.get_dev_dir("clone")}/#{relative_path}"
79
+ end
92
80
 
93
- private def checkout_local_clone_directory_branch(branch)
94
- update_local_clone_directory
95
- if(Dir.exist?(local_clone_directory))
96
- Dir.chdir(local_clone_directory) do
97
- check=`git branch`
98
- if(!check.include?("* #{branch}"))
99
- t = `git checkout #{branch}`
100
- end
101
- check=`git branch`
102
- return check.include?("* #{branch}")
103
- end
104
- end
105
- false
106
- end
81
+ private def update_local_clone_directory
82
+ if Dir.exist?(local_clone_directory)
83
+ Dir.chdir(local_clone_directory) do
84
+ Raykit::Command.new("git pull")
85
+ # t = `git pull`
86
+ end
87
+ else
88
+ PROJECT.run("git clone #{@url} #{local_clone_directory}")
89
+ end
90
+ end
91
+
92
+ private def checkout_local_clone_directory_branch(branch)
93
+ update_local_clone_directory
94
+ if Dir.exist?(local_clone_directory)
95
+ Dir.chdir(local_clone_directory) do
96
+ check = `git branch`
97
+ t = `git checkout #{branch}` unless check.include?("* #{branch}")
98
+ check = `git branch`
99
+ return check.include?("* #{branch}")
100
+ end
107
101
  end
102
+ false
103
+ end
108
104
  end
109
- end
105
+ end
106
+ end
data/lib/raykit/log.rb CHANGED
@@ -1,43 +1,45 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
2
5
  module Raykit
3
- class Log < Hash
4
- @filename
5
- def initialize(filename)
6
- @filename=filename
7
- dir=File.dirname(@filename)
8
- FileUtils.mkdir_p(dir) if(!Dir.exist?(dir))
9
- if(File.exist?(@filename))
10
- begin
11
- data=JSON.parse(File.read(filename))
12
- data.each{|k,v|
13
- self[k] = v
14
- }
15
- rescue
16
- end
17
- end
18
- end
6
+ class Log < Hash
7
+ @filename
19
8
 
20
- def save
21
- File.open(@filename, 'w') {|f| f.write(JSON.generate(self)) }
9
+ def initialize(filename)
10
+ @filename = filename
11
+ dir = File.dirname(@filename)
12
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
13
+ if File.exist?(@filename)
14
+ begin
15
+ data = JSON.parse(File.read(filename))
16
+ data.each do |k, v|
17
+ self[k] = v
18
+ end
19
+ rescue StandardError
22
20
  end
21
+ end
22
+ end
23
23
 
24
- def update_command_time(command,timestamp)
25
- command_times = Hash.new()
26
- command_times = self["command_times"] if(self.has_key?("command_times"))
27
- command_times.delete(command) if(command_times.has_key?(command))
28
- command_times[command] = timestamp.iso8601()
29
- self["command_times"] = command_times
30
- save
31
- end
24
+ def save
25
+ File.open(@filename, "w") { |f| f.write(JSON.generate(self)) }
26
+ end
32
27
 
33
- def get_command_time(command)
34
- if(self.has_key?("command_times"))
35
- command_times = self["command_times"]
36
- if(command_times.has_key?(command))
37
- return DateTime.parse(command_times[command])
38
- end
39
- end
40
- nil
41
- end
28
+ def update_command_time(command, timestamp)
29
+ command_times = {}
30
+ command_times = self["command_times"] if key?("command_times")
31
+ command_times.delete(command) if command_times.key?(command)
32
+ command_times[command] = timestamp.iso8601
33
+ self["command_times"] = command_times
34
+ save
35
+ end
36
+
37
+ def get_command_time(command)
38
+ if key?("command_times")
39
+ command_times = self["command_times"]
40
+ return DateTime.parse(command_times[command]) if command_times.key?(command)
41
+ end
42
+ nil
42
43
  end
43
- end
44
+ end
45
+ end
@@ -1,36 +1,38 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
2
5
  module Raykit
3
- # :verbose, :debug, :information, :error, :fatal
4
- class LogEvent < Hash
5
- def initialize(level,messageTemplate,properties)
6
- self["Timestamp"] = DateTime.now.iso8601
7
- self["Level"] = level
8
- self["Message"] = messageTemplate
9
- self["MessageTemplate"] = messageTemplate
10
- properties["MachineName"] = Raykit::Environment::machine if !properties.has_key?('MachineName')
11
- properties["UserName"] = Raykit::Environment::user if !properties.has_key?('UserName')
12
- properties["RakeDirectory"] = ::Rake.application.original_dir
13
- self["Properties"] = properties
14
- end
6
+ # :verbose, :debug, :information, :error, :fatal
7
+ class LogEvent < Hash
8
+ 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
17
+ end
15
18
 
16
- def to_seq
17
- #puts '---to_seq---'
18
- #puts self['Message']
19
- if !ENV['SEQ_SERVER'].nil?
20
- cmd_str="seqcli log -m \"#{self['Message'].gsub("\"","")}\" -l #{self['Level']} -s #{ENV['SEQ_SERVER']}"
21
- self["Properties"].each{|k,v|
22
- cmd_str=cmd_str + " -p \"#{k}=#{v}\""
23
- }
24
- #puts '---executing---'
25
- #puts cmd_str
26
- puts `#{cmd_str}`
27
- end
19
+ def to_seq
20
+ # puts '---to_seq---'
21
+ # 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|
25
+ cmd_str += " -p \"#{k}=#{v}\""
28
26
  end
27
+ # puts '---executing---'
28
+ # puts cmd_str
29
+ puts `#{cmd_str}`
30
+ end
29
31
  end
32
+ end
30
33
  end
31
34
 
32
-
33
- #{
35
+ # {
34
36
  # "Timestamp": "2021-10-06T06:09:25.5275817-06:00",
35
37
  # "Level": "Information",
36
38
  # "MessageTemplate": "MachineName {machine}",
@@ -44,4 +46,4 @@ end
44
46
  # "UserName": "\"loupa\"",
45
47
  # "OS": "Windows_NT"
46
48
  # }
47
- #}
49
+ # }
@@ -1,59 +1,59 @@
1
- require 'json'
2
- require 'logger'
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "logger"
3
5
 
4
6
  module Raykit
5
- class Logging
6
- attr_accessor :enabled,:loggers
7
+ class Logging
8
+ attr_accessor :enabled, :loggers
7
9
 
8
- # Logger::Severity DEBUG,ERROR,FATAL,INFO,UNKOWN,WARN
9
- # defaults to WARN
10
- attr_accessor :severity
10
+ # Logger::Severity DEBUG,ERROR,FATAL,INFO,UNKOWN,WARN
11
+ # defaults to WARN
12
+ attr_accessor :severity
11
13
 
12
- def initialize()
13
- @enabled = true
14
- @loggers = Hash.new
15
- @severity= Logger::Severity::WARN
16
- end
14
+ def initialize
15
+ @enabled = true
16
+ @loggers = {}
17
+ @severity = Logger::Severity::WARN
18
+ end
17
19
 
18
- def set_severity_as_string(severity)
19
- @severity = Logger::Severity::DEBUG if(severity == 'debug')
20
- @severity = Logger::Severity::INFO if(severity == 'info')
21
- @severity = Logger::Severity::WARN if(severity == 'warn')
22
- @severity = Logger::Severity::ERROR if(severity == 'error')
23
- end
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"
25
+ end
24
26
 
25
- def get_logger(context)
26
- if(!loggers.has_key?(context))
27
- Dir.chdir(Environment::get_dev_dir('log')) do
28
- # start the log over whenever the log exceeds 100 megabytes in size
29
- loggers[context] = Logger.new("#{context}.log",0,100*1024*1024)
30
- end
31
- end
32
- loggers[context]
27
+ def get_logger(context)
28
+ unless loggers.key?(context)
29
+ Dir.chdir(Environment.get_dev_dir("log")) do
30
+ # start the log over whenever the log exceeds 100 megabytes in size
31
+ loggers[context] = Logger.new("#{context}.log", 0, 100 * 1024 * 1024)
33
32
  end
33
+ end
34
+ loggers[context]
35
+ end
34
36
 
35
- def log(context,level,message)
36
- if(@enabled)
37
- logger = get_logger(context)
38
- case level
39
- when Logger::Severity::DEBUG
40
- logger.debug(message)
41
- when Logger::Severity::INFO
42
- logger.info(message)
43
- when Logger::Severity::WARN
44
- logger.warn(message)
45
- when Logger::Severity::ERROR
46
- logger.error(message)
47
- when Logger::Severity::FATAL
48
- logger.fatal(message)
49
- else
50
- logger.unknown(message)
51
- end
52
- end
37
+ def log(context, level, message)
38
+ if @enabled
39
+ logger = get_logger(context)
40
+ case level
41
+ when Logger::Severity::DEBUG
42
+ logger.debug(message)
43
+ when Logger::Severity::INFO
44
+ logger.info(message)
45
+ when Logger::Severity::WARN
46
+ logger.warn(message)
47
+ when Logger::Severity::ERROR
48
+ logger.error(message)
49
+ when Logger::Severity::FATAL
50
+ logger.fatal(message)
51
+ else
52
+ logger.unknown(message)
53
53
  end
54
+ end
54
55
  end
55
-
56
-
56
+ end
57
57
  end
58
58
 
59
- LOG = Raykit::Logging.new
59
+ LOG = Raykit::Logging.new
@@ -1,14 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Raykit
2
- class MsBuild
3
- def self.msbuild_path
4
- ['2019/Enterprise/MSBuild/Current/Bin',
5
- '2019/Professional/MSBuild/Current/Bin',
6
- '2019/Community/MSBuild/Current/Bin',
7
- '2017/BuildTools/MSBuild/15.0/Bin'].each{|relative_path|
8
- path = 'C:/Program Files (x86)/Microsoft Visual Studio/' + relative_path
9
- return path if(Dir.exists?(path))
10
- }
11
- ''
4
+ class MsBuild
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)
12
15
  end
16
+ #path = "C:/Program Files (x86)/Microsoft Visual Studio/#{relative_path}"
17
+ #return path if Dir.exist?(path)
18
+ end
19
+ ""
13
20
  end
14
- end
21
+ end
22
+ end
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Raykit
3
- class NugetPackage
4
- attr_accessor :name
5
- attr_accessor :version
4
+ class NugetPackage
5
+ attr_accessor :name, :version
6
6
 
7
- def initialize(name,version)
8
- @name=name
9
- @version=version
10
- end
7
+ def initialize(name, version)
8
+ @name = name
9
+ @version = version
11
10
  end
12
- end
11
+ end
12
+ end