Changeset 6408

Show
Ignore:
Timestamp:
08/19/08 15:26:01 (5 months ago)
Author:
cdent
Message:

tiddlyweb - Implement deletion of bags in the StorageInterface?
and urls.map.

If you delete a bag all the tiddlers in it are _gone_.

This presents some interesting notions with regard to
how search indexes are built and handled. For now we are
just ignoring those issues.

In order for a bag to be delete the delete constraint on
the bag's policy must pass.

We need to handle the situation where a store doesn't support
deletings bags (or whatever else), so a soon commit will
implement some StoreMethodNotImplemented? exceptions, or something
like that. The current hack for bag_delete is to recognize
when a pass has happened, which doesn't map to the style of
the rest of the system.

Location:
Trunk/contributors/ChrisDent/experimental/TiddlyWeb
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/test/test_web_bag.py

    r6247 r6408  
    209209    assert info['policy']['delete'] == policy_dict['delete'] 
    210210 
     211def test_delete_bag(): 
     212    """ 
     213    PUT a new bag to the server and then DELETE it. 
     214    """ 
     215    json_string = simplejson.dumps(dict(policy={})) 
     216 
     217    http = httplib2.Http() 
     218    response, content = http.request('http://our_test_domain:8001/bags/deleteme', 
     219            method='PUT', headers={'Content-Type': 'application/json'}, body=json_string) 
     220    location = response['location'] 
     221 
     222    assert response['status'] == '204' 
     223    assert location == 'http://our_test_domain:8001/bags/deleteme' 
     224 
     225    response, content = http.request(location, method='DELETE') 
     226    print content 
     227    assert response['status'] == '204' 
     228 
     229    response, content = http.request(location, method='GET', headers={'Accept':'application/json'}) 
     230    assert response['status'] == '404' 
     231 
    211232def test_put_bag_wrong_type(): 
    212233    """ 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/stores/__init__.py

    r6121 r6408  
    2727 
    2828    def recipe_put(self, recipe): 
     29        pass 
     30 
     31    def bag_delete(self, bag): 
    2932        pass 
    3033 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/stores/text.py

    r6286 r6408  
    4444 
    4545        recipe_file.close() 
     46 
     47    def bag_delete(self, bag): 
     48        bag_path = self._bag_path(bag.name) 
     49 
     50        try: 
     51            if not os.path.exists(bag_path): 
     52                raise NoBagError, '%s not present' % tiddler_base_filename 
     53            print 'bag_path to delete %s' % bag_path 
     54            shutil.rmtree(bag_path) 
     55            # XXX: We need to return a value so the caller knows 
     56            # that we did something otherwise it will choose 
     57            # to raise a 415. Not satisfied with this solution 
     58            # as it doesn't map to how the rest of the system behaves. 
     59            # Probably need to raise exceptions from the interface.  
     60            return 1 
     61        except NoBagError: 
     62            raise 
     63        except Exception, e: 
     64            raise IOError, 'unable to delete bag %s: %s' % (bag.name, e) 
    4665 
    4766    def bag_get(self, bag): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/web/bag.py

    r6250 r6408  
    1717from tiddlyweb.web.tiddlers import send_tiddlers 
    1818from tiddlyweb.web.http import HTTP400, HTTP404, HTTP415 
     19 
     20def delete(environ, start_response): 
     21    # XXX refactor out a _determine_bag or _determine_bag_name 
     22    # lots of duplication going on here. 
     23    bag_name = environ['wsgiorg.routing_args'][1]['bag_name'] 
     24    bag_name = urllib.unquote(bag_name) 
     25    bag_name = unicode(bag_name, 'utf-8') 
     26    bag_name = web.handle_extension(environ, bag_name) 
     27 
     28    usersign = environ['tiddlyweb.usersign'] 
     29 
     30    bag = _get_bag(environ, bag_name) 
     31    bag.policy.allows(usersign, 'delete') 
     32    # reuse the store attribute that was set on the  
     33    # bag when we "got" it. 
     34    # we don't need to check for existence here because 
     35    # the above get already did 
     36    if bag.store.delete(bag) is not None: 
     37        start_response("204 No Content", []) 
     38        return [] 
     39 
     40    raise HTTP415, 'DELETE not supported' 
    1941 
    2042def get(environ, start_response): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/urls.map

    r5818 r6408  
    8080    GET tiddlyweb.web.bag:get 
    8181    PUT tiddlyweb.web.bag:put 
     82    DELETE tiddlyweb.web.bag:delete 
    8283 
    8384# tiddlers in a bag, with option filter string in the query string