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.
data/lib/raykit/runner.rb CHANGED
@@ -1,42 +1,42 @@
1
- require 'yaml'
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
2
4
 
3
5
  module Raykit
4
- class Runner
5
- def self.run(git_url)
6
- commands=Array.new()
7
- local_dir=Dir.mktmpdir('runner')
8
- puts 'local_dir : ' + local_dir
9
- commands << Raykit::Command.new("git clone #{git_url} #{local_dir}")
10
- Dir.chdir(local_dir) do
11
- commands << Raykit::Command.new("git log -n 1")
12
- yaml=get_build_yaml(local_dir)
13
- build_hash=YAML.load(yaml)
14
- build_commands=Raykit::Command.parse_yaml_commands(yaml)
15
- if(build_hash.key?('image'))
16
- image=build_hash['image']
17
- build_commands.insert(0,'cd home')
18
- build_commands.insert(1,"git clone #{git_url} build")
19
- build_commands.insert(2,'cd build')
20
- build_commands_string=build_commands.join(';');
21
- commands << Raykit::Command.new("docker run #{image} sh -c \"#{build_commands_string}\"")
22
- else
23
- build_commands.each{|cmd_string|
24
- commands << Rakkit::Command.new(cmd_string)
25
- }
26
- end
27
- end
28
- FileUtils.rm_rf(local_dir)
29
- commands
6
+ class Runner
7
+ def self.run(git_url)
8
+ commands = []
9
+ local_dir = Dir.mktmpdir("runner")
10
+ puts "local_dir : #{local_dir}"
11
+ commands << Raykit::Command.new("git clone #{git_url} #{local_dir}")
12
+ Dir.chdir(local_dir) do
13
+ commands << Raykit::Command.new("git log -n 1")
14
+ yaml = get_build_yaml(local_dir)
15
+ build_hash = YAML.safe_load(yaml)
16
+ build_commands = Raykit::Command.parse_yaml_commands(yaml)
17
+ if build_hash.key?("image")
18
+ image = build_hash["image"]
19
+ build_commands.insert(0, "cd home")
20
+ build_commands.insert(1, "git clone #{git_url} build")
21
+ build_commands.insert(2, "cd build")
22
+ build_commands_string = build_commands.join(";")
23
+ commands << Raykit::Command.new("docker run #{image} sh -c \"#{build_commands_string}\"")
24
+ else
25
+ build_commands.each do |cmd_string|
26
+ commands << Rakkit::Command.new(cmd_string)
27
+ end
30
28
  end
29
+ end
30
+ FileUtils.rm_rf(local_dir)
31
+ commands
32
+ end
31
33
 
32
- def self.get_build_yaml(directory)
33
- yaml=''
34
- Dir.chdir(directory) do
35
- if(File.exist?('.gitlab-ci.yml'))
36
- yaml = File.open('.gitlab-ci.yml').read
37
- end
38
- end
39
- yaml
40
- end
34
+ def self.get_build_yaml(directory)
35
+ yaml = ""
36
+ Dir.chdir(directory) do
37
+ yaml = File.open(".gitlab-ci.yml").read if File.exist?(".gitlab-ci.yml")
38
+ end
39
+ yaml
41
40
  end
42
- end
41
+ end
42
+ end
@@ -1,38 +1,38 @@
1
- require 'time'
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
2
4
 
3
5
  module Raykit
4
- # Provides functionality to record the time execution times
5
- class Secrets < Hash
6
- def initialize()
7
- if ENV.has_key?('RAYKIT_SECRETS_PATH')
8
- secrets_file = ENV['RAYKIT_SECRETS_PATH']
9
- if File.exists?(secrets_file)
10
- text = IO.read(secrets_file)
11
- if (text.length > 7 )
12
- data = JSON.parse(text)
13
- data.each{|key,value|
14
- self[key] = value
15
- }
16
- end
17
- end
6
+ # Provides functionality to record the time execution times
7
+ class Secrets < Hash
8
+ def initialize
9
+ if ENV.key?("RAYKIT_SECRETS_PATH")
10
+ secrets_file = ENV["RAYKIT_SECRETS_PATH"]
11
+ if File.exist?(secrets_file)
12
+ text = IO.read(secrets_file)
13
+ if text.length > 7
14
+ data = JSON.parse(text)
15
+ data.each do |key, value|
16
+ self[key] = value
18
17
  end
18
+ end
19
19
  end
20
+ end
21
+ end
20
22
 
21
- def hide(text)
22
- hidden=text
23
- self.each{|k,v|
24
- if(!v.nil? && v.length > 0)
25
- hidden=hidden.gsub(v,'****')
26
- end
27
- }
28
- hidden
29
- end
23
+ def hide(text)
24
+ hidden = text
25
+ each do |_k, v|
26
+ hidden = hidden.gsub(v, "****") if !v.nil? && v.length.positive?
27
+ end
28
+ hidden
29
+ end
30
30
 
31
- def save()
32
- if ENV.has_key?('RAYKIT_SECRETS_PATH')
33
- secrets_file = ENV['RAYKIT_SECRETS_PATH']
34
- File.open(secrets_file,"w") { |f| f.puts self.to_json }
35
- end
36
- end
31
+ def save
32
+ if ENV.key?("RAYKIT_SECRETS_PATH")
33
+ secrets_file = ENV["RAYKIT_SECRETS_PATH"]
34
+ File.open(secrets_file, "w") { |f| f.puts to_json }
35
+ end
37
36
  end
37
+ end
38
38
  end
@@ -1,75 +1,74 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Raykit
3
- class SourceImport < Hash
4
- def initialize(url,source,glob,target,commit)
5
- self['remote'] = url
6
- self['source'] = source
7
- self['glob'] = glob
8
- self['target'] = target
9
- self['commit']=commit
10
- end
4
+ class SourceImport < Hash
5
+ def initialize(url, source, glob, target, commit)
6
+ self["remote"] = url
7
+ self["source"] = source
8
+ self["glob"] = glob
9
+ self["target"] = target
10
+ self["commit"] = commit
11
+ end
11
12
 
12
- def remote
13
- self['remote']
14
- end
13
+ def remote
14
+ self["remote"]
15
+ end
15
16
 
16
- def source
17
- self['source']
18
- end
17
+ def source
18
+ self["source"]
19
+ end
19
20
 
20
- def target
21
- self['target']
22
- end
21
+ def target
22
+ self["target"]
23
+ end
24
+
25
+ def glob
26
+ self["glob"]
27
+ end
23
28
 
24
- def glob
25
- self['glob']
29
+ def update
30
+ work = self["remote"].work_dir
31
+ work_parent = File.dirname(work)
32
+ FileUtils.mkdir_p(work_parent) unless Dir.exist?(work_parent)
33
+ if Dir.exist?(work)
34
+ Dir.chdir(work) do
35
+ cmd = Command.new("git pull")
26
36
  end
37
+ else
38
+ PROJECT.run("git clone #{remote} #{work}")
39
+ end
27
40
 
28
- def update
29
- work=self['remote'].work_dir
30
- work_parent=File.dirname(work)
31
- FileUtils.mkdir_p(work_parent) if(!Dir.exist?(work_parent))
32
- if(Dir.exist?(work))
33
- Dir.chdir(work) do
34
- cmd = Command.new('git pull')
35
- end
36
- else
37
- PROJECT.run("git clone #{remote} #{work}")
38
- end
41
+ Dir.chdir(work) do
42
+ text = `git log -n 1`
43
+ scan = text.scan(/commit (\w+)\s/)
44
+ self["commit"] = scan[0][0].to_s
45
+ end
46
+ end
39
47
 
40
- Dir.chdir(work) do
41
- text=`git log -n 1`
42
- scan=text.scan(/commit ([\w]+)\s/)
43
- self['commit'] = scan[0][0].to_s
44
- end
48
+ def copy
49
+ if target.length.zero?
50
+ puts "target has not been specified"
51
+ else
52
+ FileUtils.remove_dir(target) if Dir.exist?(target)
53
+ count = 0
54
+ source_names = []
55
+ work = self["remote"].work_dir
56
+ Dir.chdir(work) do
57
+ cmd = Command.new("rake clean") if File.exist?("rakefile.rb")
58
+ Dir.chdir(source) do
59
+ source_names = Dir.glob(self["glob"])
60
+ end
45
61
  end
46
-
47
- def copy
48
- if(target.length == 0)
49
- puts 'target has not been specified'
50
- else
51
- FileUtils.remove_dir(target) if(Dir.exist?(target))
52
- count=0
53
- source_names = []
54
- work=self['remote'].work_dir
55
- Dir.chdir(work) do
56
- if(File.exist?('rakefile.rb'))
57
- cmd = Command.new('rake clean')
58
- end
59
- Dir.chdir(self.source) do
60
- source_names=Dir.glob(self['glob'])
61
- end
62
- end
63
- source_names.each{|source_name|
64
- source_file =work + "/" + self.source + "/" + source_name
65
- target_name = target + "/" + source_name
66
- target_parent = File.dirname(target_name)
67
- FileUtils.mkdir_p(target_parent) if(!Dir.exist?(target_parent))
68
- FileUtils.copy(source_file,target_name)
69
- count += 1
70
- }
71
- puts ' copied ' + count.to_s + ' files to ' + target
72
- end
62
+ source_names.each do |source_name|
63
+ source_file = "#{work}/#{source}/#{source_name}"
64
+ target_name = "#{target}/#{source_name}"
65
+ target_parent = File.dirname(target_name)
66
+ FileUtils.mkdir_p(target_parent) unless Dir.exist?(target_parent)
67
+ FileUtils.copy(source_file, target_name)
68
+ count += 1
73
69
  end
70
+ puts " copied #{count} files to #{target}"
71
+ end
74
72
  end
75
- end
73
+ end
74
+ end
@@ -1,46 +1,43 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Raykit
3
- class SourceImports < Array
4
-
5
- def initialize(urls)
6
- urls.each{|url|
7
- self << SourceImport.new(url,'src','**/*.cs','dep','')
8
- }
9
- end
4
+ class SourceImports < Array
5
+ def initialize(urls)
6
+ urls.each do |url|
7
+ self << SourceImport.new(url, "src", "**/*.cs", "dep", "")
8
+ end
9
+ end
10
10
 
11
- def update
12
- self.each{|si|
13
- si.update
14
- }
15
- end
11
+ def update
12
+ each(&:update)
13
+ end
16
14
 
17
- def copy
18
- self.each{|si|
19
- si.copy
20
- }
21
- end
15
+ def copy
16
+ each(&:copy)
17
+ end
22
18
 
23
- def targets_exist?
24
- self.each{|si|
25
- return false if(!Dir.exist?(si.target))
26
- }
27
- true
28
- end
19
+ def targets_exist?
20
+ each do |si|
21
+ return false unless Dir.exist?(si.target)
22
+ end
23
+ true
24
+ end
29
25
 
30
- def save(filename)
31
- File.open(filename,'w'){|f|
32
- f.write(JSON.pretty_generate(self))
33
- }
34
- end
26
+ def save(filename)
27
+ File.open(filename, "w") do |f|
28
+ f.write(JSON.pretty_generate(self))
29
+ end
30
+ end
35
31
 
36
- def self.load(filename)
37
- sourceImports = SourceImports.new([])
38
- array=JSON.parse(IO.read(filename))
39
- array.each{|hash|
40
- sourceImport = SourceImport.new(hash['remote'],hash['source'],hash['glob'],hash['target'],hash['commit'])
41
- sourceImports << sourceImport
42
- }
43
- sourceImports
44
- end
32
+ def self.load(filename)
33
+ sourceImports = SourceImports.new([])
34
+ array = JSON.parse(IO.read(filename))
35
+ array.each do |hash|
36
+ sourceImport = SourceImport.new(hash["remote"], hash["source"], hash["glob"], hash["target"],
37
+ hash["commit"])
38
+ sourceImports << sourceImport
39
+ end
40
+ sourceImports
45
41
  end
46
- end
42
+ end
43
+ end
data/lib/raykit/string.rb CHANGED
@@ -1,16 +1,18 @@
1
- require_relative('./environment.rb')
1
+ # frozen_string_literal: true
2
+
3
+ require_relative("./environment")
2
4
 
3
5
  class String
4
- def work_dir
5
- rel_name=self.sub('https://','').gsub('http://','').gsub('.git','')
6
- Raykit::Environment.get_dev_dir('work') + '/' + rel_name
7
- end
6
+ def work_dir
7
+ rel_name = sub("https://", "").gsub("http://", "").gsub(".git", "")
8
+ "#{Raykit::Environment.get_dev_dir("work")}/#{rel_name}"
9
+ end
8
10
 
9
- def latest_commit
10
- Dir.chdir(self) do
11
- text=`git log -n 1`
12
- scan=text.scan(/commit ([\w]+)\s/)
13
- return scan[0][0].to_s
14
- end
11
+ def latest_commit
12
+ Dir.chdir(self) do
13
+ text = `git log -n 1`
14
+ scan = text.scan(/commit (\w+)\s/)
15
+ return scan[0][0].to_s
15
16
  end
16
- end
17
+ end
18
+ end
data/lib/raykit/tasks.rb CHANGED
@@ -1,76 +1,74 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  desc "Display project information"
3
4
  task :info do
4
- PROJECT.info
5
+ PROJECT.info
5
6
  end
6
7
 
7
8
  desc "integrate changes into the git repository"
8
9
  task :integrate do
9
- puts Rainbow(':integrate').blue.bright
10
+ puts Rainbow(":integrate").blue.bright
10
11
 
11
- git_dir=Raykit::Git::Directory.new(Rake.application.original_dir)
12
- if(git_dir.detached?)
13
- puts "detached head state, skipping integrate operations"
12
+ git_dir = Raykit::Git::Directory.new(Rake.application.original_dir)
13
+ if git_dir.detached?
14
+ puts "detached head state, skipping integrate operations"
15
+ else
16
+ if PROJECT.outstanding_commit?
17
+ Rake::Task["test"].invoke if Rake::Task.task_defined?("test")
14
18
  else
15
- if(PROJECT.outstanding_commit?)
16
- if(Rake::Task.task_defined?("test"))
17
- Rake::Task["test"].invoke
18
- end
19
- else
20
- puts "no outstanding commits detected"
21
- end
19
+ puts "no outstanding commits detected"
20
+ end
22
21
 
23
-
24
- if(!File.exist?('.gitignore'))
25
- puts "warning: .gitignore does not exist."
26
- else
27
- PROJECT.run('git add --all')
28
- if(!`git status`.include?('nothing to commit'))
29
- #if(PROJECT.outstanding_commit?)
30
- commit_message='integrate'
31
- PROJECT.run("git commit -m\"#{commit_message}\"") if(PROJECT.outstanding_commit?)
32
- PROJECT.run("git pull")
33
- #PROJECT.run("git push")
34
- #PROJECT.run("git push --tags")
35
- end
36
- end
22
+ if !File.exist?(".gitignore")
23
+ puts "warning: .gitignore does not exist."
24
+ else
25
+ PROJECT.run("git add --all")
26
+ unless `git status`.include?("nothing to commit")
27
+ # if(PROJECT.outstanding_commit?)
28
+ commit_message = "integrate"
29
+ PROJECT.run("git commit -m\"#{commit_message}\"") if PROJECT.outstanding_commit?
30
+ PROJECT.run("git pull")
31
+ # PROJECT.run("git push")
32
+ # PROJECT.run("git push --tags")
33
+ end
37
34
  end
35
+ end
38
36
  end
39
37
 
40
38
  desc "push changes including tags"
41
39
  task :push do
42
- git_dir=Raykit::Git::Directory.new(Rake.application.original_dir)
43
- if(git_dir.detached?)
44
- puts "detached head state, skipping push operations"
45
- else
46
- PROJECT.run("git push")
47
- PROJECT.run("git push --tags")
48
- end
40
+ git_dir = Raykit::Git::Directory.new(Rake.application.original_dir)
41
+ if git_dir.detached?
42
+ puts "detached head state, skipping push operations"
43
+ else
44
+ PROJECT.run("git push")
45
+ PROJECT.run("git push --tags")
46
+ end
49
47
  end
50
48
 
51
49
  desc "clean files not tracked by git"
52
50
  task :clean do
53
- puts Rainbow(':clean').blue.bright
54
- PROJECT.run('git clean -dXf')
51
+ puts Rainbow(":clean").blue.bright
52
+ PROJECT.run("git clean -dXf")
55
53
  end
56
54
 
57
55
  desc "update_source from sourceImports.json"
58
56
  task :update_source do
59
- if(File.exist?('sourceImports.json'))
60
- puts Rainbow(':update_source').blue.bright
61
- sourceImports = Raykit::SourceImports.load('sourceImports.json')
62
- json=sourceImports.to_json
63
- sourceImports.update
57
+ if File.exist?("sourceImports.json")
58
+ puts Rainbow(":update_source").blue.bright
59
+ sourceImports = Raykit::SourceImports.load("sourceImports.json")
60
+ json = sourceImports.to_json
61
+ sourceImports.update
64
62
 
65
- json2=sourceImports.to_json
66
- if(json2 != json || !sourceImports.targets_exist?)
67
- sourceImports.save('sourceImports.json')
68
- sourceImports.copy
69
- else
70
- puts ' no update required.'
71
- end
63
+ json2 = sourceImports.to_json
64
+ if json2 != json || !sourceImports.targets_exist?
65
+ sourceImports.save("sourceImports.json")
66
+ sourceImports.copy
67
+ else
68
+ puts " no update required."
72
69
  end
70
+ end
73
71
  end
74
72
 
75
73
  desc "update source files"
76
- task :update => [:update_source]
74
+ task update: [:update_source]
data/lib/raykit/text.rb CHANGED
@@ -1,30 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Raykit
2
- class Text
3
- def self.replace_in_glob(glob,search,replace)
4
- Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
4
+ class Text
5
+ def self.replace_in_glob(glob, search, replace)
6
+ Dir.glob(glob).each { |f| replace_in_file(f, search, replace) }
5
7
  end
6
-
7
- def self.replace_in_file(filename,search,replace)
8
- text1 = IO.read(filename)
9
- text2 = text1.gsub(search) { |str| str=replace }
10
- unless text1==text2
11
- File.open(filename,"w") { |f| f.puts text2 }
8
+
9
+ def self.replace_in_file(filename, search, replace)
10
+ text1 = IO.read(filename)
11
+ text2 = text1.gsub(search) { |_str| str = replace }
12
+ unless text1 == text2
13
+ File.open(filename, "w") { |f| f.puts text2 }
12
14
  return true
13
- end
14
- false
15
+ end
16
+ false
15
17
  end
16
18
 
17
- def self.copy_if_different(source,destination)
18
- if(!File.exists?(destination))
19
+ def self.copy_if_different(source, destination)
20
+ if !File.exist?(destination)
19
21
  FileUtils.cp source, destination
20
- else
21
- source_text=IO.read(source)
22
- destination_text=IO.read(destination)
23
- if(source_text != destination_text)
24
- FileUtils.rm destination
25
- FileUtils.cp source, destination
22
+ else
23
+ source_text = IO.read(source)
24
+ destination_text = IO.read(destination)
25
+ if source_text != destination_text
26
+ FileUtils.rm destination
27
+ FileUtils.cp source, destination
26
28
  end
27
- end
28
- end
29
+ end
29
30
  end
30
- end
31
+ end
32
+ end
data/lib/raykit/timer.rb CHANGED
@@ -1,29 +1,31 @@
1
- require 'time'
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
2
4
 
3
5
  module Raykit
4
- # Provides functionality to record the time execution times
5
- class Timer
6
- # The time at which start occurred
7
- attr_accessor :start_time
6
+ # Provides functionality to record the time execution times
7
+ class Timer
8
+ # The time at which start occurred
9
+ attr_accessor :start_time
8
10
 
9
- def initialize
10
- @start_time=Time.now
11
- end
11
+ def initialize
12
+ @start_time = Time.now
13
+ end
12
14
 
13
- # The elapsed time, in seconds, since the timer started
14
- def elapsed
15
- return Time.now-@start_time
16
- end
15
+ # The elapsed time, in seconds, since the timer started
16
+ def elapsed
17
+ Time.now - @start_time
18
+ end
17
19
 
18
- # The elapsed time, in seconds, as a formatted string
19
- def elapsed_str(pad=0)
20
- Timer.get_elapsed_str(elapsed,pad)
21
- end
20
+ # The elapsed time, in seconds, as a formatted string
21
+ def elapsed_str(pad = 0)
22
+ Timer.get_elapsed_str(elapsed, pad)
23
+ end
22
24
 
23
- # Converts a time span in seconds to a formatted string
24
- def self.get_elapsed_str(elapsed,pad=0)
25
- #"[" + "%.0f" % (elapsed) + "s]".ljust(pad)
26
- "%.0f" % (elapsed) + "s".ljust(pad)
27
- end
25
+ # Converts a time span in seconds to a formatted string
26
+ def self.get_elapsed_str(elapsed, pad = 0)
27
+ # "[" + "%.0f" % (elapsed) + "s]".ljust(pad)
28
+ format("%.0f", elapsed) + "s".ljust(pad)
28
29
  end
29
- end
30
+ end
31
+ end