public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Vikraman Choudhury" <vikraman.choudhury@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoostats:master commit in: client/gentoostats/, client/
Date: Mon,  1 Aug 2011 22:24:40 +0000 (UTC)	[thread overview]
Message-ID: <9fc558e2719e01c5ad25e55124e45a662ebb5fc0.vikraman@gentoo> (raw)

commit:     9fc558e2719e01c5ad25e55124e45a662ebb5fc0
Author:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Mon Jul 25 22:22:55 2011 +0000
Commit:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Mon Jul 25 22:22:55 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=9fc558e2

misc fixes

---
 client/gentoostats-cli      |    9 ++-
 client/gentoostats/list.py  |  109 +++++++++++++++++++------------------------
 client/gentoostats/utils.py |   22 +++++++++
 3 files changed, 76 insertions(+), 64 deletions(-)

diff --git a/client/gentoostats-cli b/client/gentoostats-cli
index cee0da1..c8a5222 100755
--- a/client/gentoostats-cli
+++ b/client/gentoostats-cli
@@ -3,9 +3,12 @@
 import sys
 import importlib
 
-actions = {'list':'gentoostats.list', 'search':'gentooostats.search'}
+actions = {
+        'list': 'gentoostats.list',
+        'search': 'gentooostats.search'
+        }
 
-def print_usage():
+def print_usage(actions):
     print 'Usage:', sys.argv[0], '<action>'
     print 'Available actions:'
     for action in actions.keys():
@@ -14,7 +17,7 @@ def print_usage():
 def main():
     argc = len(sys.argv)
     if argc == 1:
-        print_usage()
+        print_usage(actions)
         sys.exit(1)
     try:
         loaded_module = importlib.import_module(actions[sys.argv[1]])

diff --git a/client/gentoostats/list.py b/client/gentoostats/list.py
index 480587c..3cf60cf 100644
--- a/client/gentoostats/list.py
+++ b/client/gentoostats/list.py
@@ -2,34 +2,38 @@
 import sys
 import json
 import httplib
+import utils
 
-objects={
-'arch':'list_arch',
-'feature':'list_feature',
-'lang':'list_lang',
-'mirror':'list_mirror',
-'repo':'list_repo',
-'category':'list_cat',
-}
+objects = {
+        'arch': 'list_arch',
+        'feature': 'list_feature',
+        'lang': 'list_lang',
+        'mirror': 'list_mirror',
+        'repo': 'list_repo',
+        'cat': 'list_cat',
+        'cp': 'list_cp',
+        'cpv': 'list_cpv'
+        }
 
 server = 'soc.dev.gentoo.org'
 url = '/gentoostats'
-headers = {'Accept':'application/json'}
+headers = {'Accept': 'application/json'}
 
-def print_usage():
+def print_usage(objects):
     print 'Usage: list <object>'
     print 'Available objects:'
     for obj in objects.keys():
         print obj
 
-def pprint(object):
+def pprint(title, object):
+    print title
     import pprint
     pprint.pprint(object)
 
 def main(opts):
     l = len(opts)
     if l == 0:
-        print_usage()
+        print_usage(objects)
         sys.exit(1)
 
     if opts[0] not in objects:
@@ -37,61 +41,44 @@ def main(opts):
         sys.exit(1)
 
     try:
-        globals()[objects[opts[0]]]()
+        globals()[objects[opts[0]]](server, url, headers)
     except KeyError:
         sys.stderr.write('Unimplemented')
         sys.exit(1)
 
-def list_arch():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/arch', headers=headers)
-    try:
-        arch_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(arch_data)
+def list(server, url_base, url_extra, headers):
+    get_data = utils.GET(server=server, url=url_base+url_extra, headers=headers)
+    data = utils.deserialize(get_data)
+    return data
 
-def list_feature():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/feature', headers=headers)
-    try:
-        feature_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(feature_data)
+def list_arch(server, url, headers):
+    data = list(server, url, '/arch', headers)
+    pprint('Arch', data)
 
-def list_lang():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/lang', headers=headers)
-    try:
-        lang_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(lang_data)
+def list_feature(server, url, headers):
+    data = list(server, url, '/feature', headers)
+    pprint('Feature', data)
 
-def list_mirror():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/mirror', headers=headers)
-    try:
-        mirror_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(mirror_data)
+def list_lang(server, url, headers):
+    data = list(server, url, '/lang', headers)
+    pprint('Lang', data)
 
-def list_repo():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/mirror', headers=headers)
-    try:
-        repo_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(repo_data)
+def list_mirror(server, url, headers):
+    data = list(server, url, '/mirror', headers)
+    pprint('Mirror', data)
 
-def list_cat():
-    conn = httplib.HTTPSConnection(server)
-    conn.request('GET', url=url+'/package', headers=headers)
-    try:
-        cat_data = json.JSONDecoder().decode(conn.getresponse().read())
-    except ValueError:
-        sys.exit(1)
-    pprint(cat_data)
+def list_repo(server, url, headers):
+    data = list(server, url, '/repo', headers)
+    pprint('Repo', data)
+
+def list_cat(server, url, headers):
+    data = list(server, url, '/package', headers)
+    pprint('Category', data)
+
+def list_cp(server, url, headers):
+    data = list(server, url, '/package', headers)
+    pprint('Category/Package', data)
+
+def list_cpv(server, url, headers):
+    data = list(server, url, '/package', headers)
+    pprint('Category/Package-Version', data)

diff --git a/client/gentoostats/utils.py b/client/gentoostats/utils.py
new file mode 100644
index 0000000..ae520f2
--- /dev/null
+++ b/client/gentoostats/utils.py
@@ -0,0 +1,22 @@
+
+import json
+import httplib
+
+def GET(server, url, headers, https=True):
+    if https:
+        conn = httplib.HTTPSConnection(server)
+    else:
+        conn = httplib.HTTPConnection(server)
+    try:
+        conn.request('GET', url=url, headers=headers)
+        data = conn.getresponse().read()
+    except httplib.HTTPException:
+        return None
+    return data
+
+def deserialize(object):
+    try:
+        decoded = json.JSONDecoder().decode(object)
+    except (ValueError, TypeError):
+        return None
+    return decoded



             reply	other threads:[~2011-08-01 22:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-01 22:24 Vikraman Choudhury [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-04-17 14:15 [gentoo-commits] proj/gentoostats:master commit in: client/gentoostats/, client/ Vikraman Choudhury
2011-08-21 23:15 Vikraman Choudhury
2011-08-01 23:04 Vikraman Choudhury
2011-08-01 22:24 Vikraman Choudhury
2011-07-25 12:35 Vikraman Choudhury
2011-06-23 15:14 Vikraman Choudhury

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9fc558e2719e01c5ad25e55124e45a662ebb5fc0.vikraman@gentoo \
    --to=vikraman.choudhury@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox