changeset 28:7c82ffbca5d0

py3 and k8s upgrade
author drewp@bigasterisk.com
date Sun, 12 Jul 2020 13:16:33 -0700
parents 3d9dc1571ade
children 890584020372
files jadestache.py link.py lookup.py makefile pagetitle.py pydeps run template/add.jade.mustache template/links.jade.mustache
diffstat 9 files changed, 26 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/jadestache.py	Sat Dec 24 20:19:23 2016 -0800
+++ b/jadestache.py	Sun Jul 12 13:16:33 2020 -0700
@@ -19,7 +19,7 @@
         if encoding is None:
             encoding = self.file_encoding
 
-        src = self.unicode(b, encoding)
+        src = self.str(b, encoding)
 
         expanded = pyjade.utils.process(src)
         self.seen[path] = expanded
@@ -45,7 +45,7 @@
     def _new_loader(self):
         return _JadeLoader(
                 file_encoding=self.file_encoding, extension=self.file_extension,
-                to_unicode=self.unicode, search_dirs=self.search_dirs)
+                to_unicode=self.str, search_dirs=self.search_dirs)
         
     def _make_loader(self):
         if self._loader is not None:
--- a/link.py	Sat Dec 24 20:19:23 2016 -0800
+++ b/link.py	Sun Jul 12 13:16:33 2020 -0700
@@ -1,4 +1,4 @@
-import urlparse, urllib
+import urllib.parse, urllib.request, urllib.parse, urllib.error
 from dateutil.tz import tzlocal
 
 class NotFound(ValueError):
@@ -47,8 +47,8 @@
             out['displayDescription'] = out['description']
 
         out['tagWords'] = [{'word' : w} for w in out['tag'].split(None)]
-        out['domain'] = urlparse.urlparse(out['href']).netloc
-        out['editLink'] = 'addLink?' + urllib.urlencode([('url', out['href'])])
+        out['domain'] = urllib.parse.urlparse(out['href']).netloc
+        out['editLink'] = 'addLink?' + urllib.parse.urlencode([('url', out['href'])])
         out['shareWith'] = [{'label' : uri} for uri in doc.get('shareWith', [])]
         return out
 
@@ -61,7 +61,7 @@
             extended=data.extended,
             href=data.href,
             private=data.private,
-            shareWith=filter(None, data.shareWith.split(',')),
+            shareWith=[_f for _f in data.shareWith.split(',') if _f],
             tag=data.tag,
             t=t,
         )
--- a/lookup.py	Sat Dec 24 20:19:23 2016 -0800
+++ b/lookup.py	Sun Jul 12 13:16:33 2020 -0700
@@ -8,27 +8,27 @@
 and the add-bookmark stuff
 
 """
-import pymongo, bottle, time, urllib, datetime, json, restkit, logging
+import pymongo, bottle, time, urllib.request, urllib.parse, urllib.error, datetime, json, logging
+import requests
 from collections import defaultdict
-from urllib2 import urlparse
+from urllib.parse import urlparse
 from dateutil.tz import tzlocal
 from bottle import static_file
 from jadestache import Renderer
 from pagetitle import PageTitle
 from link import Links, NotFound
-db = pymongo.Connection('bang', tz_aware=True)['href']
+db = pymongo.Connection('mongodb.default.svc.cluster.local', tz_aware=True)['href']
 pageTitle = PageTitle(db)
 links = Links(db)
 renderer = Renderer(search_dirs=['template'], debug=bottle.DEBUG)
 log = logging.getLogger()
 
 def getLoginBar():
-    openidProxy = restkit.Resource("http://bang:9023/")
-    return openidProxy.get("_loginBar",
+    return requests.get("http://openid-proxy.default.svc.cluster.local:9023/_loginBar",
                            headers={
                                "Cookie" : bottle.request.headers.get('cookie'),
                                'x-site': 'http://bigasterisk.com/openidProxySite/href',
-                           }).body_string()
+                           }).text
 
 def getUser():
     agent = bottle.request.headers.get('x-foaf-agent', None)
@@ -70,8 +70,8 @@
             continue
         for t in docTags.difference(withTags):
             count[t] = count[t] + 1
-    byFreq = [(n, t) for t,n in count.iteritems()]
-    byFreq.sort(key=lambda (n,t): (-n, t))
+    byFreq = [(n, t) for t,n in count.items()]
+    byFreq.sort(key=lambda n_t: (-n_t[0], n_t[1]))
     return [{'label': t, 'count': n} for n, t in byFreq]
     
 def renderWithTime(name, data):
@@ -126,7 +126,7 @@
 @bottle.route('/tags')
 def tagFilterComplete():
     params = bottle.request.params
-    haveTags = filter(None, params['have'].split(','))
+    haveTags = [_f for _f in params['have'].split(',') if _f]
     if haveTags and len(haveTags[-1]) > 0:
         haveTags, partialTerm = haveTags[:-1], haveTags[-1]
     else:
@@ -145,7 +145,7 @@
     
 @bottle.route('/<user>/')
 def userSlash(user):
-    bottle.redirect(siteRoot() + "/%s" % urllib.quote(user))
+    bottle.redirect(siteRoot() + "/%s" % urllib.parse.quote(user))
 
 @bottle.route('/<user>.json', method='GET')
 def userAllJson(user):
@@ -162,19 +162,19 @@
 def userAddLink(user):
     if getUser()[0] != user:
         raise ValueError("not logged in as %s" % user)
-    print repr(bottle.request.params.__dict__)
+    print(repr(bottle.request.params.__dict__))
     doc = links.fromPostdata(bottle.request.params,
                              user,
                              datetime.datetime.now(tzlocal()))
     links.insertOrUpdate(doc)
 
-    print "notify about sharing to", repr(doc['shareWith'])
+    print("notify about sharing to", repr(doc['shareWith']))
         
     bottle.redirect(siteRoot() + '/' + user)
 
 def parseTags(tagComponent):
     # the %20 is coming from davis.js, not me :(
-    return filter(None, tagComponent.replace("%20", "+").split('+'))
+    return [_f for _f in tagComponent.replace("%20", "+").split('+') if _f]
     
 @bottle.route('/<user>/<tags:re:.*>.json')
 def userLinksJson(user, tags):
--- a/makefile	Sat Dec 24 20:19:23 2016 -0800
+++ b/makefile	Sun Jul 12 13:16:33 2020 -0700
@@ -1,7 +1,4 @@
-all: bin/python static/lib/jquery-1.9.1.min.js static/lib/knockout-2.2.1.js static/lib/select2 static/lib/async-2013-03-17.js static/lib/jquery.rdfquery.rdfa.min-1.0.js static/lib/RDFa.min.0.21.0.js
-
-bin/python:
-	bin/pip install -r pydeps
+all: static/lib/jquery-1.9.1.min.js static/lib/knockout-2.2.1.js static/lib/select2 static/lib/async-2013-03-17.js static/lib/jquery.rdfquery.rdfa.min-1.0.js static/lib/RDFa.min.0.21.0.js
 
 static/lib/jquery-1.9.1.min.js:
 	curl -o $@ http://code.jquery.com/jquery-1.9.1.min.js
--- a/pagetitle.py	Sat Dec 24 20:19:23 2016 -0800
+++ b/pagetitle.py	Sun Jul 12 13:16:33 2020 -0700
@@ -35,7 +35,7 @@
         if doc is None:
             try:
                 title = self.getPageTitleNow(uri)
-            except CantGetTitle, e:
+            except CantGetTitle as e:
                 return str(e)
             doc = {'_id': uri, 'title' : title,
                    'getTime':datetime.datetime.now(tzlocal())}
--- a/pydeps	Sat Dec 24 20:19:23 2016 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-BeautifulSoup==3.2.1
-CherryPy==3.2.2
-argparse==1.2.1
-bottle==0.11.6
-cssselect==0.7.1
-distribute==0.6.24
-gunicorn==0.17.2
-http-parser==0.8.1
-ipython==0.13.1
-lxml==3.1.0
-pyjade==2.0
-pymongo==2.4.2
-pystache==0.5.3
-python-dateutil==2.1
-requests==1.1.0
-restkit==4.2.1
-six==1.2.0
-socketpool==0.5.2
-wsgiref==0.1.2
--- a/run	Sat Dec 24 20:19:23 2016 -0800
+++ b/run	Sun Jul 12 13:16:33 2020 -0700
@@ -1,2 +1,3 @@
 #!/bin/sh
-exec bin/python lookup.py
+echo "nameserver 10.43.0.10" > /etc/resolv.conf
+exec python3 lookup.py
--- a/template/add.jade.mustache	Sat Dec 24 20:19:23 2016 -0800
+++ b/template/add.jade.mustache	Sun Jul 12 13:16:33 2020 -0700
@@ -42,8 +42,8 @@
     {{> bookmarklets.jade}}
           
     script
-      var toRoot = "{{toRoot}}", user = "{{user}}";
+      | var toRoot = "{{toRoot}}", user = "{{user}}";
     {{> tail.jade}}
     script(src="{{toRoot}}/static/add.js")
     script
-      model.linkRecord.href({{{fillHrefJson}}})
+      | model.linkRecord.href({{{fillHrefJson}}})
--- a/template/links.jade.mustache	Sat Dec 24 20:19:23 2016 -0800
+++ b/template/links.jade.mustache	Sun Jul 12 13:16:33 2020 -0700
@@ -23,6 +23,6 @@
 
     p.stats {{stats}}
     script
-      var toRoot = "{{toRoot}}", user = "{{user}}";
+      | var toRoot = "{{toRoot}}", user = "{{user}}";
     {{> tail.jade}}
     script(src="{{toRoot}}/static/links.js")