Permalink
Browse files

Undelete developer scripts and move to 'examples' folder.

This reverts commit 2746707.

Now we can delete the 'devel' branch.
  • Loading branch information...
1 parent 4cfc964 commit 5d4dba0ae2ed154f6e3093e2849365923d1bdbea @juster juster committed with OttoAllmendinger Jul 5, 2010
Showing with 472 additions and 0 deletions.
  1. +148 −0 examples/aursearch
  2. +119 −0 examples/query
  3. +205 −0 examples/test
View
@@ -0,0 +1,148 @@
+#!/usr/bin/env lua
+require "socket"
+local zlib = require "zlib"
+local yajl = require "yajl"
+local http = require "socket.http"
+local ltn12 = require "ltn12"
+local url = require "socket.url"
+local results = {}
+--require "luarocks.require"
+--require "profiler"
+local C = {
+ ['black'] = '\27[30m',
+ ['blackbold'] = '\27[30;1m',
+ ['red'] = '\27[31m',
+ ['redbold'] = '\27[31;1m',
+ ['green'] = '\27[32m',
+ ['greenbold'] = '\27[32;1m',
+ ['yellow'] = '\27[33m',
+ ['yellowbold'] = '\27[33;1m',
+ ['blue'] = '\27[34m',
+ ['bluebold'] = '\27[34;1m',
+ ['magenta'] = '\27[35m',
+ ['magentabold'] = '\27[35;1m',
+ ['cyan'] = '\27[36m',
+ ['cyanbold'] = '\27[36;1m',
+ ['white'] = '\27[37m',
+ ['whitebold'] = '\27[37;1m',
+ ['reset'] = '\27[0m',
+}
+
+yajl.to_value = function (string)
+ local result
+ local stack = {
+ function(val) result = val end
+ }
+ local obj_key
+ local events = {
+ value = function(_, val)
+ stack[#stack](val)
+ end,
+ open_array = function()
+ local arr = {}
+ local idx = 1
+ stack[#stack](arr)
+ table.insert(stack, function(val)
+ arr[idx] = val
+ idx = idx + 1
+ end)
+ end,
+ open_object = function()
+ local obj = {}
+ stack[#stack](obj)
+ table.insert(stack, function(val)
+ obj[obj_key] = val
+ end)
+ end,
+ object_key = function(_, val)
+ obj_key = val
+ end,
+ close = function()
+ stack[#stack] = nil
+ end,
+ }
+
+ yajl.parser({ events = events })(string)
+ return result
+end
+
+local aururl = "http://aur.archlinux.org/rpc.php?"
+for k, v in pairs(C) do
+-- C[k] = ""
+end
+local method = {}
+method.search = "type=search&"
+method.info = "type=info&"
+method.msearch = "type=msearch&"
+
+aururl = aururl..method.search.."arg="..url.escape(arg[1])
+
+print(aururl)
+
+
+
+
+
+local r, e = http.request {
+ url = aururl;
+ sink = ltn12.sink.table(results);
+ headers = {
+ ["accept-encoding"] = "gzip";
+ }
+}
+
+--print(table.concat(results))
+local inflated = zlib.inflate(table.concat(results))
+results = inflated:read("*a")
+
+local jsonresults = yajl.to_value(results)
+
+--print(jsonresults)
+local aurpkgs = {}
+for k,v in pairs(jsonresults.results) do
+ --io.write(k, " aur/", v.Name, " ", v.Version,"\n", v.Description, "\n")
+ --for i,w in pairs(v) do
+ -- print(i, w)
+ --end
+ --print(k, v)
+ aurpkgs[v.Name] = {['name'] = v.Name; ['version'] = v.Version; ['description'] = v.Description, ['votes'] = v.NumVotes}
+end
+
+local sorted = {}
+
+function sort(tbl)
+ local t = {}
+ for n in pairs(tbl) do table.insert(t, n) end
+ table.sort(t)
+ local i = 0
+ local iter = function()
+ i = i + 1
+ if t[i] == nil then return nil
+ else return t[i], tbl[t[i]]
+ end
+ end
+ return iter
+end
+
+--[[
+for name, line in sort(aurpkgs) do
+ print(name, line)
+end
+--]]
+function sort2(tbl)
+ local stbl = {}
+ local i = 1
+ for k, v in pairs(tbl) do
+ stbl[i] = v
+ i = i + 1
+ end
+ table.sort(stbl, function(a, b)
+ return tbl[a.name].name < tbl[b.name].name end)
+ return stbl
+end
+--profiler.start("profile")
+sorted = sort2(aurpkgs)
+--profiler.stop()
+for k,v in ipairs(sorted) do
+ io.write(C.yellowbold, k, C.magentabold, " aur/", C.whitebold, v.name, " ", C.greenbold, v.version, C.yellowbold, " (", v.votes, ")\n ",
+ C.reset, v.description, "\n") end
View
@@ -0,0 +1,119 @@
+#!/usr/bin/env lua
+local C = {
+ ['black'] = '\27[30m',
+ ['blackbold'] = '\27[30;1m',
+ ['red'] = '\27[31m',
+ ['redbold'] = '\27[31;1m',
+ ['green'] = '\27[32m',
+ ['greenbold'] = '\27[32;1m',
+ ['yellow'] = '\27[33m',
+ ['yellowbold'] = '\27[33;1m',
+ ['blue'] = '\27[34m',
+ ['bluebold'] = '\27[34;1m',
+ ['magenta'] = '\27[35m',
+ ['magentabold'] = '\27[35;1m',
+ ['cyan'] = '\27[36m',
+ ['cyanbold'] = '\27[36;1m',
+ ['white'] = '\27[37m',
+ ['whitebold'] = '\27[37;1m',
+ ['reset'] = '\27[0m',
+}
+
+--for k, v in pairs(C) do C[k] = '\27[37m' end
+local alpm = require "lualpm"
+
+local dbpath = "/var/lib/pacman"
+local cachedir = "/var/cache/pacman/pkg"
+local root = "/"
+
+alpm.initialize()
+alpm.option_set_root(root)
+alpm.option_set_dbpath(dbpath)
+alpm.option_add_cachedir(cachedir)
+--local pkgcache = {}
+local db_local = alpm.db_register_local()
+local db_extra = alpm.db_register_sync("extra")
+local db_core = alpm.db_register_sync("core")
+local db_comm = alpm.db_register_sync("community")
+
+--local extracache = db_extra:db_get_pkgcache()
+--local corecache = db_core:db_get_pkgcache()
+--local commcache = db_comm:db_get_pkgcache()
+
+local pkgcache = db_local:db_get_pkgcache()
+
+--local caches = { extracache, corecache, commcache }
+local repos = { db_core, db_extra, db_comm }
+--local packages = {}
+
+--for k, db in ipairs(repos) do
+local function hurr()
+ for l, db in ipairs(repos) do
+ local pkgcache = db:db_get_pkgcache()
+ for n, pkg in ipairs(pkgcache) do
+ local name = pkg:pkg_get_name()
+ packages[name] = {}
+ packages[name].repo = db:db_get_name()
+ packages[name].version = pkg:pkg_get_version()
+ if db_local:db_get_pkg(name) then
+ io.write(packages[name].repo .. "/" .. name .. " " .. packages[name].version, "\n")
+ end
+ end
+ end
+end
+
+local function Q()
+ local colors = {
+ ['extra'] = C.greenbold,
+ ['core'] = C.redbold,
+ ['community'] = C.magentabold,
+ }
+ local packages = {}
+ for k, repo in ipairs(repos) do
+ local pkgcache = repo:db_get_pkgcache()
+ for l, pkg in ipairs(pkgcache) do
+ local name = pkg:pkg_get_name()
+ packages[name] = repo:db_get_name()
+ --print(pkg:pkg_get_name())
+ end
+ end
+ for k, pkg in ipairs(pkgcache) do
+ local name = pkg:pkg_get_name()
+ if packages[name] then
+ local color = colors[packages[name]] or C.magentabold
+ io.write(color, packages[name], "/", C.whitebold , name , " " , C.greenbold , pkg:pkg_get_version() , C.reset , "\n")
+ --io.write(color .. packages[name] .. "/" .. C.whitebold .. name .. " " .. C.greenbold .. pkg:pkg_get_version() .. C.reset .. "\n")
+ else
+ io.write(C.yellowbold ,"local/" , C.whitebold , name , " " , C.greenbold , pkg:pkg_get_version() , C.reset , "\n")
+ --io.write(C.yellowbold .."local/" .. C.whitebold .. name .. " " .. C.greenbold.. pkg:pkg_get_version() .. C.reset .. "\n")
+ end
+ end
+end
+Q()
+--[[
+for k, pkg in ipairs(pkgcache) do
+ for l, cache in ipairs(caches) do
+ for j, pkg1 in ipairs(cache) do
+-- table.insert(packages, pkg1:pkg_get_name())
+ local repodb = pkg1:pkg_get_db()
+ local repo = repodb:db_get_name()
+ -- print(pkg:pkg_get_name() .. " " .. pkg:pkg_get_version())
+ end
+ end
+end
+--]]
+-- 01:20 < DigitalKiwi> djszapi: I suppose more specifically I'm wondering if I run db_get_name on a database I got from pkg_get_db on a package that was got from db_get_pkg just what name I'll have...
+
+
+
+
+--[[
+for l, m in ipairs(caches) do
+ for k, v in ipairs(m) do
+ local repo = db_local:db_get_name()
+ print (repo)
+ io.write(v:pkg_get_name().." " ..v:pkg_get_version(), "\n")
+end
+end
+--]]
+alpm.release()
Oops, something went wrong.

0 comments on commit 5d4dba0

Please sign in to comment.