Mercurial > hg > simpypi
comparison simpypi/wsgi.py @ 41:c934505fa098
sketch out quick + dirty solution; tests do not pass
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 01 Mar 2012 10:43:28 -0800 |
parents | bb69b82ddd17 |
children | 6ea806412fd1 |
comparison
equal
deleted
inserted
replaced
40:bb69b82ddd17 | 41:c934505fa098 |
---|---|
57 | 57 |
58 # sanity check: is it a file? (TODO) | 58 # sanity check: is it a file? (TODO) |
59 if not hasattr(package, 'file') or not hasattr(package, 'filename'): | 59 if not hasattr(package, 'file') or not hasattr(package, 'filename'): |
60 return exc.HTTPBadRequest() | 60 return exc.HTTPBadRequest() |
61 | 61 |
62 # successful response | 62 # successful response: redirect to the main page |
63 response = exc.HTTPSeeOther(add_slash=True) | 63 response = exc.HTTPSeeOther(add_slash=True) |
64 | 64 |
65 # make a temporary copy for pkginfo | 65 # make a temporary copy for pkginfo |
66 # (or PaInt?) | 66 # (or PaInt?) |
67 tmpdir = tempfile.mkdtemp() | 67 tmpdir = tempfile.mkdtemp() |
68 try: | 68 try: |
69 path = os.path.join(tmpdir, filename) | 69 path = os.path.join(tmpdir, package.filename) |
70 f = file(path, 'w') | 70 f = file(path, 'w') |
71 import pdb; pdb.set_trace() | 71 f.write(package.file.read()) |
72 f.close() | 72 f.close() |
73 # put the package in the right place | 73 |
74 # get package data | |
75 sdist = pkginfo.sdist.SDist(path) | |
76 | |
77 # put the package in the right place | |
78 self.add_package(sdist) | |
79 except: | |
80 # something bad happen | |
81 response = exc.HTTPBadRequest() | |
74 finally: | 82 finally: |
75 # cleanup | 83 # cleanup |
76 shutil.rmtree(tmpdir) | 84 shutil.rmtree(tmpdir) |
77 | 85 |
78 # redirect to the main page | |
79 return response | 86 return response |
87 | |
88 ### API | |
89 | |
90 def add_package(self, sdist, move=True): | |
91 """ | |
92 add a package to the directory | |
93 """ | |
94 | |
95 # make a directory for the package | |
96 directory = os.path.join(self.directory, sdist.name) | |
97 if not os.path.exists(directory): | |
98 os.makedir(directory) | |
99 assert os.path.isdir(directory) | |
100 | |
101 # determine the extension (XXX hacky) | |
102 extensions = ('.tar.gz', '.zip', '.tar.bz2') | |
103 for ext in extensions: | |
104 if sdist.filename.endswith(ext): | |
105 break | |
106 else: | |
107 raise Exception("Extension %s not found: %s" % (extensions, sdist.filename)) | |
108 | |
109 # get the filename destination | |
110 filename = '%s-%s%s' % (sdist.name, sdist.version, ext) | |
111 filename = os.path.join(directory, filename) | |
112 | |
113 if move: | |
114 # move the file | |
115 shutil.move(sdist.filename, filename) | |
116 else: | |
117 # copy the file | |
118 shutil.copy(sdist.filename, filename) |