Commits

Rodrigo Bistolfi  committed 88502b5

Initial commit

  • Participants

Comments (0)

Files changed (3)

+# Generated by http://gitignore.io
+
+### Ruby ###
+*.gem
+*.rbc
+.bundle
+.config
+coverage
+InstalledFiles
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+
+# YARD artifacts
+.yardoc
+_yardoc
+doc/
+
+### Emacs ###
+*~
+\#*\#
+/.emacs.desktop
+/.emacs.desktop.lock
+.elc
+auto-save-list
+tramp
+.\#*
+
+# Org-mode
+.org-id-locations
+*_archive
+
+### vim ###
+.*.s[a-w][a-z]
+*.un~
+Session.vim
+.netrwhist
+*~
+
+### Linux ###
+.*
+!.gitignore
+*~
+=======
+PVC API
+=======
+
+
+The packages.vectorlinux.com API.
+
+
+::
+
+   GET /
+   
+   API description and entry points
+
+
+::
+   
+   GET /<release>
+
+   Return the available architechtures for <release>
+
+
+::
+
+   GET /<release>/<arch>
+
+   Return the available repositories for the given platform
+
+
+::
+
+   GET /<release>/<arch>/<repository>
+
+   Return all the available packages for the repository
+
+
+::
+
+   GET /<release>/<arch>/<repository>/PACKAGES.TXT
+
+   Return package data in plain text format
+
+
+::
+
+   GET /<release>/<arch>/<repository>/<category>/
+
+   Return available packages in the given category
+
+
+::
+
+   GET /<release>/<arch>/<repository>/<category>/<package>
+
+   Return package data
+
+
+::
+
+   POST /<release>/<arch>/<repository>/<category>/<package>
+   { ... package data ... }
+
+   Create a new package
+
+
+::
+
+   POST /<release>/<arch>/<repository>/<category>/<package>
+   { ... package data ... }
+
+   Update package data
+
+
+::
+
+   DELETE /<release>/<arch>/<repository>/<category>/<package>
+
+   Delete a package
+
+
+The Package data type
+=====================
+
+A *package* object looks like this:
+
+::
+
+   {
+       "Arch": "i586",
+       "Build": 3,
+       "Description": "Document oriented database",
+       "Category": "development",
+       "Name": "CouchDB",
+       "Repository": "extra",
+       "Required": "erlang-otp >= R14, openssl",
+       "Conflicts": "",
+       "Suggests": "",
+       "Release": "7.1",
+       "Version": "1.3.0",
+       "Filename": "CouchDB-1.3.0-i586-3vl71.txz",
+       "Url":, "http://mirror.vl.com/extra/development/",
+       "Md5": "2e1d0773931627e23809b1d0ba52035e",
+       "SizeCompressed": 123KB,
+       "SizeUncompressed": 1234KB
+   }
+require "rubygems"
+require "sinatra"
+require "json"
+require "redis"
+
+
+get "/" do
+    {
+        "releases" => ["7.0", "7.1"]
+    }.to_json
+end
+
+
+get "/:release" do
+    {
+        "arch" => ["x86", "x86_64"]
+    }.to_json
+end
+
+
+get "/:release/:arch" do
+    {
+        "repos" => ["packages", "extra", "testing", "patches", "pool", "attic"]
+    }.to_json
+end
+
+
+get "/:release/:arch/:repo" do
+    {
+        "packages" => []
+    }.to_json
+end
+
+
+get "/:release/:arch/:repo/PACKAGES.TXT" do
+    "PACKAGES.TXT"
+end
+
+
+get "/:release/:arch/:repo/:category" do
+    {
+        params["category"] => []
+    }.to_json
+end
+
+
+post "/:release/:arch/:repo/:category" do
+    data = JSON.parse(request.body.string)
+    pkg = Package.save(data)
+    pkg.to_json
+end
+
+
+get "/:release/:arch/:repo/:category/:name" do
+    pkg = Package.get(params[:name], params[:arch], params[:repo])
+    if pkg.empty? then
+        status 404
+    else
+        pkg.to_json
+    end
+end
+
+
+put "/:release/:arch/:repo/:category/:name" do
+    data = JSON.parse(request.body.string)
+    pkg = Package.update(params[:name], params[:arch], params[:repo], data)
+    if pkg.empty? then
+        status 404
+    else
+        pkg.to_json
+    end
+end
+
+
+delete "/:release/:arch/:repo/:category/:name" do
+    Package.delete(params[:name], params[:arch], params[:repo])
+    status 204
+end
+
+
+class Package
+
+    @redis = Redis.new
+    @prefix = "package"
+
+    def self.get(name, arch, repo)
+        k = "#{@prefix}/#{name}:#{arch}:#{repo}"
+        @redis.hgetall(k)
+    end
+
+    def self.save(json)
+        self.validate(json)
+        k = "#{@prefix}/#{json['name']}:#{json['arch']}:#{json['repository']}"
+        @redis.mapped_hmset(k, json)
+    end
+
+    def self.update(name, arch, repo, json)
+        pkg = self.get(name, arch, repo)
+        pkg.update(json)
+        self.save(pkg)
+        pkg
+    end
+
+    def self.delete(name, arch, repo)
+        if repo != "attic" then
+            pkg = self.get(name, arch, repo)
+            pkg["repository"] = "attic"
+            self.save(pkg)
+        end
+        k = "#{@prefix}/#{name}:#{arch}:#{repo}"
+        @redis.del(k)
+    end
+
+    def self.validate(json)
+        # Raise if invalid
+    end
+end
+