Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pep8

  • Loading branch information...
commit 257bddfef70e4a6679a2bf94b5d38be3cf673149 1 parent be5cc32
@wraithan wraithan authored
View
6 bin/client.py
@@ -25,9 +25,7 @@
import slumber
api = slumber.API("http://localhost:8000/api/v1/")
-
-LIMIT=500
-
+LIMIT = 500
test_data = [
["rtd", "http://readthedocs.org"],
["google", "http://google.com"],
@@ -61,7 +59,7 @@
print ret['slug']
if sys.argv[1] == 'delete':
- ret = api.hydra.get(limit=LIMIT)
+ ret = api.hydra.get(limit=LIMIT)
for ret in ret['objects']:
slug = ret['slug']
print slug,
View
12 src/hydra/api.py
@@ -14,26 +14,33 @@
r = redis.StrictRedis.from_url(settings.REDIS_URL)
+
def make_slug(val, version="latest"):
return "hydra:v1:redirects:%s:%s" % (version, val)
+
def remove_slug(val, version="latest"):
return val.replace("hydra:v1:redirects:%s:" % version, "")
+
def save(slug, url, version="latest"):
redis_slug = make_slug(slug, version)
return r.zincrby(redis_slug, url, 1)
#r.set(redis_slug, urls)
+
def get_range(pk, withscores=True):
return r.zrange(make_slug(pk), 0, -1, withscores=withscores)
+
def get_keys(key):
return r.keys(make_slug('%s' % key))
+
def delete(slug):
return r.delete(make_slug(slug))
+
def get_urls(slug, count=None):
ret_val = []
# Could have defaulted to -1 but that is a less obvious API
@@ -141,6 +148,9 @@ def obj_delete_list(self, request=None, **kwargs):
r.delete(slug)
def override_urls(self):
+ raw_url = r"^(?P<resource_name>%s)/(?P<pk>^(schema)[^/]+)/$"
return [
- url(r"^(?P<resource_name>%s)/(?P<pk>^(schema)[^/]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
+ url(raw_url % self._meta.resource_name,
+ self.wrap_view('dispatch_detail'),
+ name="api_dispatch_detail"),
]
View
5 src/hydra/management/commands/import.py
@@ -8,14 +8,17 @@
from hydra.api import r, save, make_slug
+
def safe_save(slug, url):
if not r.keys(make_slug(slug)):
save(slug, url)
+
class Command(NoArgsCommand):
def handle_noargs(self, **options):
read(os.path.join(settings.ROOT_DIR, 'django.inv'))
+
def read(file):
urlpattern = 'http://django.readthedocs.org/en/latest/%s'
f = open(file)
@@ -27,7 +30,7 @@ def read(file):
inner_keys = data[top_key].keys()
for inner_key in inner_keys:
#print "INNER KEY: %s" % inner_key
- project, version, url, title = data[top_key][inner_key]
+ project, version, url, title = data[top_key][inner_key]
url_key = url.split('#')[1]
if ":" in url_key:
#This dumps junk data into the url namespace we don't need
View
1  src/zzz/urls.py
@@ -23,4 +23,3 @@
url(r'^_analytics/', include('analytics.urls')),
url(r'^', include('hydra.urls.slug')),
)
-
Please sign in to comment.
Something went wrong with that request. Please try again.