Module: LaPack
- Defined in:
- lib/laenv.rb,
lib/lapack.rb,
lib/providers/ctan.rb,
lib/providers/provider.rb
Defined Under Namespace
Classes: CtanProvider, LaEnv, Provider
Constant Summary collapse
- LENV =
LaEnv.new
- LOG_LEVELS =
TODO: Move in latools or lacore
{ warning: "*\t%s".light_red, info: "*\t".yellow.bold + "%s".blue.bold, succes: "*\t".green.bold + "%s".green, error: "*\t".red.bold + "%s".red.bold, plain: "%s" }
Class Method Summary collapse
-
.add(db, args = {}) ⇒ Object
Add db to local repo.
-
.add_db(name, args = {}) ⇒ Object
Add db by name if supported.
-
.dbs ⇒ Object
Show installed dbs.
-
.get(url, dst) ⇒ Object
Get data from
urland save it todst. -
.gets(url) ⇒ Object
Get data from
urland return it as string. -
.install(db, *packages) ⇒ Object
Install packages.
-
.list(*dbs) ⇒ Object
List available packages for
dbs. -
.log(string, level = :info) ⇒ Object
Logging method TODO: Remove from LaPack module.
-
.remove(db, *packages) ⇒ Object
Remove packages from store.
-
.show(db, package) ⇒ Object
Show package info for
packagefromdb. -
.update(*dbnames) ⇒ Object
Fetch package index for
dbnames.
Class Method Details
.add(db, args = {}) ⇒ Object
Add db to local repo. Creates needed structure @ ~/.config/lapack/db
104 105 106 |
# File 'lib/lapack.rb', line 104 def LaPack.add(db, args={}) add_db(db, args={}) end |
.add_db(name, args = {}) ⇒ Object
Add db by name if supported
89 90 91 |
# File 'lib/lapack.rb', line 89 def LaPack.add_db(name, args = {}) LENV.add(name.to_s, args) unless !LENV.supports?(name) end |
.dbs ⇒ Object
Show installed dbs
139 140 141 142 |
# File 'lib/lapack.rb', line 139 def LaPack.dbs log("Currently plugged dbs:") log(LENV.dbs.map{|d| "\t* %s".white.bold % d}.join("\n"), :plain) end |
.get(url, dst) ⇒ Object
Get data from url and save it to dst
54 55 56 57 |
# File 'lib/lapack.rb', line 54 def LaPack.get(url, dst) log("Fetching #{url.white.bold} to #{dst.white.bold}") File.open(dst, "w"){|f| f << LaPack.gets(url)} end |
.gets(url) ⇒ Object
Get data from url and return it as string
62 63 64 |
# File 'lib/lapack.rb', line 62 def LaPack.gets(url) open(url).read end |
.install(db, *packages) ⇒ Object
Install packages. If last argument from packages list is directory install all packages to directory else install to current working dir
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lapack.rb', line 114 def LaPack.install(db, *packages) raise "Empty package list" unless !packages.last.nil? # No packages specified at all if File.directory?(packages.last) to_dir = packages.last packages = packages[0..(packages.length - 2)] LENV.db(db).install(to_dir, *packages) else LENV.db(db).install('.', *packages) end end |
.list(*dbs) ⇒ Object
List available packages for dbs
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lapack.rb', line 69 def LaPack.list(*dbs) if dbs.length == 1 && dbs.first.eql?("all") # TODO: log("`all` unsupported yet", :warning) else # TODO: More sofisticated pretty pring # TODO: assuming we had json like structure dbs.each do |dbname| LENV.db(dbname).list.each do |entry| printf("%#{-60}s %s\n", "#{dbname.magenta}/#{entry[:name].magenta.bold}", "#{entry[:caption].blue.bold}") end puts puts end end end |
.log(string, level = :info) ⇒ Object
Logging method TODO: Remove from LaPack module. Move to utils.rb
97 98 99 |
# File 'lib/lapack.rb', line 97 def LaPack.log(string, level = :info) puts LOG_LEVELS[level] % string unless LENV.quiet? # Do not print anything if quiet end |
.remove(db, *packages) ⇒ Object
Remove packages from store
153 154 155 156 157 |
# File 'lib/lapack.rb', line 153 def LaPack.remove(db, *packages) raise "Empty package list" unless !packages.last.nil? # No packages specified at all LENV.db(db).remove(*packages) end |
.show(db, package) ⇒ Object
Show package info for package from db
146 147 148 |
# File 'lib/lapack.rb', line 146 def LaPack.show(db, package) puts JSON.pretty_generate(LENV.db(db).show(package)) end |
.update(*dbnames) ⇒ Object
Fetch package index for dbnames
130 131 132 133 134 |
# File 'lib/lapack.rb', line 130 def LaPack.update(*dbnames) dbnames.each do |dbname| LENV.db(dbname).update end end |