]>
git.ipfire.org Git - ipfire.org.git/blob - dlhandler.py
66ff8d5eba374e17323b450c618318faad006d22
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: 404 Not found"
28 print "Pragma: no-cache"
29 print "Cache-control: no-cache"
30 print "Connection: close"
35 print "Status: 302 Moved"
37 print "Pragma: no-cache"
38 print "Cache-control: no-cache"
39 print "Connection: close"
44 class NotFoundError(Exception):
48 def __init__(self
, path
):
51 self
.object_type
= None
58 ## This is for python 2.4.
60 #self.hash_md5 = md5.new(self.data()).hexdigest()
63 self
.hash_sha1
= sha
.new(self
.data()).hexdigest()
70 self
.showhttpheaders()
73 def showhttpheaders(self
):
74 print "Pragma: no-cache"
75 print "Cache-control: no-cache"
76 print "Connection: close"
77 print "Content-type:" + self
.mimetype()
78 print "Content-length: %s" % len(self
.data())
80 print "X-Object:" + self
.object_type
82 print "X-MD5:" + self
.hash_md5
84 print "X-SHA1:" + self
.hash_sha1
86 # An empty line ends the header
88 class FileObject(SourceObject
):
89 def __init__(self
, path
, version
, url
="/srv/www/ipfire.org/source/"):
90 SourceObject
.__init
__(self
, path
)
91 self
.url
= os
.path
.join(url
, "source-%s" % version
)
92 self
.filepath
= os
.path
.join(self
.url
, path
)
95 self
.object_type
= "FileObject"
99 f
= open(self
.filepath
, "rb")
103 self
.filedata
= f
.read()
107 default_mimetype
= "text/plain"
108 from mimetypes
import guess_type
109 return guess_type(self
.filepath
)[0] or default_mimetype
111 class PatchObject(SourceObject
):
112 def __init__(self
, path
, url
="/srv/git/patches.git"):
113 SourceObject
.__init
__(self
, path
)
115 self
.object_type
= "PatchObject"
122 self
.repo
= Repository(self
.url
)
125 #self.head = self.repo.head()
126 self
.tree
= self
.repo
.head
.tree
128 self
.blob
= self
.set_blob()
133 for directory
in self
.tree
.keys():
134 if isinstance(self
.tree
[directory
], Blob
):
137 blob
= self
.tree
[directory
][path
]
147 self
.filedata
= blob
._contents
151 return "text/plain" #self.blob.mime_type
154 path
= cgi
.FieldStorage().getfirst('path')
155 ver
= cgi
.FieldStorage().getfirst('ver')
164 # At first, we assume that the requested object is a plain file:
166 object = FileObject(path
=path
, version
=ver
)
167 except NotFoundError
:
168 # Second, we assume that the requestet object is in the patch repo:
170 object = PatchObject(path
=path
)
171 except NotFoundError
: