lense 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lense +15 -19
- data/lib/lense.rb +54 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b7caa4fbcf410db3adf45c8e3f1a22dabae34e
|
4
|
+
data.tar.gz: 1aca957e23511a177e1f2c1ec8921e4bb9758092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba1d8e4816d4a9ba15b423e21981a183e8bbffc9f6fca78036b6793ca44f5ebb752ebf2d8c345ad618d9ef9e9afeb3d6f73e3d721404cd742728347c125b5a4
|
7
|
+
data.tar.gz: c574851870ffeeef7a11f08aac229594253dce3ddb080454c1cbff9e86a122e6e351107975ab63661eb1ae39e2427891a3eda563bb0190ebc2c362de1ae3e827
|
data/bin/lense
CHANGED
@@ -47,7 +47,7 @@ command :search do |c|
|
|
47
47
|
end
|
48
48
|
|
49
49
|
command :up do |c|
|
50
|
-
c.action do
|
50
|
+
c.action do
|
51
51
|
LENSE_APP.run
|
52
52
|
end
|
53
53
|
end
|
@@ -64,34 +64,30 @@ command :destroy do |c|
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
command :
|
68
|
-
c.action do
|
69
|
-
|
67
|
+
command :push do |c|
|
68
|
+
c.action do |global_options,options,args|
|
69
|
+
exit_now!('Must supply a LENSE repository.') if args.count < 1
|
70
|
+
LENSE_APP.push args[0]
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
|
-
command :
|
74
|
-
c.action do
|
75
|
-
|
74
|
+
command :pull do |c|
|
75
|
+
c.action do |global_options,options,args|
|
76
|
+
exit_now!('Must supply a LENSE repository.') if args.count < 1
|
77
|
+
LENSE_APP.pull args[0]
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
command :
|
81
|
+
command :clone do |c|
|
80
82
|
c.action do |global_options,options,args|
|
81
|
-
exit_now!('Must supply
|
82
|
-
|
83
|
-
res = LENSE_APP.select_course course
|
84
|
-
if res.nil?
|
85
|
-
puts "Staying on #{course}..."
|
86
|
-
else
|
87
|
-
puts "Switched to course: #{res}."
|
88
|
-
end
|
83
|
+
exit_now!('Must supply a LENSE repository.') if args.count < 1
|
84
|
+
LENSE_APP.clone args[0]
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
92
88
|
command :commit do |c|
|
93
89
|
c.action do |global_options,options,args|
|
94
|
-
exit_now!('Must supply
|
90
|
+
exit_now!('Must supply file.') if args.count < 1
|
95
91
|
LENSE_APP.commit args.join(' ')
|
96
92
|
end
|
97
93
|
end
|
@@ -111,14 +107,14 @@ end
|
|
111
107
|
|
112
108
|
command :stage do |c|
|
113
109
|
c.action do |global_options,options,args|
|
114
|
-
exit_now!('Must supply
|
110
|
+
exit_now!('Must supply file.') if args.count < 1
|
115
111
|
LENSE_APP.stage args[0]
|
116
112
|
end
|
117
113
|
end
|
118
114
|
|
119
115
|
command :unstage do |c|
|
120
116
|
c.action do |global_options,options,args|
|
121
|
-
exit_now!('Must supply
|
117
|
+
exit_now!('Must supply file.') if args.count < 1
|
122
118
|
LENSE_APP.unstage args[0]
|
123
119
|
end
|
124
120
|
end
|
data/lib/lense.rb
CHANGED
@@ -6,7 +6,7 @@ require 'sqlite3'
|
|
6
6
|
class LENSE
|
7
7
|
attr_reader :config, :current_course, :lense_file_hash
|
8
8
|
|
9
|
-
VERSION = '0.2.
|
9
|
+
VERSION = '0.2.3'
|
10
10
|
LENSE_DIR = File.join(ENV['HOME'],'.lense')
|
11
11
|
COURSES_DIR = File.join(LENSE_DIR,'courses')
|
12
12
|
CURRENT_COURSE_FILE = File.join(LENSE_DIR,'current_course')
|
@@ -15,6 +15,8 @@ class LENSE
|
|
15
15
|
REFS_DIR = File.join(LOCAL_LENSE_DIR,'refs')
|
16
16
|
CURRENT_REF_FILE = File.join(REFS_DIR,'current')
|
17
17
|
LENSE_FILE = File.join(ENV['PWD'],'LENSEfile')
|
18
|
+
API_BASE = 'http://lightweightnetsec.com'
|
19
|
+
TARFLAGS = ''
|
18
20
|
|
19
21
|
def initialize()
|
20
22
|
Dir.mkdir(LENSE_DIR) unless File.directory?(LENSE_DIR)
|
@@ -57,7 +59,7 @@ class LENSE
|
|
57
59
|
|
58
60
|
def search(term)
|
59
61
|
puts "Searching course repository ..."
|
60
|
-
response = RestClient.get
|
62
|
+
response = RestClient.get "#{API_BASE}/lessons", { params: { format: 'json', text: term } }
|
61
63
|
courses = JSON.parse(response)
|
62
64
|
courses.each do |c|
|
63
65
|
puts "---"
|
@@ -179,7 +181,7 @@ class LENSE
|
|
179
181
|
end
|
180
182
|
|
181
183
|
combined_hash = files.map {|f| f[:hash]}.join ''
|
182
|
-
commit_hash =
|
184
|
+
commit_hash = hash_contents "#{DateTime.now.to_s}#{combined_hash}"
|
183
185
|
@DB.execute 'insert into commits (hash,message,created_at) values (?,?,?);',[commit_hash,msg,DateTime.now.to_s]
|
184
186
|
commit_id = @DB.last_insert_row_id
|
185
187
|
|
@@ -250,10 +252,57 @@ class LENSE
|
|
250
252
|
end
|
251
253
|
end
|
252
254
|
|
255
|
+
def push(repo)
|
256
|
+
exit_now!("Invalid repo name.") unless repo =~ /\A\w+\/\w+\Z/
|
257
|
+
end
|
258
|
+
|
259
|
+
def pull(repo)
|
260
|
+
exit_now!("Invalid repo name.") unless repo =~ /\A\w+\/\w+\Z/
|
261
|
+
response = RestClient.get "#{API_BASE}/#{repo}/pull", { params: { format: 'json' } }
|
262
|
+
repository = JSON.parse(response)
|
263
|
+
end
|
264
|
+
|
265
|
+
def clone(repo)
|
266
|
+
exit_now!("Invalid repo name.") unless repo =~ /\A\w+\/\w+\Z/
|
267
|
+
response = RestClient.get "#{API_BASE}/#{repo}/pull", { params: { format: 'json' } }
|
268
|
+
repository = JSON.parse(response)
|
269
|
+
tar_str = Base64::decode64 repository["tar_file_base64"]
|
270
|
+
tar_hash = repository["tar_file_fingerprint"]
|
271
|
+
|
272
|
+
username, project_name = repo.split '/'
|
273
|
+
|
274
|
+
# make repo dir in current directory
|
275
|
+
Dir.mkdir project_name unless Dir.directory? project_name
|
276
|
+
|
277
|
+
# make .lense dir and .lense/temp
|
278
|
+
proj_lense_dir = File.join project_name, '.lense'
|
279
|
+
Dir.mkdir proj_lense_dir unless Dir.directory? proj_lense_dir
|
280
|
+
|
281
|
+
temp_dir = File.join proj_lense_dir, 'temp'
|
282
|
+
Dir.mkdir temp_dir unless Dir.directory? temp_dir
|
283
|
+
|
284
|
+
# write tar file to .lense/temp/hash.tar
|
285
|
+
tar_fname = "#{tar_hash}.tar"
|
286
|
+
File.open(File.join(temp_dir,tar_fname), 'w') { |f| f.write tar_str }
|
287
|
+
|
288
|
+
# cd into repo dir and untar
|
289
|
+
`cd #{project_name} && tar -x#{TARFLAGS}f #{tar_fname}`
|
290
|
+
|
291
|
+
# read lensefile
|
292
|
+
# iterate over dependencies
|
293
|
+
# - download
|
294
|
+
# - verify w/ hash
|
295
|
+
end
|
296
|
+
|
253
297
|
private
|
254
298
|
def hash_file(file)
|
255
|
-
|
299
|
+
hash_contents File.read(file)
|
256
300
|
end
|
301
|
+
|
302
|
+
def hash_contents(contents)
|
303
|
+
Digest::MD5.hexdigest contents
|
304
|
+
end
|
305
|
+
|
257
306
|
def get_dependency(file)
|
258
307
|
rows = @DB.execute("
|
259
308
|
select d.id, d.path, d.added_at, r.hash, r.created_at, c.hash
|
@@ -266,9 +315,9 @@ class LENSE
|
|
266
315
|
order by r.created_at desc
|
267
316
|
limit 1;
|
268
317
|
", file)
|
318
|
+
|
269
319
|
if rows.length > 0
|
270
320
|
id, path, added_at, file_hash, saved_at, commit_hash = rows[0]
|
271
|
-
|
272
321
|
{
|
273
322
|
id: id,
|
274
323
|
path: path,
|
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.
|
4
|
+
version: 0.2.3
|
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-
|
12
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|