[z3-checkins] r45286 - in z3/deliverance/DeliveranceVHoster/trunk: docs dvhoster tests
ianb at codespeak.net
ianb at codespeak.net
Tue Jul 24 00:17:22 CEST 2007
Author: ianb
Date: Tue Jul 24 00:17:21 2007
New Revision: 45286
Modified:
z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt
z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py
z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
Log:
Added an API to delete domains
Modified: z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt Tue Jul 24 00:17:21 2007
@@ -151,6 +151,12 @@
Like ``remote_uris`` you can POST to these locations to add and
remove redirects, without reseting all redirects.
+``/.deliverance/delete``
+
+ POST to this resource (no body required) to delete the domain. The
+ actual data is moved into a directory ``TRASH``, but is no longer
+ visible. You have to clean up these trash directories manually.
+
Python Usage
------------
Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py Tue Jul 24 00:17:21 2007
@@ -1,5 +1,6 @@
import re
import os
+import shutil
from ohm import persist
from ohm import server
from ohm import descriptors
@@ -44,6 +45,16 @@
</rules>
'''
+def unique_filename(dir, base_filename):
+ n = 0
+ suffix = ''
+ while 1:
+ new = os.path.join(dir, base_filename) + suffix
+ if not os.path.exists(new):
+ return new
+ n += 1
+ suffix = '-%s' + n
+
class DomainInfoSet(object):
"""
Represents a set of DomainInfo objects.
@@ -55,6 +66,8 @@
This also handles aliases -- domains that point to other domains.
"""
+ trash_dir = 'TRASH'
+
def __init__(self, dir):
self.dir = dir
if not os.path.exists(self.dir):
@@ -157,6 +170,18 @@
os.rename(old_dir, new_dir)
return self.domain(new_domain_name)
+ def delete_domain(self, domain):
+ if hasattr(domain, 'domain'):
+ # DomainInfo object; get its domain:
+ domain = domain.domain
+ domain = self.normalize(domain)
+ cur_dir = os.path.join(self.dir, domain)
+ trash_dir = os.path.join(self.dir, self.trash_dir)
+ if not os.path.exists(trash_dir):
+ os.makedirs(trash_dir)
+ new_dir = unique_filename(trash_dir, domain)
+ shutil.move(cur_dir, new_dir)
+
class DomainInfo(object):
"""
Represents the information about a single domain.
@@ -249,6 +274,9 @@
domain = property(domain__get, domain__set)
+ def delete_domain(self):
+ self.domain_set.delete_domain(self)
+
class DomainValidator(validators.Regex):
regex = r'^[a-z0-9\-]+|[a-z0-9][a-z0-9\-\.\_]*\.[a-z]+$'
@@ -428,6 +456,12 @@
additional_request_headers = server.JSONSetter(
validator=HeaderValidator())
+ def delete_domain(self, body):
+ self.delete_domain()
+
+ delete = server.Setter(
+ POST=(None, delete_domain))
+
@server.appfactory()
def rules(self):
if not os.path.exists(self.rule_dir):
Modified: z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py Tue Jul 24 00:17:21 2007
@@ -39,6 +39,7 @@
yield (use_api, 'localhost')
yield (rename_site,)
yield (use_api, 'localhost2')
+ yield (delete_site,)
def reset_env():
if os.path.exists(data_filename):
@@ -183,6 +184,15 @@
assert app.get('/.deliverance/domain').body == 'localhost2'
print 'site renamed to localhost2'
+def delete_site():
+ app.extra_environ['HTTP_HOST'] = 'localhost2'
+ res = app.get('/.deliverance/domain')
+ res = app.get('/foo.html', status=404)
+ put('/.deliverance/static/foo.html', 'text')
+ res = app.get('/foo.html')
+ assert res.body == 'text'
+ res = app.post('/.deliverance/delete', '', status=204)
+ res = app.get('/foo.html', status=404)
def setup_module(module):
from paste.script import testapp
More information about the z3-checkins
mailing list