annotate fetch.py @ 27:423b67ff4512

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 14 Nov 2011 21:32:54 -0800
parents d495b610046a
children 5ecb6507931b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 fetch stuff from the interwebs
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import os
23
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
8 import shutil
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import optparse
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
12 __all__ = ['Fetcher', 'Fetch', 'main']
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
13
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
14 def which(executable, path=os.environ['PATH']):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
15 """python equivalent of which; should really be in the stdlib"""
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
16 dirs = path.split(os.pathsep)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
17 for dir in dirs:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
18 if os.path.isfile(os.path.join(dir, executable)):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
19 return os.path.join(dir, executable)
7
4d3d0e1324f5 flush out tarfile
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
20
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 class Fetcher(object):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
22 """abstract base class for resource fetchers"""
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
24 @classmethod
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
25 def match(cls, _type):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
26 return _type == cls.type
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27
23
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
28 def __init__(self, url, clobber=True):
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
29 self.subpath = None
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
30 if '#' in url:
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
31 url, self.subpath = url.rsplit('#')
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
32 if self.subpath:
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
33 self.subpath = self.subpath.split('/')
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
34 self.url = url
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
35 self._clobber = clobber
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
37 def __call__(self, dest):
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
38 raise NotImplementedError("Should be called by implementing class")
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
39
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
40 def clobber(self, dest):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
41 """clobbers if self._clobber is set"""
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
42 if self._clobber and os.path.exists(dest):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
43 if os.path.isfile(dest):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
44 os.remove(dest)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
45 else:
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
46 shutil.rmtree(dest)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
47
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
48 @classmethod
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
49 def doc(cls):
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
50 """return docstring for the instance"""
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
51 retval = getattr(cls, '__doc__', '').strip()
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
52 return ' '.join(retval.split())
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53
7
4d3d0e1324f5 flush out tarfile
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
54 ### standard dispatchers - always available
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55
7
4d3d0e1324f5 flush out tarfile
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
56 import tarfile
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 import urllib2
7
4d3d0e1324f5 flush out tarfile
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
58 from StringIO import StringIO
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59
5
5b78d1411cdd typo; this now works
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
60 class FileFetcher(Fetcher):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
61 """fetch a single file"""
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
62 # Note: subpath and clobber for single files are ignored
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
64 type = 'file'
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
66 @classmethod
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
67 def download(cls, url):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
68 return urllib2.urlopen(url).read()
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
70 def __call__(self, dest):
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
71
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
72 if os.path.isdir(dest):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
73 filename = self.url.rsplit('/', 1)[-1]
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
74 dest = os.path.join(dest, filename)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
75 f = file(dest, 'w')
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
76 f.write(self.download(self.url))
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
77 f.close()
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
78
6
86f6f99e421b add types for unimplemented dispatchers
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
79
5
5b78d1411cdd typo; this now works
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
80 class TarballFetcher(FileFetcher):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
81 """fetch and extract a tarball"""
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
82
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
83 type = 'tar'
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
84
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
85 def __call__(self, dest):
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
86 if self.clobber:
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
87 shutil.rmtree(dest)
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
88 if os.path.exists(dest):
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
89 assert os.path.isdir(dest), "Destination must be a directory"
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
90 else:
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
91 os.mkdirs(dest)
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
92 if self.subpath:
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
93 raise NotImplementedError("should extract only a subpath of a tarball but I haven't finished it yet")
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
94 buffer = StringIO()
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
95 buffer.write(self.download(self.url))
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
96 buffer.seek(0)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
97 tf = tarfile.open(mode='r', fileobj=buffer)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
98 tf.extract(dest)
7
4d3d0e1324f5 flush out tarfile
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
99
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
100 fetchers = [FileFetcher, TarballFetcher]
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
101
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
102 ### VCS fetchers
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
103
11
726c3d288733 * add convenience import in __init__
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
104 import subprocess
19
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
105 try:
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
106 from subprocess import check_call as call
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
107 except ImportErorr:
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
108 raise # we need check_call, kinda
11
726c3d288733 * add convenience import in __init__
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
109
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
110 class VCSFetcher(Fetcher):
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
111
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
112 command = None
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
113
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
114 def call(*args, **kwargs):
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
115 assert command is not None, "Abstract base class"
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
116 call([self.command] + list(args), **kwargs)
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
117
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
118 def __init__(self, url, export=True):
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
119 """
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
120 - export : whether to strip the versioning information
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
121 """
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
122 Fetcher.__init__(self, url)
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
123 self.export = export
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
124
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
125 def __call__(self, dest):
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
126
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
127 if self.subpath or self.export:
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
128 # can only export with a subpath
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
129 self.export(dest, subpath=self.subpath)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
130 return
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
131
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
132 if os.path.exists(dest):
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
133 assert os.path.isdir(dest)
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
134 self.clone(dest)
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
135
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
136 def export(self, dest):
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
137 """
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
138 export a clone of the directory
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
139 """
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
140 dest = os.path.abspath(dest)
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
141 tmpdir = tempfile.mkdtmp()
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
142 self.clone(tmpdir)
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
143 path = tmpdir
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
144 if self.subpath:
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
145 path = os.path.join([tmpdir] + self.subpath)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
146 assert os.path.exists(path), "subpath %s of %s not found" % (os.path.sep.join(self.subpath), self.url)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
147 self.clobber(dest)
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
148 if os.path.isdir(path):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
149 if os.path.exists(dest):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
150 assert os.path.isdir(dest), "source is a directory; destination is a file"
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
151 else:
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
152 os.makedirs(dest)
27
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
153 shutil.copytree(path, dest)
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
154 else:
27
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
155 if not os.path.exists(dest):
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
156 directory, filename = os.path.split(dest)
27
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
157 if os.path.exists(directory):
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
158 assert os.path.isdir(directory), "%s is not a directory" % directory
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
159 else:
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
160 os.makedirs(directory)
423b67ff4512 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 26
diff changeset
161 shutil.copy(path, dest)
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
162 shutil.rmtree(tmpdir)
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
163
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
164 def clone(self, dest):
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
165 """
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
166 clones into a directory
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
167 """
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
168 raise NotImplementedError("Abstract base class")
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
169
26
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
170 def update(self, dest):
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
171 """
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
172 updates a checkout
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
173 """
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
174 raise NotImplementedError("Abstract base class")
d495b610046a more stubbing; tests work again
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
175
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
176
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
177 if which('hg'):
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
178
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
179 class HgFetcher(VCSFetcher):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
180 """checkout a mercurial repository"""
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
181 type = 'hg'
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
182
19
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
183 def __init__(self, url, export=True):
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
184 VCSFetcher.__init__(self, url, export=True)
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
185 self.hg = which('hg')
25
e628ce3ae49f more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
186 assert self.hg, "'hg' command not found"
19
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
187
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
188 def __call__(self, dest):
23
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
189 if os.path.exists(dest):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
190 assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.hg'))
19
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
191 call([self.hg, 'pull', self.url], cwd=dest)
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
192 call([self.hg, 'update'], cwd=dest)
d69041957c0e more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 18
diff changeset
193 else:
23
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
194 if not os.path.exists(dest):
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
195 os.mkdirs(dest)
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
196 call([self.hg, 'clone', self.url, dest])
11
726c3d288733 * add convenience import in __init__
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
197
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
198 fetchers.append(HgFetcher)
6
86f6f99e421b add types for unimplemented dispatchers
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
199
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
200
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
201 if which('git'):
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
202
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
203 class GitFetcher(Fetcher):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
204 """checkout a git repository"""
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
205 type = 'git'
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
206
20
738d84b4de52 start documenting
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
207 def __init__(self, url, export=True):
738d84b4de52 start documenting
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
208 VCSFetcher.__init__(self, url, export=True)
23
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
209 self.git = which('git')
12ad9ab11860 stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
210
24
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
211 def __call__(self, dest):
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
212 if os.path.exists(dest):
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
213 assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.git'))
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
214 call([self.git, 'pull', self.url], cwd=dest)
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
215 call([self.hg, 'update'], cwd=dest)
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
216 else:
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
217 if not os.path.exists(dest):
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
218 os.mkdirs(dest)
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
219 call([self.hg, 'clone', self.url, dest])
b1f65f3bd1bc pretend to flesh out git fetcher
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
220
20
738d84b4de52 start documenting
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
221
738d84b4de52 start documenting
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
222 fetchers.append(GitFetcher)
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
223
16
c77d29a10e08 get it working
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
224 __all__ += [i.__name__ for i in fetchers]
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
225
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
226 class Fetch(object):
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
227
21
0706968f01bb stub testing
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
228 def __init__(self, fetchers=fetchers[:], relative_to=None, strict=True):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
229 self.fetchers = fetchers
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
230 self.relative_to = relative_to
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
231 self.strict = strict
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
232
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
233 def fetcher(self, _type):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
234 """find the fetcher for the appropriate type"""
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
235 for fetcher in fetchers:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
236 if fetcher.match(_type):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
237 return fetcher
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
238
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
239 def __call__(self, url, destination, type, **options):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
240 fetcher = self.fetcher(type)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
241 assert fetcher is not None, "No fetcher found for type '%s'" % type
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
242 fetcher = fetcher(url, **options)
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
243 fetcher(destination)
2
0c344ed749ac fix typos
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
244
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
245 def fetch(self, *items):
2
0c344ed749ac fix typos
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
246
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
247 if self.strict:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
248 # ensure all the required fetchers are available
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
249 types = set([i['type'] for i in items])
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
250 assert not [i for i in types
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
251 if [True for fetcher in fetchers if fetcher.match(i)]]
4
a984091d681a fix up destination
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
252
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
253 for item in items:
4
a984091d681a fix up destination
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
254
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
255 # fix up relative paths
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
256 dest = item['dest']
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
257 if not os.path.isabs(dest):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
258 relative_to = self.relative_to or os.path.dirname(os.path.abspath(item['manifest']))
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
259 dest = os.path.join(relative_to, dest)
4
a984091d681a fix up destination
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
260
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
261 # fetch the items
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
262 self(item['url'], destination=dest, type=item['type'], **item['options'])
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
263
21
0706968f01bb stub testing
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
264
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
265 format_string = "[URL] [destination] [type] <options>"
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
266 def read_manifests(*manifests):
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
267 """
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
268 read some manifests and return the items
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
269
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
270 Format:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
271 %s
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
272 """ % format_string
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
273
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
274 # sanity check
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
275 assert not [i for i in manifests if not os.path.exists(i)]
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
276
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
277 retval = []
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
278
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
279 for manifest in manifests:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
280 for line in file(i).readlines():
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
281 line = line.strip()
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
282 if line.startswith('#') or not line:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
283 continue
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
284 line = line.split()
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
285 if len(line) not in (3,4):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
286 raise Exception("Format should be: %s; line %s" % (format_string, line))
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
287 options = {}
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
288 if len(line) == 4:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
289 option_string = line.pop().rstrip(',')
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
290 try:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
291 options = dict([[j.strip() for j in i.split('=', 1)]
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
292 for i in option_string.split(',')])
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
293 except:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
294 raise Exception("Options format should be: key=value,key2=value2,...; got %s" % option_string)
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
295
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
296 url, dest, _type = line
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
297 retval.append(dict(url=url, dest=dest, type=_type, options=options, manifest=manifest))
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
298 return retval
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
299
2
0c344ed749ac fix typos
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
300 def main(args=sys.argv[1:]):
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
301
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
302 # parse command line options
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
303 usage = '%prog [options] manifest [manifest] [...]'
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
304
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
305 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
306 def format_description(self, description):
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
307 if description:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
308 return description + '\n'
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
309 else:
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
310 return ''
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
311
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
312 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
313 parser.add_option('-o', '--output',
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
314 help="output relative to this location vs. the manifest location")
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
315 parser.add_option('-d', '--dest', # XXX unused
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
316 action='append',
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
317 help="output only these destinations")
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
318 parser.add_option('-s', '--strict',
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
319 action='store_true', default=False,
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
320 help="fail on error")
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
321 parser.add_option('--list-fetchers', dest='list_fetchers',
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
322 action='store_true', default=False,
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
323 help='list available fetchers and exit')
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
324 options, args = parser.parse_args(args)
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
325
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
326 if options.list_fetchers:
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
327 types = set()
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
328 for fetcher in fetchers:
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
329 if fetcher.type in types:
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
330 continue # occluded, should probably display separately
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
331 print '%s : %s' % (fetcher.type, fetcher.doc())
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
332 types.add(fetcher.type)
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
333 parser.exit()
8
cf00d46b1bfb pretend like we have a pluggable system to start debugging it
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
334
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
335 if not args:
17
e2af4bc5159c more polishing
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
336 # TODO: could read from stdin
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
337 parser.print_help()
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
338 parser.exit()
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
339
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
340 items = read_manifests(*args)
16
c77d29a10e08 get it working
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
341 fetch = Fetch(fetchers, strict=options.strict)
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
342
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
343 # download the files
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
344 fetch.fetch(*items)
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
345
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
346 if __name__ == '__main__':
15
bc7d6763357e clean up spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
347 main()
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
348