lapack 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lapack +79 -13
- data/lib/laenv.rb +32 -4
- data/lib/lapack.rb +79 -13
- data/lib/providers/ctan.rb +32 -0
- data/lib/providers/provider.rb +10 -0
- metadata +3 -4
- data/lib/providers/github.rb +0 -154
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 229dc554d0692dd3c2d927bb50a3b8a21835df44
|
4
|
+
data.tar.gz: fd2dd7fb92ead3003fe50db2a4290243e6334c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc1ff437ec82ccc4824b3667be7382c149e7656597776fb30f8e95765e6f025ac428c0597925ed13fac5dfe4ac9b44bfd53dfd1b70cbd8792f81ff39c1f8e603
|
7
|
+
data.tar.gz: 8720417cd62fc541484eaa866c082ace317af47a652f2f8949710a9e19f09da09b50f10ec30269a37b0fc1420b3dff86b4d69eeb2b9d44149057588f9d09413b
|
data/bin/lapack
CHANGED
@@ -17,12 +17,23 @@ require 'tmpdir'
|
|
17
17
|
|
18
18
|
ENV['LAPACK'] = File.dirname(File.realpath(__FILE__))
|
19
19
|
|
20
|
-
|
20
|
+
##
|
21
|
+
# Check if we in debug mode or not
|
22
|
+
#
|
23
|
+
DEBUG = false
|
24
|
+
|
25
|
+
##
|
26
|
+
# Current version
|
27
|
+
#
|
28
|
+
Version = [0, 0, 3]
|
29
|
+
|
30
|
+
def lareq path
|
31
|
+
require (DEBUG ? File.join(ENV['LAPACK'], path) : path)
|
32
|
+
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
require "providers/github"
|
34
|
+
lareq "laenv"
|
35
|
+
lareq "providers/provider"
|
36
|
+
lareq "providers/ctan"
|
26
37
|
|
27
38
|
|
28
39
|
module LaPack
|
@@ -37,15 +48,17 @@ module LaPack
|
|
37
48
|
plain: "%s"
|
38
49
|
}
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
## laenv - окружение, в котором работаем
|
51
|
+
##
|
52
|
+
# Get data from +url+ and save it to +dst+
|
53
|
+
#
|
44
54
|
def LaPack.get(url, dst)
|
45
55
|
log("Fetching #{url.white.bold} to #{dst.white.bold}")
|
46
56
|
File.open(dst, "w"){|f| f << LaPack.gets(url)}
|
47
57
|
end
|
48
58
|
|
59
|
+
##
|
60
|
+
# Get data from +url+ and return it as string
|
61
|
+
#
|
49
62
|
def LaPack.gets(url)
|
50
63
|
open(url).read
|
51
64
|
end
|
@@ -80,6 +93,7 @@ module LaPack
|
|
80
93
|
##
|
81
94
|
# Logging method
|
82
95
|
# TODO: Remove from LaPack module. Move to utils.rb
|
96
|
+
#
|
83
97
|
def LaPack.log(string, level = :info)
|
84
98
|
puts LOG_LEVELS[level] % string unless LENV.quiet? # Do not print anything if quiet
|
85
99
|
end
|
@@ -94,9 +108,8 @@ module LaPack
|
|
94
108
|
##
|
95
109
|
# Install packages.
|
96
110
|
# If last argument from packages list is directory
|
97
|
-
#
|
98
|
-
# else
|
99
|
-
# install to current working dir
|
111
|
+
# install all packages to directory
|
112
|
+
# else install to current working dir
|
100
113
|
#
|
101
114
|
def LaPack.install(db, *packages)
|
102
115
|
raise "Empty package list" unless !packages.last.nil? # No packages specified at all
|
@@ -144,11 +157,64 @@ module LaPack
|
|
144
157
|
end
|
145
158
|
end
|
146
159
|
|
160
|
+
require 'optparse'
|
161
|
+
require 'optparse/time'
|
162
|
+
require 'ostruct'
|
163
|
+
require 'pp'
|
164
|
+
|
165
|
+
class Args
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
#
|
170
|
+
# Return a structure describing the options.
|
171
|
+
#
|
172
|
+
def self.parse(args)
|
173
|
+
# The options specified on the command line will be collected in *options*.
|
174
|
+
# We set default values here.
|
175
|
+
options = OpenStruct.new
|
176
|
+
options.command
|
177
|
+
opt_parser = OptionParser.new do |opts|
|
178
|
+
opts.banner = "Usage: lapack [command] [command_args]..."
|
179
|
+
|
180
|
+
opts.separator ""
|
181
|
+
opts.separator "Commands:"
|
182
|
+
opts.separator "\t add [reponame] -- add repository. Currently supported: ctan"
|
183
|
+
opts.separator "\t update [reponame] -- update repository index."
|
184
|
+
opts.separator "\t install [reponame] [package]... [to_dir] -- install packages from repository to specified directory. If no directory specified use current working dir"
|
185
|
+
opts.separator "\t remove [reponame] [package]... -- remove packages from local cache"
|
186
|
+
opts.separator ""
|
187
|
+
opts.separator "Specific options:"
|
188
|
+
|
189
|
+
# No argument, shows at tail. This will print an options summary.
|
190
|
+
# Try it and see!
|
191
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
192
|
+
puts opts
|
193
|
+
exit
|
194
|
+
end
|
195
|
+
|
196
|
+
# Another typical switch to print the version.
|
197
|
+
opts.on_tail("--version", "Show version") do
|
198
|
+
puts Version.join('.')
|
199
|
+
exit
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
opt_parser.parse!(args)
|
204
|
+
options
|
205
|
+
end # parse()
|
206
|
+
|
207
|
+
end # class Args
|
208
|
+
|
209
|
+
|
210
|
+
|
147
211
|
if (ARGV.empty?)
|
148
212
|
puts "No args passed"
|
149
213
|
else
|
214
|
+
options = Args.parse(ARGV)
|
215
|
+
|
150
216
|
begin
|
151
|
-
LaPack.send(ARGV[0], *ARGV[1..ARGV.length])
|
217
|
+
LaPack.send(ARGV[0], *ARGV[1..ARGV.length]) unless ARGV.empty?
|
152
218
|
rescue NoMethodError => undefined
|
153
219
|
puts "Unknown operation #{undefined.name}"
|
154
220
|
rescue Exception => e
|
data/lib/laenv.rb
CHANGED
@@ -5,8 +5,20 @@ module LaPack
|
|
5
5
|
#
|
6
6
|
class LaEnv
|
7
7
|
|
8
|
-
|
8
|
+
# Provides path for storage root
|
9
|
+
attr_reader :lastore
|
10
|
+
# Povides path for dbs root
|
11
|
+
attr_reader :ladb
|
12
|
+
# Prodives pkg dir name
|
13
|
+
attr_reader :lapkg
|
9
14
|
|
15
|
+
##
|
16
|
+
# Create new LaEnv instance
|
17
|
+
#
|
18
|
+
# Expected +args+ keys
|
19
|
+
# :lastore - path fro storage root
|
20
|
+
# :quiet - enable or disable logging
|
21
|
+
#
|
10
22
|
def initialize(args={})
|
11
23
|
@quiet = args.delete(:quiet) || false
|
12
24
|
@lastore = File.expand_path(args.delete(:lastore)|| "~/.config/lapack")
|
@@ -17,6 +29,9 @@ module LaPack
|
|
17
29
|
raise "Unknown args #{args.keys.join(', ')}" unless args.keys.empty?
|
18
30
|
end
|
19
31
|
|
32
|
+
##
|
33
|
+
# Check if loggin is turned on
|
34
|
+
#
|
20
35
|
def quiet?
|
21
36
|
@quiet
|
22
37
|
end
|
@@ -28,28 +43,41 @@ module LaPack
|
|
28
43
|
File.join(@lastore, ladb)
|
29
44
|
end
|
30
45
|
|
46
|
+
##
|
47
|
+
# Returns db object
|
48
|
+
#
|
31
49
|
def db(name)
|
32
50
|
@dbs_hash[name.to_sym]
|
33
51
|
end
|
34
52
|
|
53
|
+
##
|
54
|
+
# Returns list of plugged dbs
|
55
|
+
#
|
35
56
|
def dbs
|
36
57
|
@dbs_hash.keys
|
37
58
|
end
|
38
59
|
|
60
|
+
##
|
61
|
+
# Init db instance in local store
|
62
|
+
#
|
39
63
|
def add(db, params = {})
|
40
64
|
if(db.to_sym.eql?(:ctan))
|
41
65
|
File.open(File.join(dbs_store, "#{db}.db"), "w") {|f| f << {name: 'ctan', clazz: 'CtanProvider', params: {}}.to_json}
|
42
|
-
elsif (db.to_sym.eql?(:github))
|
43
|
-
File.open(File.join(dbs_store, "#{db}.db"), "w") {|f| f << {name: 'github', clazz: 'GithubProvider', params: {}}.to_json}
|
44
66
|
else
|
45
67
|
raise "Unsupported"
|
46
68
|
end
|
47
69
|
end
|
48
70
|
|
71
|
+
##
|
72
|
+
# Check if we support +dbtype+
|
73
|
+
#
|
49
74
|
def supports?(dbtype)
|
50
|
-
(:ctan.eql? dbtype.to_sym)
|
75
|
+
(:ctan.eql? dbtype.to_sym)
|
51
76
|
end
|
52
77
|
|
78
|
+
##
|
79
|
+
# System medthod to init db structure
|
80
|
+
#
|
53
81
|
def dbs_init
|
54
82
|
@dbs_hash = Dir["#{dbs_store}/*.db"]
|
55
83
|
.map do |dbfile|
|
data/lib/lapack.rb
CHANGED
@@ -17,12 +17,23 @@ require 'tmpdir'
|
|
17
17
|
|
18
18
|
ENV['LAPACK'] = File.dirname(File.realpath(__FILE__))
|
19
19
|
|
20
|
-
|
20
|
+
##
|
21
|
+
# Check if we in debug mode or not
|
22
|
+
#
|
23
|
+
DEBUG = false
|
24
|
+
|
25
|
+
##
|
26
|
+
# Current version
|
27
|
+
#
|
28
|
+
Version = [0, 0, 3]
|
29
|
+
|
30
|
+
def lareq path
|
31
|
+
require (DEBUG ? File.join(ENV['LAPACK'], path) : path)
|
32
|
+
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
require "providers/github"
|
34
|
+
lareq "laenv"
|
35
|
+
lareq "providers/provider"
|
36
|
+
lareq "providers/ctan"
|
26
37
|
|
27
38
|
|
28
39
|
module LaPack
|
@@ -37,15 +48,17 @@ module LaPack
|
|
37
48
|
plain: "%s"
|
38
49
|
}
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
## laenv - окружение, в котором работаем
|
51
|
+
##
|
52
|
+
# Get data from +url+ and save it to +dst+
|
53
|
+
#
|
44
54
|
def LaPack.get(url, dst)
|
45
55
|
log("Fetching #{url.white.bold} to #{dst.white.bold}")
|
46
56
|
File.open(dst, "w"){|f| f << LaPack.gets(url)}
|
47
57
|
end
|
48
58
|
|
59
|
+
##
|
60
|
+
# Get data from +url+ and return it as string
|
61
|
+
#
|
49
62
|
def LaPack.gets(url)
|
50
63
|
open(url).read
|
51
64
|
end
|
@@ -80,6 +93,7 @@ module LaPack
|
|
80
93
|
##
|
81
94
|
# Logging method
|
82
95
|
# TODO: Remove from LaPack module. Move to utils.rb
|
96
|
+
#
|
83
97
|
def LaPack.log(string, level = :info)
|
84
98
|
puts LOG_LEVELS[level] % string unless LENV.quiet? # Do not print anything if quiet
|
85
99
|
end
|
@@ -94,9 +108,8 @@ module LaPack
|
|
94
108
|
##
|
95
109
|
# Install packages.
|
96
110
|
# If last argument from packages list is directory
|
97
|
-
#
|
98
|
-
# else
|
99
|
-
# install to current working dir
|
111
|
+
# install all packages to directory
|
112
|
+
# else install to current working dir
|
100
113
|
#
|
101
114
|
def LaPack.install(db, *packages)
|
102
115
|
raise "Empty package list" unless !packages.last.nil? # No packages specified at all
|
@@ -144,11 +157,64 @@ module LaPack
|
|
144
157
|
end
|
145
158
|
end
|
146
159
|
|
160
|
+
require 'optparse'
|
161
|
+
require 'optparse/time'
|
162
|
+
require 'ostruct'
|
163
|
+
require 'pp'
|
164
|
+
|
165
|
+
class Args
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
#
|
170
|
+
# Return a structure describing the options.
|
171
|
+
#
|
172
|
+
def self.parse(args)
|
173
|
+
# The options specified on the command line will be collected in *options*.
|
174
|
+
# We set default values here.
|
175
|
+
options = OpenStruct.new
|
176
|
+
options.command
|
177
|
+
opt_parser = OptionParser.new do |opts|
|
178
|
+
opts.banner = "Usage: lapack [command] [command_args]..."
|
179
|
+
|
180
|
+
opts.separator ""
|
181
|
+
opts.separator "Commands:"
|
182
|
+
opts.separator "\t add [reponame] -- add repository. Currently supported: ctan"
|
183
|
+
opts.separator "\t update [reponame] -- update repository index."
|
184
|
+
opts.separator "\t install [reponame] [package]... [to_dir] -- install packages from repository to specified directory. If no directory specified use current working dir"
|
185
|
+
opts.separator "\t remove [reponame] [package]... -- remove packages from local cache"
|
186
|
+
opts.separator ""
|
187
|
+
opts.separator "Specific options:"
|
188
|
+
|
189
|
+
# No argument, shows at tail. This will print an options summary.
|
190
|
+
# Try it and see!
|
191
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
192
|
+
puts opts
|
193
|
+
exit
|
194
|
+
end
|
195
|
+
|
196
|
+
# Another typical switch to print the version.
|
197
|
+
opts.on_tail("--version", "Show version") do
|
198
|
+
puts Version.join('.')
|
199
|
+
exit
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
opt_parser.parse!(args)
|
204
|
+
options
|
205
|
+
end # parse()
|
206
|
+
|
207
|
+
end # class Args
|
208
|
+
|
209
|
+
|
210
|
+
|
147
211
|
if (ARGV.empty?)
|
148
212
|
puts "No args passed"
|
149
213
|
else
|
214
|
+
options = Args.parse(ARGV)
|
215
|
+
|
150
216
|
begin
|
151
|
-
LaPack.send(ARGV[0], *ARGV[1..ARGV.length])
|
217
|
+
LaPack.send(ARGV[0], *ARGV[1..ARGV.length]) unless ARGV.empty?
|
152
218
|
rescue NoMethodError => undefined
|
153
219
|
puts "Unknown operation #{undefined.name}"
|
154
220
|
rescue Exception => e
|
data/lib/providers/ctan.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
module LaPack
|
2
2
|
|
3
|
+
##
|
4
|
+
# Provider for packages from ctan.org
|
5
|
+
#
|
3
6
|
class CtanProvider < Provider
|
4
7
|
|
8
|
+
##
|
9
|
+
# Create new Ctan instance.
|
10
|
+
#
|
11
|
+
# No special params expected
|
12
|
+
#
|
5
13
|
def initialize(env, params = {})
|
6
14
|
super env, 'ctan', params
|
7
15
|
|
@@ -11,6 +19,9 @@ module LaPack
|
|
11
19
|
@package_info = 'http://ctan.org/json/pkg/%s'
|
12
20
|
end
|
13
21
|
|
22
|
+
##
|
23
|
+
# Basic initialization of CtanProvider instance
|
24
|
+
#
|
14
25
|
def init(dbdir)
|
15
26
|
# dbdir path
|
16
27
|
@dbdir = dbdir
|
@@ -26,19 +37,37 @@ module LaPack
|
|
26
37
|
raise "Can't write to #{@packages}. Not a directory" unless File.directory?(@packages)
|
27
38
|
end
|
28
39
|
|
40
|
+
##
|
41
|
+
# Update package index
|
42
|
+
#
|
43
|
+
# This will download newer version of package list from ctan.org
|
44
|
+
#
|
29
45
|
def update
|
30
46
|
LaPack.get(@package_list, @index)
|
31
47
|
end
|
32
48
|
|
49
|
+
##
|
50
|
+
# List packages from ctan archive
|
51
|
+
#
|
33
52
|
def list
|
34
53
|
raise "Update db first" unless File.exists?(@index)
|
35
54
|
File.open(@index, "r") {|f| JSON.parse(f.read, symbolize_names: true)}
|
36
55
|
end
|
37
56
|
|
57
|
+
##
|
58
|
+
# Show package details
|
59
|
+
#
|
38
60
|
def show(package)
|
39
61
|
JSON.parse(LaPack.gets(@package_info % package), symbolize_names: true)
|
40
62
|
end
|
41
63
|
|
64
|
+
##
|
65
|
+
# Create links for +packages+ at +to_dir+
|
66
|
+
#
|
67
|
+
# If any package not installed, it will be installed after running this command
|
68
|
+
#
|
69
|
+
# TODO: Dry run (no linking just installation) will be implemented
|
70
|
+
#
|
42
71
|
def install(to_dir, *packages)
|
43
72
|
packages.each do |package|
|
44
73
|
LaPack.log("Installing #{package.blue.bold}")
|
@@ -50,6 +79,9 @@ module LaPack
|
|
50
79
|
end
|
51
80
|
end
|
52
81
|
|
82
|
+
##
|
83
|
+
# Remove +packages+ from ctan storage
|
84
|
+
#
|
53
85
|
def remove(*packages)
|
54
86
|
packages.each do |package|
|
55
87
|
LaPack.log("Removing #{package.blue.bold}")
|
data/lib/providers/provider.rb
CHANGED
@@ -54,18 +54,28 @@ module LaPack
|
|
54
54
|
|
55
55
|
##
|
56
56
|
# Shows available packages
|
57
|
+
#
|
57
58
|
def list
|
58
59
|
return []
|
59
60
|
end
|
60
61
|
|
62
|
+
##
|
63
|
+
# Install each package from +packages+
|
64
|
+
#
|
61
65
|
def install(*packages)
|
62
66
|
puts "Dummy implementation. Should install: #{packages.join(",")}"
|
63
67
|
end
|
64
68
|
|
69
|
+
##
|
70
|
+
# Show +package+ details
|
71
|
+
#
|
65
72
|
def show(package)
|
66
73
|
[]
|
67
74
|
end
|
68
75
|
|
76
|
+
##
|
77
|
+
# Delete package from local store
|
78
|
+
#
|
69
79
|
def remove(package)
|
70
80
|
# do nothing
|
71
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lapack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Arkhanhelsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple packaging tool for LaTeX
|
14
14
|
email: ilya.arkhanhelsky@gmail.com
|
@@ -21,9 +21,8 @@ files:
|
|
21
21
|
- lib/laenv.rb
|
22
22
|
- lib/lapack.rb
|
23
23
|
- lib/providers/ctan.rb
|
24
|
-
- lib/providers/github.rb
|
25
24
|
- lib/providers/provider.rb
|
26
|
-
homepage: http://
|
25
|
+
homepage: http://github.com/bsutex/lapack
|
27
26
|
licenses:
|
28
27
|
- Apache
|
29
28
|
metadata: {}
|
data/lib/providers/github.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
module LaPack
|
2
|
-
|
3
|
-
class GithubProvider < Provider
|
4
|
-
|
5
|
-
## Entries per github query page
|
6
|
-
@@PER_PAGE = 100
|
7
|
-
|
8
|
-
def initialize(env, params = {})
|
9
|
-
super env, 'github', params
|
10
|
-
|
11
|
-
@github_db = "https://api.github.com/search/repositories?q=language:tex&page=%d&per_page=#{@@PER_PAGE}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def init(dbdir)
|
15
|
-
# dbdir path
|
16
|
-
@dbdir = dbdir
|
17
|
-
# dbdir name
|
18
|
-
@packages = File.join(dbdir, 'pkg')
|
19
|
-
# Package index
|
20
|
-
@index = File.join(dbdir, "#{@name}.json")
|
21
|
-
|
22
|
-
FileUtils.mkdir_p(@packages) unless File.exists?(@packages)
|
23
|
-
|
24
|
-
raise "Can't write to #{@packages}. Not a directory" unless File.directory?(@packages)
|
25
|
-
end
|
26
|
-
|
27
|
-
def update
|
28
|
-
first_page = JSON.parse(LaPack.gets(@github_db % [ 1 ]), symbolize_names: true)
|
29
|
-
repos_count = first_page[:total_count]
|
30
|
-
pages = (repos_count / @@PER_PAGE) + ((repos_count % @@PER_PAGE) == 0 ? 0 : 1)
|
31
|
-
repos = []
|
32
|
-
|
33
|
-
repos << scan_page(first_page)
|
34
|
-
repos << (2..pages).map do |page|
|
35
|
-
sleep(60 / 5) # Five requests per minute limitation
|
36
|
-
LaPack.log("Getting page #{page} from #{pages}")
|
37
|
-
scan_page(JSON.parse(LaPack.gets(@github_db % [page]), symbolize_names: true))
|
38
|
-
end
|
39
|
-
|
40
|
-
File.open(@index, "w") {|f| f << repos.to_json}
|
41
|
-
end
|
42
|
-
|
43
|
-
def scan_page(page)
|
44
|
-
page[:items].map{|item| item.select{|k, v| [:html_url, :name, :description, :git_url, :full_name].include?(k)}}
|
45
|
-
end
|
46
|
-
|
47
|
-
def list
|
48
|
-
LaPack.log("Unavailable", :warning)
|
49
|
-
end
|
50
|
-
|
51
|
-
def show(package)
|
52
|
-
LaPack.log("Unavailable", :warning)
|
53
|
-
end
|
54
|
-
|
55
|
-
def install(to_dir, *packages)
|
56
|
-
packages.each do |package|
|
57
|
-
LaPack.log("Installing #{package.blue.bold}")
|
58
|
-
if list.select{|p| p[:name].eql?(package)}.empty?
|
59
|
-
raise "No such package #{package.white.bold}"
|
60
|
-
else
|
61
|
-
install_package(package, to_dir)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def remove(*packages)
|
67
|
-
packages.each do |package|
|
68
|
-
LaPack.log("Removing #{package.blue.bold}")
|
69
|
-
if list.select{|p| p[:name].eql?(package)}.empty?
|
70
|
-
raise "No such package #{package.white.bold}"
|
71
|
-
else
|
72
|
-
ctan_remove(package)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
##
|
79
|
-
# Install package routine
|
80
|
-
#
|
81
|
-
def install_package(package, to_dir)
|
82
|
-
|
83
|
-
package_dir = File.join(@packages, package)
|
84
|
-
FileUtils.mkdir_p(package_dir)
|
85
|
-
package_info = show(package)
|
86
|
-
# If exists #{package}.json - we already have some version of
|
87
|
-
# package. So check version and go ahead.
|
88
|
-
package_info_store = File.join(package_dir, "#{package}.json")
|
89
|
-
current = {}
|
90
|
-
if (File.exists?(package_info_store))
|
91
|
-
current = JSON.parse(File.open(package_info_store){|f| f.read}, symbolize_names: true)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Current does not exists or is out of date
|
95
|
-
# (assuming we always had newer version @ CTAN. Thats little bit wrong)
|
96
|
-
if current.empty? || !current[:version][:number].eql?(package_info[:version][:number])
|
97
|
-
|
98
|
-
LaPack.log("Updating #{package}: #{current[:version][:number]} ~> #{package_info[:version][:number]}") unless current.empty?
|
99
|
-
|
100
|
-
# Create tmp dir and do make routine
|
101
|
-
Dir.mktmpdir("lapack-#{package}-") do |tmp|
|
102
|
-
stys = []
|
103
|
-
# Currently we can make from :ctan field. That is mostly common case
|
104
|
-
if package_info.has_key?(:ctan)
|
105
|
-
stys = ctan_install(package_info, tmp)
|
106
|
-
elsif package_info.has_key?(:install)
|
107
|
-
LaPack.log("Don't know how to build from install")
|
108
|
-
elsif package_info.has_key?(:texlive)
|
109
|
-
LaPack.log("Don't know how to build from texlive")
|
110
|
-
else
|
111
|
-
raise("Don't know how to build #{package}")
|
112
|
-
end
|
113
|
-
|
114
|
-
# stys contains path list for all artifacts
|
115
|
-
# we'll copy them to package dist dir
|
116
|
-
stys.each{|sty| FileUtils.cp(sty, package_dir)}
|
117
|
-
|
118
|
-
# Flush package info to package dist dir
|
119
|
-
File.open(package_info_store, "w"){|f| f << package_info.to_json}
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Relinking stys
|
124
|
-
LaPack.log("Linking #{package} content to #{to_dir}")
|
125
|
-
Dir["#{package_dir}/*.sty"].each do |sty|
|
126
|
-
FileUtils.ln_s(sty, to_dir, force: true)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def ctan_install(package_info, tmpdir)
|
131
|
-
# Place were package archive stored @ CTAN
|
132
|
-
link = (@ctan_fetch % package_info[:ctan][:path]) + ".zip"
|
133
|
-
|
134
|
-
arch = File.join(tmpdir, "#{package_info[:name]}.zip")
|
135
|
-
# Unpack archive
|
136
|
-
LaPack.get(link, arch)
|
137
|
-
`unzip #{arch} -d #{File.join(tmpdir, "src")}`
|
138
|
-
Dir["#{tmpdir}/**/*.ins"].each do |ins|
|
139
|
-
# And do latex on each *.ins file
|
140
|
-
Dir.chdir(File.dirname(ins)) do |dir|
|
141
|
-
LaPack.log("LaTex on #{ins}")
|
142
|
-
system "latex #{ins}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
# Return list of *.sty
|
146
|
-
Dir["#{tmpdir}/**/*.sty"]
|
147
|
-
end
|
148
|
-
|
149
|
-
def ctan_remove(package)
|
150
|
-
package_dir = File.join(@packages, package)
|
151
|
-
FileUtils.rm_r(package_dir)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|