[open-ils-commits] r1313 - in servres/trunk/conifer: integration plumbing (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Apr 2 21:52:55 EDT 2011
Author: gfawcett
Date: 2011-04-02 21:52:54 -0400 (Sat, 02 Apr 2011)
New Revision: 1313
Added:
servres/trunk/conifer/plumbing/memoization.py
Removed:
servres/trunk/conifer/integration/clew-memberships
servres/trunk/conifer/integration/clew-sections-for-site
servres/trunk/conifer/integration/memoization.py
Modified:
servres/trunk/conifer/integration/evergreen_site.py
servres/trunk/conifer/integration/uwindsor_campus_info.py
Log:
cleanup
for uwindsor,
CAMPUS_INFO_SERVICE = 'http://fawcett.medialab.uwindsor.ca/campus-info/'
Deleted: servres/trunk/conifer/integration/clew-memberships
===================================================================
--- servres/trunk/conifer/integration/clew-memberships 2011-04-03 01:52:50 UTC (rev 1312)
+++ servres/trunk/conifer/integration/clew-memberships 2011-04-03 01:52:54 UTC (rev 1313)
@@ -1,53 +0,0 @@
-#!/usr/local/bin/python-oracle-cgi-wrapper
-# -*- mode: python -*-
-
-import os
-import cgi
-import cx_Oracle
-import simplejson
-import re
-
-CONN_STRING = '***/***@********'
-conn = cx_Oracle.connect(CONN_STRING)
-#import cgitb; cgitb.enable(display=True)
-
-def memberships(uid):
- q = ("select realm_id, role_name, S.title, DBMS_LOB.SUBSTR(P.value, 64) "
- "from sakai_realm_rl_gr G "
- "left join sakai_realm R on G.realm_key = R.realm_key "
- "left join sakai_user_id_map M on G.user_id=M.user_id "
- "left join sakai_site S on S.site_id = substr(R.realm_id, 7) "
- "left join sakai_realm_role RR on G.role_key = RR.role_key "
- "left join sakai_site_property P on P.site_id = S.site_id and P.name='term_code' "
- "where eid=:1 and active=1 "
- "and regexp_like(realm_id, '^/site/.{36}$') ")
- cursor = conn.cursor()
- cursor.execute(q, (uid,))
- coursepat = re.compile(r'^(\d\d-\d\d-\d\d\d)')
- for realm, role, title, term in cursor.fetchall():
- site = realm[6:]
- tmp = coursepat.match(title)
- course = tmp and tmp.group(1) or None
- # term: convert 'W08+S08' to ['2008W', '2008S']
- try:
- terms = ['20%s%s' % (t[-2:], t[0]) for t in term.split('+')]
- except:
- terms = []
- yield {'site': site, 'role': role, 'title': title, 'terms': terms,
- 'course': course}
-
-form = cgi.FieldStorage()
-uid = form['uid'].value
-compress = 'deflate' in os.environ.get('HTTP_ACCEPT_ENCODING', '')
-resp = simplejson.dumps(list(memberships(uid)))
-
-print 'Status: 200 OK'
-print 'Content-Type: application/json'
-if compress:
- import zlib
- print 'Content-Encoding: deflate'
- print
- print zlib.compress(resp)
-else:
- print
- print resp
Deleted: servres/trunk/conifer/integration/clew-sections-for-site
===================================================================
--- servres/trunk/conifer/integration/clew-sections-for-site 2011-04-03 01:52:50 UTC (rev 1312)
+++ servres/trunk/conifer/integration/clew-sections-for-site 2011-04-03 01:52:54 UTC (rev 1313)
@@ -1,37 +0,0 @@
-#!/usr/local/bin/python-oracle-cgi-wrapper
-# -*- mode: python -*-
-
-import os
-import cx_Oracle
-import simplejson as json
-import cgitb
-#cgitb.enable(display=True)
-
-CONN_STRING = '***/***@********'
-conn = cx_Oracle.connect(CONN_STRING)
-
-try:
- siteid = os.environ['PATH_INFO'][1:]
- assert len(siteid) == 36, 'malformed site id'
-
- cursor = conn.cursor()
- query = """
- select provider_id from sakai_realm
- where realm_id like '/site/' || :1
- """
- cursor.execute(query, (siteid,))
- try:
- provider_id = cursor.fetchone()[0] or ''
- except:
- raise Exception('site ID not found.')
-
- providers = provider_id.split('+')
- output = json.dumps({'status':'ok', 'siteid': siteid, 'providers': providers})
-except Exception, e:
- output = {'status':'error', 'error': str(e)}
-
-print 'Status: 200 OK'
-print 'Content-Type: application/json'
-print
-print output
-conn.close()
Modified: servres/trunk/conifer/integration/evergreen_site.py
===================================================================
--- servres/trunk/conifer/integration/evergreen_site.py 2011-04-03 01:52:50 UTC (rev 1312)
+++ servres/trunk/conifer/integration/evergreen_site.py 2011-04-03 01:52:54 UTC (rev 1313)
@@ -4,8 +4,8 @@
from conifer.libsystems.evergreen import item_status as I
from conifer.libsystems.evergreen.support import initialize, E1
from conifer.libsystems.z3950 import pyz3950_search as PZ
+from conifer.plumbing.memoization import memoize
from django.conf import settings
-from memoization import memoize
from xml.etree import ElementTree as ET
import re
import time
Deleted: servres/trunk/conifer/integration/memoization.py
===================================================================
--- servres/trunk/conifer/integration/memoization.py 2011-04-03 01:52:50 UTC (rev 1312)
+++ servres/trunk/conifer/integration/memoization.py 2011-04-03 01:52:54 UTC (rev 1313)
@@ -1,39 +0,0 @@
-# http://code.activestate.com/recipes/325905/ (r5)
-# Recipe 325905: Memoize Decorator with Timeout (Python), by "S W"
-#
-import time
-
-class memoize(object):
- """Memoize With Timeout"""
- _caches = {}
- _timeouts = {}
-
- def __init__(self,timeout=2):
- self.timeout = timeout
-
- def collect(self):
- """Clear cache of results which have timed out"""
- for func in self._caches:
- cache = {}
- for key in self._caches[func]:
- if (time.time() - self._caches[func][key][1]) < self._timeouts[func]:
- cache[key] = self._caches[func][key]
- self._caches[func] = cache
-
- def __call__(self, f):
- self.cache = self._caches[f] = {}
- self._timeouts[f] = self.timeout
-
- def func(*args, **kwargs):
- kw = sorted(kwargs.items())
- key = (args, tuple(kw))
- try:
- v = self.cache[key]
- if (time.time() - v[1]) > self.timeout:
- raise KeyError
- except KeyError:
- v = self.cache[key] = f(*args,**kwargs),time.time()
- return v[0]
- func.func_name = f.func_name
-
- return func
Modified: servres/trunk/conifer/integration/uwindsor_campus_info.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor_campus_info.py 2011-04-03 01:52:50 UTC (rev 1312)
+++ servres/trunk/conifer/integration/uwindsor_campus_info.py 2011-04-03 01:52:54 UTC (rev 1313)
@@ -1,14 +1,12 @@
from urllib2 import *
from django.utils import simplejson
+from django.conf import settings
-CAMPUS_INFO_SERVICE = 'http://fawcett.medialab.uwindsor.ca/campus-info/'
-
def call(name, *args):
- url = '%s%s?%s' % (CAMPUS_INFO_SERVICE, name, simplejson.dumps(args))
+ url = '%s%s?%s' % (settings.CAMPUS_INFO_SERVICE, name, simplejson.dumps(args))
raw = urlopen(url).read()
return simplejson.loads(raw)
if __name__ == '__main__':
print call('methods_supported')
print call('person_lookup', 'fawcett')
- print call('membership_ids', 'dunn15')
Copied: servres/trunk/conifer/plumbing/memoization.py (from rev 1312, servres/trunk/conifer/integration/memoization.py)
===================================================================
--- servres/trunk/conifer/plumbing/memoization.py (rev 0)
+++ servres/trunk/conifer/plumbing/memoization.py 2011-04-03 01:52:54 UTC (rev 1313)
@@ -0,0 +1,39 @@
+# http://code.activestate.com/recipes/325905/ (r5)
+# Recipe 325905: Memoize Decorator with Timeout (Python), by "S W"
+#
+import time
+
+class memoize(object):
+ """Memoize With Timeout"""
+ _caches = {}
+ _timeouts = {}
+
+ def __init__(self,timeout=2):
+ self.timeout = timeout
+
+ def collect(self):
+ """Clear cache of results which have timed out"""
+ for func in self._caches:
+ cache = {}
+ for key in self._caches[func]:
+ if (time.time() - self._caches[func][key][1]) < self._timeouts[func]:
+ cache[key] = self._caches[func][key]
+ self._caches[func] = cache
+
+ def __call__(self, f):
+ self.cache = self._caches[f] = {}
+ self._timeouts[f] = self.timeout
+
+ def func(*args, **kwargs):
+ kw = sorted(kwargs.items())
+ key = (args, tuple(kw))
+ try:
+ v = self.cache[key]
+ if (time.time() - v[1]) > self.timeout:
+ raise KeyError
+ except KeyError:
+ v = self.cache[key] = f(*args,**kwargs),time.time()
+ return v[0]
+ func.func_name = f.func_name
+
+ return func
More information about the open-ils-commits
mailing list