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
=== modified file 'u1sync/client.py'
--- u1sync/client.py 2013-05-27 14:22:00 +0000
+++ u1sync/client.py 2013-06-06 19:12:23 +0000
@@ -1,11 +1,4 @@
1# u1sync.client1# Copyright 2009-2013 Canonical
2#
3# Client/protocol end of u1sync
4#
5# Author: Lucio Torre <lucio.torre@canonical.com>
6# Author: Tim Cole <tim.cole@canonical.com>
7#
8# Copyright 2009 Canonical Ltd.
9#2#
10# This program is free software: you can redistribute it and/or modify it3# This program is free software: you can redistribute it and/or modify it
11# under the terms of the GNU General Public License version 3, as published4# under the terms of the GNU General Public License version 3, as published
@@ -18,6 +11,7 @@
18#11#
19# You should have received a copy of the GNU General Public License along12# 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/>.13# with this program. If not, see <http://www.gnu.org/licenses/>.
14
21"""Pretty API for protocol client."""15"""Pretty API for protocol client."""
2216
23from __future__ import with_statement17from __future__ import with_statement
@@ -45,8 +39,9 @@
45from ubuntuone.storageprotocol.client import (39from ubuntuone.storageprotocol.client import (
46 StorageClientFactory, StorageClient)40 StorageClientFactory, StorageClient)
47from ubuntuone.storageprotocol import request, volumes41from ubuntuone.storageprotocol import request, volumes
48from ubuntuone.storageprotocol.dircontent_pb2 import \42from ubuntuone.storageprotocol.delta import DIRECTORY as delta_DIR
49 DirectoryContent, DIRECTORY43from ubuntuone.storageprotocol.dircontent_pb2 import DIRECTORY, FILE
44
50import uuid45import uuid
51import logging46import logging
52from logging.handlers import RotatingFileHandler47from logging.handlers import RotatingFileHandler
@@ -458,9 +453,7 @@
458 content_hash = hashes.get(root_uuid, None)453 content_hash = hashes.get(root_uuid, None)
459 if content_hash is None:454 if content_hash is None:
460 raise KeyError, "Content hash not available"455 raise KeyError, "Content hash not available"
461 entries = yield self._get_raw_dir_entries(share_uuid,456 entries = yield self._get_dir_entries(share_uuid, root_uuid)
462 root_uuid,
463 content_hash)
464 match_name = name.decode('utf-8')457 match_name = name.decode('utf-8')
465 match = None458 match = None
466 for entry in entries:459 for entry in entries:
@@ -526,9 +519,7 @@
526 immediate children.519 immediate children.
527520
528 """521 """
529 entries = yield self._get_raw_dir_entries(share_uuid,522 entries = yield self._get_dir_entries(share_uuid, parent_uuid)
530 parent_uuid,
531 parent_content_hash)
532 children = {}523 children = {}
533 for entry in entries:524 for entry in entries:
534 if should_sync(entry.name):525 if should_sync(entry.name):
@@ -556,21 +547,20 @@
556 return root547 return root
557548
558 @log_timing549 @log_timing
559 def _get_raw_dir_entries(self, share_uuid, node_uuid, content_hash):550 @defer.inlineCallbacks
560 """Gets raw dir entries for the given directory."""551 def _get_dir_entries(self, share_uuid, node_uuid):
561 d = self.factory.current_protocol.get_content(share_str(share_uuid),552 """Get raw dir entries for the given directory."""
562 str(node_uuid),553 result = yield self.factory.current_protocol.get_delta(
563 content_hash)554 share_str(share_uuid), from_scratch=True)
564 d.addCallback(lambda c: zlib.decompress(c.data))555 node_uuid = share_str(node_uuid)
565556 children = []
566 def _parse_content(raw_content):557 for n in result.response:
567 """Parses directory content into a list of entry objects."""558 if n.parent_id == node_uuid:
568 unserialized_content = DirectoryContent()559 # adapt here some attrs so we don't need to change ALL the code
569 unserialized_content.ParseFromString(raw_content)560 n.node_type = DIRECTORY if n.file_type == delta_DIR else FILE
570 return list(unserialized_content.entries)561 n.node = n.node_id
571562 children.append(n)
572 d.addCallback(_parse_content)563 defer.returnValue(children)
573 return d
574564
575 @log_timing565 @log_timing
576 def download_string(self, share_uuid, node_uuid, content_hash):566 def download_string(self, share_uuid, node_uuid, content_hash):

Subscribers

People subscribed via source and target branches