Class: Repositories::Pypi

Inherits:
Base
  • Object
show all
Defined in:
app/models/repositories/pypi.rb

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
false
LIBRARIAN_SUPPORT =
true
SECURITY_PLANNED =
true
URL =
'https://pypi.python.org'
COLOR =
'#3581ba'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED

Class Method Summary collapse

Methods inherited from Base

color, dependencies, download_dependencies, get, get_html, get_json, get_raw, import, import_async, import_new, import_new_async, import_recent, import_recent_async, new_names, package_link, repo_fallback, save, save_dependencies, update

Class Method Details

.formatted_nameObject


10
11
12
# File 'app/models/repositories/pypi.rb', line 10

def self.formatted_name
  'PyPI'
end

.mapping(project) ⇒ Object


30
31
32
33
34
35
36
37
38
39
# File 'app/models/repositories/pypi.rb', line 30

def self.mapping(project)
  {
    :name => project['info']['name'],
    :description => project['info']['summary'],
    :homepage => project['info']['home_page'],
    :keywords_array => Array.wrap(project['info']['keywords'].try(:split, ',')),
    :licenses => project['info']['license'],
    :repository_url => repo_fallback('', project['info']['home_page'])
  }
end

.project(name) ⇒ Object


26
27
28
# File 'app/models/repositories/pypi.rb', line 26

def self.project(name)
  get("https://pypi.python.org/pypi/#{name}/json")
end

.project_namesObject


14
15
16
# File 'app/models/repositories/pypi.rb', line 14

def self.project_names
  get_raw("https://pypi.python.org/simple/").scan(/href='(\w+)'/).flatten
end

.recent_namesObject


18
19
20
21
22
23
24
# File 'app/models/repositories/pypi.rb', line 18

def self.recent_names
  u = 'https://pypi.python.org/pypi?%3Aaction=rss'
  updated = SimpleRSS.parse(Typhoeus.get(u).body).items.map(&:title)
  u = 'https://pypi.python.org/pypi?%3Aaction=packages_rss'
  new_packages = SimpleRSS.parse(Typhoeus.get(u).body).items.map(&:title)
  (updated.map { |t| t.split(' ').first } + new_packages.map { |t| t.split(' ').first }).uniq
end

.versions(project) ⇒ Object


41
42
43
44
45
46
47
48
# File 'app/models/repositories/pypi.rb', line 41

def self.versions(project)
  project['releases'].select{ |k, v| v != [] }.map do |k, v|
    {
      :number => k,
      :published_at => v[0]['upload_time']
    }
  end
end