cnvrg 0.0.2

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.
@@ -0,0 +1,237 @@
1
+ require 'fileutils'
2
+
3
+ module Cnvrg
4
+ class Project
5
+ attr_reader :slug, :owner, :title, :local_path
6
+
7
+ RemoteURL ||= "https://cnvrg.io"
8
+
9
+ def initialize(project_home)
10
+ config = YAML.load_file(project_home+"/.cnvrg/config.yml")
11
+ @local_path = project_home
12
+ @title = config[:project_name]
13
+ @slug = config[:project_slug]
14
+ @owner = config[:owner]
15
+ end
16
+
17
+
18
+ def last_local_commit
19
+ idx = YAML.load_file(@local_path + "/.cnvrg/idx.yml")
20
+ return idx[:commit]
21
+ end
22
+
23
+ def url
24
+ "#{RemoteURL}/#{self.owner}/projects/#{self.slug}"
25
+ end
26
+
27
+ def update_ignore_list(new_ignore)
28
+ if new_ignore.empty?
29
+ return true
30
+ end
31
+ begin
32
+ File.open(self.local_path+"/.cnvrgignore", "a+") do |f|
33
+ new_ignore.each do |i|
34
+ f.puts("#{i}\n")
35
+ end
36
+ end
37
+ return true
38
+ rescue
39
+ return false
40
+ end
41
+ end
42
+ def get_ignore_list
43
+ ignore_list = []
44
+ File.open(self.local_path+"/.cnvrgignore", "r").each_line do |line|
45
+ line = line.strip
46
+ if line.start_with? "#"
47
+ next
48
+ end
49
+ if line.end_with? "/"
50
+ ignore_list << line.chop
51
+ sub_dirs = Dir.glob("#{line}/**/*").each{ |x| x.gsub!("//","/") }
52
+ ignore_list << sub_dirs.flatten
53
+ else
54
+ ignore_list << line
55
+ end
56
+ end
57
+ return ignore_list.flatten
58
+
59
+ end
60
+
61
+ # Create project
62
+
63
+ def self.create(project_name, path=nil,clean)
64
+ if clean
65
+ list_dirs = [project_name, project_name + "/.cnvrg"]
66
+ else
67
+
68
+ list_dirs = [project_name,
69
+ project_name + "/data",
70
+ project_name + "/models",
71
+ project_name + "/notebooks",
72
+ project_name + "/src",
73
+ project_name + "/src/visualizations",
74
+ project_name + "/src/features",
75
+ project_name + "/.cnvrg"
76
+ ]
77
+ end
78
+
79
+
80
+ list_files = [
81
+ project_name + "/README.md",
82
+ project_name + "/.cnvrgignore",
83
+ project_name + "/.cnvrg/config.yml"
84
+ ]
85
+ cnvrgreadme = Helpers.readme_content
86
+ cnvrgignore = Helpers.cnvrgignore_content
87
+
88
+ begin
89
+ response = Cnvrg::API.request("cli/create_project", 'POST', { title: project_name })
90
+ Cnvrg::CLI.is_response_success(response)
91
+ response = JSON.parse response["result"]
92
+ project_slug = response["slug"]
93
+ owner = response["owner"]
94
+
95
+ config = { project_name: project_name,
96
+ project_slug: project_slug,
97
+ owner: owner }
98
+ FileUtils.mkdir_p list_dirs
99
+ FileUtils.touch list_files
100
+
101
+ File.open(project_name + "/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
102
+ File.open(project_name + "/.cnvrgignore", "w+") { |f| f.write cnvrgignore }
103
+ File.open(project_name + "/README.md", "w+") { |f| f.write cnvrgreadme }
104
+ rescue
105
+ return false
106
+ end
107
+ return true
108
+ end
109
+ def self.link(project_name, path=nil)
110
+ list_dirs = [ ".cnvrg"
111
+ ]
112
+
113
+ list_files = [
114
+ "README.md",
115
+ ".cnvrgignore",
116
+ ".cnvrg/config.yml"
117
+ ]
118
+ cnvrgreadme = Helpers.readme_content
119
+ cnvrgignore = Helpers.cnvrgignore_content
120
+ begin
121
+ response = Cnvrg::API.request("cli/create_project", 'POST', { title: project_name })
122
+ Cnvrg::CLI.is_response_success(response)
123
+ response = JSON.parse response["result"]
124
+ project_slug = response["slug"]
125
+ owner = response["owner"]
126
+
127
+ config = { project_name: project_name,
128
+ project_slug: project_slug,
129
+ owner: owner }
130
+ FileUtils.mkdir_p list_dirs
131
+ FileUtils.touch list_files
132
+ File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
133
+ File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore }
134
+ File.open("README.md", "w+") { |f| f.write cnvrgreadme }
135
+ rescue => e
136
+ puts e
137
+ return false
138
+ end
139
+ return true
140
+ end
141
+ def self.clone_dir(project_slug,project_owner,project_name)
142
+ list_dirs = [project_name,
143
+ project_name + "/.cnvrg"
144
+ ]
145
+
146
+
147
+ list_files = [
148
+ project_name + "/.cnvrg/config.yml",
149
+ ]
150
+ begin
151
+ config = { project_name: project_name,
152
+ project_slug: project_slug,
153
+ owner: project_owner}
154
+ FileUtils.mkdir_p list_dirs
155
+ FileUtils.touch list_files
156
+
157
+ File.open(project_name + "/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
158
+ File.open(project_name + "/.cnvrg/idx.yml", "w+") { |f| f.write config.to_yaml }
159
+ rescue
160
+ return false
161
+ end
162
+ return true
163
+ end
164
+ def generate_idx
165
+ if File.exists? "#{self.local_path}/.cnvrg/idx.yml"
166
+ old_idx = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
167
+ else
168
+ old_idx = nil
169
+ end
170
+
171
+ tree_idx = Hash.new(0)
172
+
173
+ list = Dir.glob("#{self.local_path}/**/**", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) }
174
+ list_ignore = self.get_ignore_list()
175
+ list.each do |e|
176
+ label = e.gsub(self.local_path + "/", "")
177
+ if File.directory? e
178
+ if list_ignore.include? label
179
+ next
180
+ end
181
+ tree_idx[label+"/"] = nil
182
+ else
183
+ if list_ignore.include? label
184
+ next
185
+ end
186
+ sha1 = Digest::SHA1.file(e).hexdigest
187
+ if old_idx.nil? or old_idx.to_h[:tree].nil?
188
+ tree_idx[label] = { sha1: sha1, commit_time: nil }
189
+ elsif old_idx[:tree][label].nil? or old_idx[:tree][label][:sha1] != sha1
190
+ tree_idx[label] = { sha1: sha1, commit_time: nil }
191
+ else
192
+ tree_idx[label] = old_idx[:tree][label]
193
+ end
194
+ end
195
+ end
196
+
197
+ idx = { commit: old_idx.to_h[:commit], tree: tree_idx }
198
+
199
+ File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }
200
+ return YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
201
+ end
202
+
203
+ def get_idx
204
+ YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
205
+ end
206
+ def clone
207
+ response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/clone", 'POST', { project_slug: self.slug})
208
+ Cnvrg::CLI.is_response_success(response)
209
+ return response
210
+ end
211
+ def compare_idx
212
+ local_idx = self.generate_idx
213
+ response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/status", 'POST', { idx: local_idx })
214
+ CLI.is_response_success(response)
215
+ return response
216
+ end
217
+ def update_idx_with_files_commits!(files, commit_time)
218
+
219
+ idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
220
+ files.each do |path|
221
+ idx_hash[:tree][path][:commit_time] = commit_time
222
+ end
223
+ File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
224
+
225
+ return true
226
+ end
227
+
228
+ def update_idx_with_commit!(commit)
229
+ idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
230
+ idx_hash[:commit] = commit
231
+
232
+ File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
233
+ return true
234
+ end
235
+
236
+ end
237
+ end
@@ -0,0 +1,3 @@
1
+ module Cnvrg
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cnvrg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yochay Ettun
8
+ - Leah Kolben
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mimemagic
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.3.1
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.2
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: 0.3.1
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.2
34
+ - !ruby/object:Gem::Dependency
35
+ name: faraday
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ - !ruby/object:Gem::Dependency
49
+ name: netrc
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: open4
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.4
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.3'
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.4
82
+ - !ruby/object:Gem::Dependency
83
+ name: highline
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.7'
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 1.7.8
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.7'
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 1.7.8
102
+ - !ruby/object:Gem::Dependency
103
+ name: thor
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 0.19.0
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 0.19.1
112
+ type: :runtime
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.19.0
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 0.19.1
122
+ description: A CLI tool for interacting with cnvrg.io.
123
+ email:
124
+ - info@cnvrg.io
125
+ executables:
126
+ - cnvrg
127
+ extensions: []
128
+ extra_rdoc_files: []
129
+ files:
130
+ - bin/cnvrg
131
+ - cnvrg.gemspec
132
+ - lib/cnvrg.rb
133
+ - lib/cnvrg/api.rb
134
+ - lib/cnvrg/auth.rb
135
+ - lib/cnvrg/cli.rb
136
+ - lib/cnvrg/experiment.rb
137
+ - lib/cnvrg/files.rb
138
+ - lib/cnvrg/helpers.rb
139
+ - lib/cnvrg/old_cli.rb
140
+ - lib/cnvrg/project.rb
141
+ - lib/cnvrg/version.rb
142
+ homepage: https://cnvrg.io
143
+ licenses: []
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.5.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: A CLI tool for interacting with cnvrg.io.
165
+ test_files: []