Module: LaPack

Defined in:
lib/laenv.rb,
lib/lapack.rb,
lib/providers/ctan.rb,
lib/providers/github.rb,
lib/providers/provider.rb

Defined Under Namespace

Classes: CtanProvider, GithubProvider, 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

Class Method Details

.add(db, args = {}) ⇒ Object

Add db to local repo. Creates needed structure @ ~/.config/lapack/db



90
91
92
# File 'lib/lapack.rb', line 90

def LaPack.add(db, args={})
  add_db(db, args={})
end

.add_db(name, args = {}) ⇒ Object

Add db by name if supported



76
77
78
# File 'lib/lapack.rb', line 76

def LaPack.add_db(name, args = {})
  LENV.add(name.to_s, args) unless !LENV.supports?(name)
end

.dbsObject

Show installed dbs



126
127
128
129
# File 'lib/lapack.rb', line 126

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

Получаем файл по url и складываем его по имени файла url - вообще говоря uri dst - путь к файлу, в который записываем laenv - окружение, в котором работаем



44
45
46
47
# File 'lib/lapack.rb', line 44

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



49
50
51
# File 'lib/lapack.rb', line 49

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


101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/lapack.rb', line 101

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lapack.rb', line 56

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



83
84
85
# File 'lib/lapack.rb', line 83

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



140
141
142
143
144
# File 'lib/lapack.rb', line 140

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



133
134
135
# File 'lib/lapack.rb', line 133

def LaPack.show(db, package)
  puts JSON.pretty_generate(LENV.db(db).show(package))
end

.update(*dbnames) ⇒ Object

Fetch package index for dbnames



117
118
119
120
121
# File 'lib/lapack.rb', line 117

def LaPack.update(*dbnames)
  dbnames.each do |dbname|
    LENV.db(dbname).update
  end
end