~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/hash_queue.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from twisted.internet import reactor
29
29
 
30
 
from ubuntuone.storageprotocol.hash import \
 
30
from ubuntuone.storageprotocol.content_hash import \
31
31
    content_hash_factory, crc32
32
32
 
33
33
 
34
34
class StopHashing(Exception):
35
 
    """The current hash was cancelled"""
 
35
    """The current hash was cancelled."""
36
36
 
37
37
 
38
38
class _Hasher(threading.Thread):
77
77
            except StopHashing, e:
78
78
                self.logger.debug(str(e))
79
79
            else:
80
 
                m = "Hasher: path hash pushed:  path %r  hash %r"
81
 
                self.logger.debug(m, path, result)
 
80
                hashdata, crc, size, stat = result
 
81
                self.logger.debug("Hasher: path hash pushed:  path=%r  hash=%s"
 
82
                                  "  crc=%s  size=%d  st_ino=%d  st_size=%d"
 
83
                                  "  st_mtime=%r", path, hashdata,crc, size,
 
84
                                  stat.st_ino, stat.st_size, stat.st_mtime)
82
85
                reactor.callFromThread(self.eq.push,
83
86
                                       "HQ_HASH_NEW", path, *result)
84
87
            finally:
88
91
            self.queue.task_done()
89
92
 
90
93
    def stop(self):
91
 
        """Stop the hasher (will be effective in the next loop if a hash
92
 
        is in progress)
 
94
        """Stop the hasher.
 
95
 
 
96
        Will be effective in the next loop if a hash is in progress.
 
97
 
93
98
        """
94
99
        # clear the queue to push a end_mark, just to unblok if we are waiting
95
100
        # for a new item
125
130
        return hasher.content_hash(), crc, size, initial_stat
126
131
 
127
132
    def busy(self):
128
 
        """return whether we are busy"""
 
133
        """Return whether we are busy."""
129
134
        with self.mutex:
130
135
            return self.hashing
131
136
 
132
137
    def cancel_if_running(self, path):
133
 
        """request a cancel/stop of the current hash, if it's == path"""
 
138
        """Request a cancel/stop of the current hash, if it's == path."""
134
139
        with self.mutex:
135
140
            if self.hashing == path:
136
141
                self._should_cancel = path