lense 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/data/mfwvl1.yaml +6 -1
  3. data/lib/lense.rb +71 -18
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c121069eb1ee2fbdfee54479be7b2be9fec63a3f
4
- data.tar.gz: 875b065ea8d1f0f4f5ae1c63ac05bc0b16d7dcde
3
+ metadata.gz: d70caab50233ebeac96062c48b778c90ea58ed6a
4
+ data.tar.gz: 598f475c0ef9cf20a217452bb7571a4c7f887bc8
5
5
  SHA512:
6
- metadata.gz: a60eb1b8c2484ccc3dbd7d8a952ff513e44c04a01d54d43e96b438a04c40fd63dfa8d1dfac7dff245eec1cf39bb869d514a9ea8f5fb53b44d1126b0dd1db19da
7
- data.tar.gz: 8cf1ebaf4b5488c43f77151680c467d06a729c0d6317b7bd40d708971da92a6fa6e44cbc4316a4f982c7888ce4f9e6193d1e413d8e2142123b4752b052bc25dc
6
+ metadata.gz: 6af0ee9c28a139cb059a3684d55d58eb26affc4b8f5819a228cb590bd93638f311a315bf7ca8bc4090fa6a99644235a2819ddf376ee4b09fd26351c8c156f59b
7
+ data.tar.gz: 6f54d7b138ef4589ffeae3534f4ef3284841705f30a58aa4d8b65e28bb764733bcc038e58ce3aa24b26b7c1328e3d7c8beea0355c3344fca8188b3a96cdc6c07
data/data/mfwvl1.yaml CHANGED
@@ -6,7 +6,12 @@ authors:
6
6
  email: lance.lacoste@gmail.com
7
7
 
8
8
  dependancies:
9
- - data/my_memory_sample.vmem
9
+ - path: data/my_memory_sample.vmem
10
+ url: http://url.com/file
11
+ hash: fj13k4jkf15j
12
+ - path: docker-compose.yml
13
+ hash: fj13k4jkf15j
14
+
10
15
 
11
16
  # The final command to open in a new terminal.
12
17
  up:
data/lib/lense.rb CHANGED
@@ -3,11 +3,12 @@ require 'highline/import'
3
3
  require 'digest'
4
4
  require 'sqlite3'
5
5
  require 'base64'
6
+ require 'active_support/all'
6
7
 
7
8
  class LENSE
8
9
  attr_reader :config, :current_course, :lense_file_hash
9
10
 
10
- VERSION = '0.2.16'
11
+ VERSION = '0.2.17'
11
12
  LENSE_DIR = File.join(ENV['HOME'],'.lense')
12
13
  COURSES_DIR = File.join(LENSE_DIR,'courses')
13
14
  CURRENT_COURSE_FILE = File.join(LENSE_DIR,'current_course')
@@ -17,7 +18,7 @@ class LENSE
17
18
  CURRENT_REF_FILE = File.join(REFS_DIR,'current')
18
19
  LENSE_FILE = File.join(ENV['PWD'],'LENSEfile')
19
20
  API_BASE = 'http://lightweightnetsec.com'
20
- TARFLAGS = ''
21
+ TARFLAGS = 'z'
21
22
 
22
23
  def initialize()
23
24
  Dir.mkdir(LENSE_DIR) unless File.directory?(LENSE_DIR)
@@ -138,11 +139,11 @@ class LENSE
138
139
  end
139
140
 
140
141
  def status()
141
- #say "Hash : #{@lense_file_hash}"
142
142
  exit_now!("Not a LENSE project: .lense") unless File.directory?(LOCAL_LENSE_DIR)
143
143
 
144
- say "Staged Files:\n"
145
- @DB.execute("select path from staging;").each do |row|
144
+ rows = @DB.execute("select path from staging;")
145
+ say "Staged Files:\n" if rows.length > 0
146
+ rows.each do |row|
146
147
  path = row[0]
147
148
  dependency = get_dependency(path)
148
149
  action = dependency.nil? ? 'New File' : 'Modified'
@@ -158,11 +159,6 @@ class LENSE
158
159
  end
159
160
  end
160
161
 
161
- # check changes in depenancy files
162
- # - for each depenceny
163
- # - - get the current file hash
164
- # - - check against .lense/deps/#{rel_path_to_dep}
165
- # - - output any ones that have changed
166
162
  end
167
163
 
168
164
  def commit(msg)
@@ -176,16 +172,21 @@ class LENSE
176
172
  }
177
173
  end
178
174
 
175
+ # only select new or modified files
179
176
  files = rows.select do |file|
180
177
  dependency = get_dependency(file[:path])
181
178
  dependency.nil? || dependency[:file_hash] != file[:hash]
182
179
  end
183
180
 
181
+ # generate commit hash
184
182
  combined_hash = files.map {|f| f[:hash]}.join ''
185
183
  commit_hash = hash_contents "#{DateTime.now.to_s}#{combined_hash}"
184
+
185
+ # save to db
186
186
  @DB.execute 'insert into commits (hash,message,created_at) values (?,?,?);',[commit_hash,msg,DateTime.now.to_s]
187
187
  commit_id = @DB.last_insert_row_id
188
188
 
189
+ # add file revisions for all new/modified dependencies
189
190
  files.each do |file|
190
191
  @DB.transaction
191
192
  dependency = get_dependency(file[:path])
@@ -198,13 +199,11 @@ class LENSE
198
199
  @DB.execute 'insert into revisions (commit_id,dependency_id,hash,created_at) values (?,?,?,?);',[commit_id,dependency_id,file[:hash],DateTime.now.to_s]
199
200
  @DB.commit
200
201
  end
202
+
203
+ # empty staging
201
204
  @DB.transaction
202
205
  @DB.execute 'delete from staging;'
203
206
  @DB.commit
204
- # add new files to dependancies
205
- # create a hash for the commit and add to commits
206
- # for all dependancies add current hashes to revisions
207
- # truncate staging
208
207
  end
209
208
 
210
209
  def stage(file)
@@ -260,6 +259,8 @@ class LENSE
260
259
  output = `#{cmd}`
261
260
  say "<%= color(' => ',:blue) %> #{output}"
262
261
  end
262
+
263
+ run
263
264
  end
264
265
 
265
266
  def down
@@ -273,6 +274,35 @@ class LENSE
273
274
 
274
275
  def push(repo)
275
276
  repo = validate_in_repo
277
+ user, project = repo.split '/'
278
+ rows = @DB.execute "select path from dependencies where not deleted;"
279
+ rows.map! { |r| r[0] }
280
+
281
+ # only include files < 10 megabytes
282
+ deps = rows.select do |path|
283
+ File.size path <= 10.megabytes
284
+ end
285
+
286
+ db_hash = hash_file '.lense/db'
287
+ tar_fname = "#{user}_#{project}_#{db_hash}.tar"
288
+ tar_path = ".lense/temp/#{tar_fname}"
289
+
290
+ cmd = "tar -c#{TARFLAGS}f #{tar_path} .lense/db #{deps.join ' '}"
291
+ say "taring up with: #{cmd}"
292
+ `#{cmd}`
293
+
294
+ post_body = {
295
+ params: {
296
+ format: 'json',
297
+ user_token: 'z5kqZTsKU_oXvC3d5j96',
298
+ tar_file_base64: Base64::encode64(File.read(tar_path)),
299
+ filename: tar_fname,
300
+ content_type: "application/x-tar"
301
+
302
+ }
303
+ }
304
+ response = RestClient.post "#{API_BASE}/#{repo}/push", post_body
305
+ say "response: #{response}"
276
306
  end
277
307
 
278
308
  def pull()
@@ -328,10 +358,33 @@ class LENSE
328
358
  `tar -x#{TARFLAGS}f #{rel_tar_path}`
329
359
 
330
360
  say "done"
331
- # read lensefile
332
- # iterate over dependencies
333
- # - download
334
- # - verify w/ hash
361
+ lense = read_lensefile
362
+ lense['dependencies'].each do |dep|
363
+ next unless dep['url']
364
+
365
+ # check if file already exists
366
+ if File.file? dep['path']
367
+ # skip if same hash
368
+ if dep['hash'] == hash_file(dep['path'])
369
+ say "Skipping #{dep['path']}"
370
+ next
371
+ # error if different
372
+ else
373
+ exit_now!("File already exists and has been modified: #{dep['path']}")
374
+ end
375
+ end
376
+
377
+ dirs, path = File.split dep['path']
378
+ FileUtils.mkdir_p dirs unless File.directory? dirs
379
+ begin
380
+ say "fetching #{dep['path']} from #{dep['url']}"
381
+ file_str = RestClient.get dep['url']
382
+ exit_now!("Problem downloading file: #{dep['path']}") unless dep['hash'] == hash_contents(file_str)
383
+ File.open(path,'w') { |f| f.write file_str }
384
+ rescue
385
+ exit_now!("Unable to fetch dependency: #{dep['url']}")
386
+ end
387
+ end
335
388
  end
336
389
 
337
390
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lense
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Zubieta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-26 00:00:00.000000000 Z
12
+ date: 2015-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake