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,150 +1,145 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Raykit
2
- module Git
3
- # Functionality to manage a local clone of a git repository
4
- class Directory
5
- # The directory name of the local repository clone
6
- attr_accessor :directory
7
- @repository
8
-
9
- def initialize(directory)
10
- @directory=directory
11
- end
12
-
13
- def outstanding_commit?
14
- Dir.chdir(directory) do
15
- if(user_can_commit)
16
- return !`git status`.include?('nothing to commit,')
17
- else
18
- return false
19
- end
20
- end
21
- end
22
-
23
- def detached?
24
- Dir.chdir(directory) do
25
- status=`git status`.strip
26
- if status.include?('detached')
27
- true
28
- else
29
- false
30
- end
31
- end
32
- end
33
-
34
- def pull
35
- Dir.chdir(directory) do
36
- diff=`git diff`.strip
37
- status=`git status`.strip
38
- if(diff.length == 0 && status.include?('nothing to commit'))
39
- PROJECT.run('git pull',false)
40
- end
41
- end
42
- end
43
-
44
- def rake(task)
45
-
46
- if(!Dir.exist?(@directory))
47
- puts 'directory not found.'
48
- return 1
49
- end
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"
54
-
55
- puts "log filename #{rake_log}" if(debug)
56
- if(File.exist?(rake_log))
57
- if(File.mtime(rake_log) > last_modified_time)
58
- puts "using logged data" if(debug)
59
- cmd=Raykit::Command::parse(File.read(rake_log))
60
- cmd.summary
61
- return
62
- end
63
- end
64
-
65
- Dir.chdir(@directory) do
66
- if(File.exist?('rakefile.rb'))
67
- cmd = Raykit::Command.new("rake #{task}")
68
- cmd.summary
69
- FileUtils.mkdir_p(File.dirname(rake_log))
70
- File.open(rake_log, 'w') {|f| f.write(JSON.generate(cmd.to_hash)) }
71
- else
72
- puts 'rakefile.rb not found'
73
- end
74
- end
75
- end
76
-
77
- def last_modified_time
78
- Dir.chdir(@directory) do
79
- File.mtime(Dir.glob("**/*.*").select{|f| File.file?(f)}.max_by {|f| File.mtime(f)})
80
- end
81
- end
82
-
83
- # The latest tag for a branch of the repository
84
- def latest_tag(branch)
85
- Dir.chdir(directory) do
86
- return `git describe --abbrev=0`.strip
87
- end
88
- ''
89
- end
90
-
91
- def get_tag_commit_id(name)
92
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"",0,nil,false)
93
- if !cmd.output.include?('fatal') && !cmd.error.include?('fatal')
94
- cmd.output.strip()
95
- else
96
- ''
97
- end
98
- end
99
-
100
- def get_sha(filename)
101
- if File.exists?(filename)
102
- Digest::SHA256.file(filename).hexdigest.to_s
103
- else
104
- "#{filename} not found"
105
- end
106
- #''
107
- end
108
-
109
- def user_name
110
- `git config --get user.name`.strip
111
- end
112
-
113
- def user_email
114
- `git config --get user.email`.strip
115
- end
116
-
117
- def user_can_commit
118
- return false if(user_name.length == 0)
119
- return false if(user_email.length == 0)
120
- return true
121
- end
122
-
123
- def branch
124
- Dir.chdir(directory) do
125
- scan=`git branch`.scan(/\*\s([\w\.-]+)/)
126
- return scan[0][0].to_s if(!scan.nil? && scan.length > 0 && scan[0].length > 0)
127
- end
128
- 'master'
129
- end
130
-
131
- def repository
132
- if(@repository.nil?)
133
- @repository = Raykit::Git::Repository.new(remote)
134
- end
135
- @repository
136
- end
137
-
138
- def remote
139
- if(Dir.exist?(directory))
140
- Dir.chdir(directory) do
141
- if(Dir.exist?('.git'))
142
- return Command.new('git config --get remote.origin.url').output.strip
143
- end
144
- end
145
- end
146
- ""
147
- end
4
+ module Git
5
+ # Functionality to manage a local clone of a git repository
6
+ class Directory
7
+ # The directory name of the local repository clone
8
+ attr_accessor :directory
9
+
10
+ @repository
11
+
12
+ def initialize(directory)
13
+ @directory = directory
14
+ end
15
+
16
+ def outstanding_commit?
17
+ Dir.chdir(directory) do
18
+ if user_can_commit
19
+ return !`git status`.include?("nothing to commit,")
20
+ else
21
+ return false
22
+ end
23
+ end
24
+ end
25
+
26
+ def detached?
27
+ Dir.chdir(directory) do
28
+ status = `git status`.strip
29
+ if status.include?("detached")
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+ end
36
+
37
+ def pull
38
+ Dir.chdir(directory) do
39
+ diff = `git diff`.strip
40
+ status = `git status`.strip
41
+ PROJECT.run("git pull", false) if diff.length.zero? && status.include?("nothing to commit")
42
+ end
43
+ end
44
+
45
+ def rake(task)
46
+ unless Dir.exist?(@directory)
47
+ puts "directory not found."
48
+ return 1
49
+ end
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"
54
+
55
+ puts "log filename #{rake_log}" if debug
56
+ if File.exist?(rake_log) && (File.mtime(rake_log) > last_modified_time)
57
+ puts "using logged data" if debug
58
+ cmd = Raykit::Command.parse(File.read(rake_log))
59
+ cmd.summary
60
+ return
61
+ end
62
+
63
+ Dir.chdir(@directory) do
64
+ if File.exist?("rakefile.rb")
65
+ cmd = Raykit::Command.new("rake #{task}")
66
+ cmd.summary
67
+ FileUtils.mkdir_p(File.dirname(rake_log))
68
+ File.open(rake_log, "w") { |f| f.write(JSON.generate(cmd.to_hash)) }
69
+ else
70
+ puts "rakefile.rb not found"
71
+ end
72
+ end
73
+ end
74
+
75
+ def last_modified_time
76
+ Dir.chdir(@directory) do
77
+ File.mtime(Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) })
78
+ end
79
+ end
80
+
81
+ # The latest tag for a branch of the repository
82
+ def latest_tag(_branch)
83
+ Dir.chdir(directory) do
84
+ return `git describe --abbrev=0`.strip
85
+ end
86
+ ""
87
+ end
88
+
89
+ def get_tag_commit_id(name)
90
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"", 0, nil, false)
91
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
92
+ cmd.output.strip
93
+ else
94
+ ""
95
+ end
96
+ end
97
+
98
+ def get_sha(filename)
99
+ if File.exist?(filename)
100
+ Digest::SHA256.file(filename).hexdigest.to_s
101
+ else
102
+ "#{filename} not found"
103
+ end
104
+ # ''
105
+ end
106
+
107
+ def user_name
108
+ `git config --get user.name`.strip
109
+ end
110
+
111
+ def user_email
112
+ `git config --get user.email`.strip
113
+ end
114
+
115
+ def user_can_commit
116
+ return false if user_name.length.zero?
117
+ return false if user_email.length.zero?
118
+
119
+ true
120
+ end
121
+
122
+ def branch
123
+ Dir.chdir(directory) do
124
+ scan = `git branch`.scan(/\*\s([\w.-]+)/)
125
+ return scan[0][0].to_s if !scan.nil? && scan.length.positive? && scan[0].length.positive?
126
+ end
127
+ "master"
128
+ end
129
+
130
+ def repository
131
+ @repository = Raykit::Git::Repository.new(remote) if @repository.nil?
132
+ @repository
133
+ end
134
+
135
+ def remote
136
+ if Dir.exist?(directory)
137
+ Dir.chdir(directory) do
138
+ return Command.new("git config --get remote.origin.url").output.strip if Dir.exist?(".git")
139
+ end
148
140
  end
141
+ ""
142
+ end
149
143
  end
150
- end
144
+ end
145
+ end
@@ -1,45 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Raykit
2
- module Git
3
- # Functionality to manage a local clone of a git repository
4
- class Files
5
- @url
6
- @commit_id
7
- def initialize(url,commit_id)
8
- @url = url
9
- @commit_id = commit_id
10
- end
11
-
12
- def clean
13
- if Dir.exists?(commit_path())
14
- FileUtils.rm_rf(commit_path())
15
- end
16
- end
17
-
18
- def get(name)
19
- puts "commit_path(): " + commit_path()
20
- if !Dir.exists?(commit_path())
21
- puts 'cloning commit path...'
22
- clone = Raykit::Command.new('git clone ' + @url + ' ' + commit_path())
23
- puts clone.output
24
- puts clone.error
25
- Dir.chdir(commit_path()) do
26
- checkout = Raykit::Command.new('git checkout ' + @commit_id)
27
- end
28
- end
29
-
30
- if File.exists?(filename(name))
31
- return filename(name)
32
- end
33
- ''
34
- end
35
-
36
- def commit_path
37
- Dir.tmpdir() + File::SEPARATOR + 'Raykit.Git.Files' + File::SEPARATOR + @url.gsub('://','.') + File::SEPARATOR + @commit_id
38
- end
39
-
40
- def filename(name)
41
- commit_path() + File::SEPARATOR + name
42
- end
4
+ module Git
5
+ # Functionality to manage a local clone of a git repository
6
+ class Files
7
+ @url
8
+ @commit_id
9
+
10
+ def initialize(url, commit_id)
11
+ @url = url
12
+ @commit_id = commit_id
13
+ end
14
+
15
+ def clean
16
+ FileUtils.rm_rf(commit_path) if Dir.exist?(commit_path)
17
+ end
18
+
19
+ def get(name)
20
+ puts "commit_path(): #{commit_path}"
21
+ unless Dir.exist?(commit_path)
22
+ puts "cloning commit path..."
23
+ clone = Raykit::Command.new("git clone #{@url} #{commit_path}")
24
+ puts clone.output
25
+ puts clone.error
26
+ Dir.chdir(commit_path) do
27
+ checkout = Raykit::Command.new("git checkout #{@commit_id}")
28
+ end
43
29
  end
30
+
31
+ return filename(name) if File.exist?(filename(name))
32
+
33
+ ""
34
+ end
35
+
36
+ def commit_path
37
+ Dir.tmpdir + File::SEPARATOR + "Raykit.Git.Files" + File::SEPARATOR + @url.gsub("://",
38
+ ".") + File::SEPARATOR + @commit_id
39
+ end
40
+
41
+ def filename(name)
42
+ commit_path + File::SEPARATOR + name
43
+ end
44
44
  end
45
- end
45
+ end
46
+ end
@@ -1,93 +1,91 @@
1
- require_relative('./directory.rb')
1
+ # frozen_string_literal: true
2
+
3
+ require_relative("./directory")
2
4
 
3
5
  module Raykit
4
- module Git
5
- # Functionality to manage a remote git repository
6
- class Repositories < Array
7
- attr_accessor :filename
6
+ module Git
7
+ # Functionality to manage a remote git repository
8
+ class Repositories < Array
9
+ attr_accessor :filename
8
10
 
9
- def initialize(filename)
10
- @filename=filename
11
- open(@filename)
12
- end
11
+ def initialize(filename)
12
+ @filename = filename
13
+ open(@filename)
14
+ end
13
15
 
14
- def open(filename)
15
- if(File.exist?(filename))
16
- JSON.parse(File.read(filename)).each{|url|
17
- insert(-1,url)
18
- }
19
- else
20
- #puts "filename #{filename} does not exist"
21
- end
22
- end
16
+ def open(filename)
17
+ if File.exist?(filename)
18
+ JSON.parse(File.read(filename)).each do |url|
19
+ insert(-1, url)
20
+ end
21
+ else
22
+ # puts "filename #{filename} does not exist"
23
+ end
24
+ end
23
25
 
24
- def save(filename)
25
- File.open(@filename,'w'){|f|
26
- #json = JSON.pretty_generate(self)
27
- f.write(JSON.pretty_generate(self))
28
- #f.write(self.to_json)
29
- }
30
- end
26
+ def save(_filename)
27
+ File.open(@filename, "w") do |f|
28
+ # json = JSON.pretty_generate(self)
29
+ f.write(JSON.pretty_generate(self))
30
+ # f.write(self.to_json)
31
+ end
32
+ end
31
33
 
32
- def work_dir
33
- Environment::get_dev_dir('work')
34
- end
34
+ def work_dir
35
+ Environment.get_dev_dir("work")
36
+ end
35
37
 
36
- def is_remote_url pattern
37
- return true if(pattern.include?('http://'))
38
- return true if(pattern.include?('https://'))
39
- false
40
- end
38
+ def is_remote_url(pattern)
39
+ return true if pattern.include?("http://")
40
+ return true if pattern.include?("https://")
41
41
 
42
- def remove url
43
- if(include?(url))
44
- self.delete(url)
45
- save(@filename)
46
- end
47
- end
42
+ false
43
+ end
48
44
 
49
- def import(pattern)
50
- imported=Array.new
51
- if(is_remote_url(pattern))
52
- remote=pattern
53
- if(!include?(remote))
54
- insert(-1,remote)
55
- imported.insert(-1,remote)
56
- end
57
- else
58
- git_dirs = Array.new
59
- Dir.chdir(work_dir) do
60
- Dir.glob('**/.git'){|git_dir|
61
- dir = File.expand_path('..',git_dir)
62
- if(dir.length > 0)
63
- git_dirs.insert(0,dir)
64
- end
65
- }
66
- end
45
+ def remove(url)
46
+ if include?(url)
47
+ delete(url)
48
+ save(@filename)
49
+ end
50
+ end
67
51
 
68
- git_dirs.each{|git_dir|
69
- dir=Raykit::Git::Directory.new(git_dir)
70
- remote=dir.remote
71
- if(remote.include?(pattern) && !include?(remote))
72
- insert(-1,remote)
73
- imported.insert(-1,remote)
74
- end
75
- }
76
- end
77
- save(@filename)
78
- imported
52
+ def import(pattern)
53
+ imported = []
54
+ if is_remote_url(pattern)
55
+ remote = pattern
56
+ unless include?(remote)
57
+ insert(-1, remote)
58
+ imported.insert(-1, remote)
59
+ end
60
+ else
61
+ git_dirs = []
62
+ Dir.chdir(work_dir) do
63
+ Dir.glob("**/.git") do |git_dir|
64
+ dir = File.expand_path("..", git_dir)
65
+ git_dirs.insert(0, dir) if dir.length.positive?
79
66
  end
67
+ end
80
68
 
81
- def matches(pattern)
82
- matches = Array.new
83
- REPOSITORIES.each{|url|
84
- if(url.include?(pattern))
85
- matches << url
86
- end
87
- }
88
- matches
69
+ git_dirs.each do |git_dir|
70
+ dir = Raykit::Git::Directory.new(git_dir)
71
+ remote = dir.remote
72
+ if remote.include?(pattern) && !include?(remote)
73
+ insert(-1, remote)
74
+ imported.insert(-1, remote)
89
75
  end
76
+ end
77
+ end
78
+ save(@filename)
79
+ imported
80
+ end
81
+
82
+ def matches(pattern)
83
+ matches = []
84
+ REPOSITORIES.each do |url|
85
+ matches << url if url.include?(pattern)
90
86
  end
87
+ matches
88
+ end
91
89
  end
90
+ end
92
91
  end
93
-