Mercurial > hg > MakeItSo
comparison makeitso/makeitso.py @ 23:776805790c84
stub out getting tempita from the net; unttested
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 30 Nov 2010 09:17:22 -0800 |
| parents | fc2867bc2ba6 |
| children | 1b802678b341 |
comparison
equal
deleted
inserted
replaced
| 22:fc2867bc2ba6 | 23:776805790c84 |
|---|---|
| 16 location = 'http://k0s.org/mozilla/hg/MakeItSo/raw-file/tip/makeitso/makeitso.py' | 16 location = 'http://k0s.org/mozilla/hg/MakeItSo/raw-file/tip/makeitso/makeitso.py' |
| 17 | 17 |
| 18 # URL of tempita | 18 # URL of tempita |
| 19 tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' | 19 tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' |
| 20 | 20 |
| 21 def cleanup(): | |
| 22 if 'tempdir' in globals(): | |
| 23 ### TODO: remove it | |
| 24 pass | |
| 25 | |
| 21 try: | 26 try: |
| 22 import tempita | 27 import tempita |
| 23 except ImportError: | 28 except ImportError: |
| 24 | 29 |
| 25 # Get tempita from the net | 30 # Get tempita from the net |
| 26 def getFiles(url, files): | 31 def getFiles(url, subdir, files): |
| 27 """ | 32 """ |
| 28 fetch files from the internet | 33 fetch files from the internet |
| 29 - url : base url | 34 - url : base url |
| 35 - subdirectory: to put things in | |
| 30 - files : list of files to retrieve | 36 - files : list of files to retrieve |
| 31 returns the location of a temporary directory | 37 returns the location of a temporary directory |
| 32 """ | 38 """ |
| 33 | 39 globals()['tempdir'] = tempfile.mkdtemp() |
| 34 raise NotImplementedError | 40 os.mkdir(subdir) |
| 41 url = url.rstrip('/') | |
| 42 for filename in files: | |
| 43 f, headers = urllib.urlretrive('%s/%s' % (url, filename)) | |
| 44 content = file(f).read() | |
| 45 outfile = os.path.join(globals()['tempdir'], subdir, filename) | |
| 46 o = file(outfile, 'w') | |
| 47 print >> o, content | |
| 48 return globals()['tempdir'] | |
| 49 | |
| 50 tempita_files = ['__init__.py', '_looper.py', 'compat3.py'] | |
| 51 | |
| 52 try: | |
| 53 t = getFiles(tempita_location, 'tempita', tempita_files) | |
| 54 sys.path.append(t) | |
| 55 import tempita | |
| 56 except: | |
| 57 cleanup() | |
| 58 raise NotImplementedError('This should say something like youre not connected to the net') | |
| 59 | |
| 35 | 60 |
| 36 | 61 |
| 37 # regular expressions for finding the shebang | 62 # regular expressions for finding the shebang |
| 38 shebang_re = '#!.*makeitso.*' | 63 shebang_re = '#!.*makeitso.*' |
| 39 shebang_re = re.compile(shebang_re) | 64 shebang_re = re.compile(shebang_re) |
| 178 content = file(f).read() | 203 content = file(f).read() |
| 179 print substitute(content, variables=variables) | 204 print substitute(content, variables=variables) |
| 180 else: | 205 else: |
| 181 content = sys.stdin.read() | 206 content = sys.stdin.read() |
| 182 print substitute(content, variables=variables) | 207 print substitute(content, variables=variables) |
| 208 | |
| 209 # cleanup | |
| 210 cleanup() | |
| 183 | 211 |
| 184 if __name__ == '__main__': | 212 if __name__ == '__main__': |
| 185 main() | 213 main() |
