]>
git.ipfire.org Git - ipfire.org.git/blob - source/dlhandler.py
614a64c0c4c27feee842f1e790a20d7d18bd2bde
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
27 print "Status: 403 Forbidden"
28 print "Pragma: no-cache"
29 print "Cache-control: no-cache"
30 print "Connection: close"
36 print "Status: 404 Not found"
37 print "Pragma: no-cache"
38 print "Cache-control: no-cache"
39 print "Connection: close"
45 print "Status: 302 Moved"
47 print "Pragma: no-cache"
48 print "Cache-control: no-cache"
49 print "Connection: close"
54 class NotFoundError(Exception):
58 def __init__(self
, path
):
61 self
.object_type
= None
68 ## This is for python 2.4.
70 #self.hash_md5 = md5.new(self.data()).hexdigest()
73 self
.hash_sha1
= sha
.new(self
.data()).hexdigest()
80 self
.showhttpheaders()
83 def showhttpheaders(self
):
84 print "Pragma: no-cache"
85 print "Cache-control: no-cache"
86 print "Connection: close"
87 print "Content-type:" + self
.mimetype()
88 print "Content-length: %s" % len(self
.data())
90 print "X-Object:" + self
.object_type
92 print "X-MD5:" + self
.hash_md5
94 print "X-SHA1:" + self
.hash_sha1
96 # An empty line ends the header
98 class FileObject(SourceObject
):
99 def __init__(self
, path
, version
, url
="/srv/www/ipfire.org/source/"):
100 SourceObject
.__init
__(self
, path
)
101 self
.url
= os
.path
.join(url
, "source-%s" % version
)
102 self
.filepath
= os
.path
.join(self
.url
, path
)
105 self
.object_type
= "FileObject"
109 f
= open(self
.filepath
, "rb")
113 self
.filedata
= f
.read()
117 default_mimetype
= "text/plain"
118 from mimetypes
import guess_type
119 return guess_type(self
.filepath
)[0] or default_mimetype
121 class PatchObject(SourceObject
):
122 def __init__(self
, path
, url
="/srv/git/patches.git"):
123 SourceObject
.__init
__(self
, path
)
125 self
.object_type
= "PatchObject"
132 self
.repo
= Repository(self
.url
)
135 #self.head = self.repo.head()
136 self
.tree
= self
.repo
.head
.tree
138 self
.blob
= self
.set_blob()
143 for directory
in self
.tree
.keys():
144 if isinstance(self
.tree
[directory
], Blob
):
147 blob
= self
.tree
[directory
][path
]
157 self
.filedata
= blob
._contents
158 self
.filedata
+= '\n'
162 return "text/plain" #self.blob.mime_type
165 os
.environ
["QUERY_STRING"] = \
166 os
.environ
["QUERY_STRING"].replace("+", "%2b")
168 path
= cgi
.FieldStorage().getfirst('path')
169 ver
= cgi
.FieldStorage().getfirst('ver')
171 if not os
.environ
["HTTP_USER_AGENT"].startswith("IPFireSourceGrabber"):
180 # At first, we assume that the requested object is a plain file:
182 object = FileObject(path
=path
, version
=ver
)
183 except NotFoundError
:
184 # Second, we assume that the requestet object is in the patch repo:
186 object = PatchObject(path
=path
)
187 except NotFoundError
: