Mercurial > hg
annotate hgext/largefiles/remotestore.py @ 15252:6e809bb4f969
largefiles: improve comments, internal docstrings
- fix some ungrammatical/unclear/incorrect comments/docstrings
- rewrite some really unclear comments/docstrings
- make formatting/style more consistent with the rest of Mercurial
(lowercase without period unless it's really multiple sentences)
- wrap to 75 columns
- always say "largefile(s)", not "lfile(s)" (or "big files")
- one space between sentences, not two
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Wed, 12 Oct 2011 20:59:27 -0400 |
parents | 8e115063950d |
children | 67d010779907 |
rev | line source |
---|---|
15168 | 1 # Copyright 2010-2011 Fog Creek Software |
2 # Copyright 2010-2011 Unity Technologies | |
3 # | |
4 # This software may be used and distributed according to the terms of the | |
5 # GNU General Public License version 2 or any later version. | |
6 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15188
diff
changeset
|
7 '''remote largefile store; the base class for servestore''' |
15168 | 8 |
9 import urllib2 | |
10 | |
11 from mercurial import util | |
12 from mercurial.i18n import _ | |
13 | |
14 import lfutil | |
15 import basestore | |
16 | |
17 class remotestore(basestore.basestore): | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15188
diff
changeset
|
18 '''a largefile store accessed over a network''' |
15168 | 19 def __init__(self, ui, repo, url): |
20 super(remotestore, self).__init__(ui, repo, url) | |
21 | |
22 def put(self, source, hash): | |
23 if self._verify(hash): | |
24 return | |
25 if self.sendfile(source, hash): | |
26 raise util.Abort( | |
27 _('remotestore: could not put %s to remote store %s') | |
28 % (source, self.url)) | |
29 self.ui.debug( | |
30 _('remotestore: put %s to remote store %s') % (source, self.url)) | |
31 | |
32 def exists(self, hash): | |
33 return self._verify(hash) | |
34 | |
35 def sendfile(self, filename, hash): | |
36 self.ui.debug('remotestore: sendfile(%s, %s)\n' % (filename, hash)) | |
37 fd = None | |
38 try: | |
39 try: | |
40 fd = lfutil.httpsendfile(self.ui, filename) | |
41 except IOError, e: | |
42 raise util.Abort( | |
43 _('remotestore: could not open file %s: %s') | |
44 % (filename, str(e))) | |
45 return self._put(hash, fd) | |
46 finally: | |
47 if fd: | |
48 fd.close() | |
49 | |
50 def _getfile(self, tmpfile, filename, hash): | |
51 # quit if the largefile isn't there | |
52 stat = self._stat(hash) | |
53 if stat: | |
54 raise util.Abort(_('remotestore: largefile %s is %s') % | |
55 (hash, stat == 1 and 'invalid' or 'missing')) | |
56 | |
57 try: | |
58 length, infile = self._get(hash) | |
15188
8e115063950d
largefiles: don't break existing tests (syntax error, bad imports)
Greg Ward <greg@gerg.ca>
parents:
15168
diff
changeset
|
59 except urllib2.HTTPError, e: |
15168 | 60 # 401s get converted to util.Aborts; everything else is fine being |
61 # turned into a StoreError | |
62 raise basestore.StoreError(filename, hash, self.url, str(e)) | |
63 except urllib2.URLError, e: | |
64 # This usually indicates a connection problem, so don't | |
65 # keep trying with the other files... they will probably | |
66 # all fail too. | |
67 raise util.Abort('%s: %s' % (self.url, str(e.reason))) | |
68 except IOError, e: | |
69 raise basestore.StoreError(filename, hash, self.url, str(e)) | |
70 | |
71 # Mercurial does not close its SSH connections after writing a stream | |
72 if length is not None: | |
73 infile = lfutil.limitreader(infile, length) | |
74 return lfutil.copyandhash(lfutil.blockstream(infile), tmpfile) | |
75 | |
76 def _verify(self, hash): | |
77 return not self._stat(hash) | |
78 | |
79 def _verifyfile(self, cctx, cset, contents, standin, verified): | |
80 filename = lfutil.splitstandin(standin) | |
81 if not filename: | |
82 return False | |
83 fctx = cctx[standin] | |
84 key = (filename, fctx.filenode()) | |
85 if key in verified: | |
86 return False | |
87 | |
88 verified.add(key) | |
89 | |
90 stat = self._stat(hash) | |
91 if not stat: | |
92 return False | |
93 elif stat == 1: | |
94 self.ui.warn( | |
95 _('changeset %s: %s: contents differ\n') | |
96 % (cset, filename)) | |
97 return True # failed | |
98 elif stat == 2: | |
99 self.ui.warn( | |
100 _('changeset %s: %s missing\n') | |
101 % (cset, filename)) | |
102 return True # failed | |
103 else: | |
104 raise util.Abort(_('check failed, unexpected response' | |
105 'statlfile: %d') % stat) |