Merge lp:~facundo/u1sync/more-generations into lp:u1sync

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 8
Merged at revision: 8
Proposed branch: lp:~facundo/u1sync/more-generations
Merge into: lp:u1sync
Diff against target: 94 lines (+21/-31)
1 file modified
u1sync/client.py (+21/-31)
To merge this branch: bzr merge lp:~facundo/u1sync/more-generations
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+167835@code.launchpad.net

Commit message

Get the content of the dir not using GetContent.

Description of the change

Get the content of the dir not using GetContent.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1sync/client.py'
2--- u1sync/client.py 2013-05-27 14:22:00 +0000
3+++ u1sync/client.py 2013-06-06 19:12:23 +0000
4@@ -1,11 +1,4 @@
5-# u1sync.client
6-#
7-# Client/protocol end of u1sync
8-#
9-# Author: Lucio Torre <lucio.torre@canonical.com>
10-# Author: Tim Cole <tim.cole@canonical.com>
11-#
12-# Copyright 2009 Canonical Ltd.
13+# Copyright 2009-2013 Canonical
14 #
15 # This program is free software: you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License version 3, as published
17@@ -18,6 +11,7 @@
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22 """Pretty API for protocol client."""
23
24 from __future__ import with_statement
25@@ -45,8 +39,9 @@
26 from ubuntuone.storageprotocol.client import (
27 StorageClientFactory, StorageClient)
28 from ubuntuone.storageprotocol import request, volumes
29-from ubuntuone.storageprotocol.dircontent_pb2 import \
30- DirectoryContent, DIRECTORY
31+from ubuntuone.storageprotocol.delta import DIRECTORY as delta_DIR
32+from ubuntuone.storageprotocol.dircontent_pb2 import DIRECTORY, FILE
33+
34 import uuid
35 import logging
36 from logging.handlers import RotatingFileHandler
37@@ -458,9 +453,7 @@
38 content_hash = hashes.get(root_uuid, None)
39 if content_hash is None:
40 raise KeyError, "Content hash not available"
41- entries = yield self._get_raw_dir_entries(share_uuid,
42- root_uuid,
43- content_hash)
44+ entries = yield self._get_dir_entries(share_uuid, root_uuid)
45 match_name = name.decode('utf-8')
46 match = None
47 for entry in entries:
48@@ -526,9 +519,7 @@
49 immediate children.
50
51 """
52- entries = yield self._get_raw_dir_entries(share_uuid,
53- parent_uuid,
54- parent_content_hash)
55+ entries = yield self._get_dir_entries(share_uuid, parent_uuid)
56 children = {}
57 for entry in entries:
58 if should_sync(entry.name):
59@@ -556,21 +547,20 @@
60 return root
61
62 @log_timing
63- def _get_raw_dir_entries(self, share_uuid, node_uuid, content_hash):
64- """Gets raw dir entries for the given directory."""
65- d = self.factory.current_protocol.get_content(share_str(share_uuid),
66- str(node_uuid),
67- content_hash)
68- d.addCallback(lambda c: zlib.decompress(c.data))
69-
70- def _parse_content(raw_content):
71- """Parses directory content into a list of entry objects."""
72- unserialized_content = DirectoryContent()
73- unserialized_content.ParseFromString(raw_content)
74- return list(unserialized_content.entries)
75-
76- d.addCallback(_parse_content)
77- return d
78+ @defer.inlineCallbacks
79+ def _get_dir_entries(self, share_uuid, node_uuid):
80+ """Get raw dir entries for the given directory."""
81+ result = yield self.factory.current_protocol.get_delta(
82+ share_str(share_uuid), from_scratch=True)
83+ node_uuid = share_str(node_uuid)
84+ children = []
85+ for n in result.response:
86+ if n.parent_id == node_uuid:
87+ # adapt here some attrs so we don't need to change ALL the code
88+ n.node_type = DIRECTORY if n.file_type == delta_DIR else FILE
89+ n.node = n.node_id
90+ children.append(n)
91+ defer.returnValue(children)
92
93 @log_timing
94 def download_string(self, share_uuid, node_uuid, content_hash):

Subscribers

People subscribed via source and target branches