# Copyright (c) 2005, Reinhard Tartler, Stefan Potyra
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import os, sys
from mod_python import psp
from mod_python import util
from mod_python.Session import Session
from Config import Config
import User
from Package import *
from Uploads import *
from Comments import *
from stat import *
LISTING_TMPL = "listing.html"
DETAILS_TMPL = "details.html"
def _baseurl(c, upid):
return cfg.getBaseUrlPath() + basedir(c, upid)
def _filesize(f, directory):
s = os.stat("".join([directory, f]))
if S_ISDIR(s[ST_MODE]):
return 'DIR'
if s.st_size > 2048:
return '%d KiBytes' % ( s.st_size / 1024 )
else:
return '%d Bytes' % ( s.st_size )
def _packageindex(c, upid):
directory = cfg.getIncomingDir() + basedir(c, upid)
s = ''
for filename in os.listdir(directory):
s += '
%s | %s |
' % (_baseurl(c, upid) + filename, filename, _filesize(filename, directory))
return s
def _concerninguploads(c, upid, currentuser, currentlevel):
""" shows uploads concerning the same sourcepackage """
sql = """SELECT upid, to_char(dateofupload, 'Month DD HH24:MI'),
( SELECT count(*) FROM Comments WHERE upid = %d)
FROM Upload
WHERE SID = ( SELECT sid from Upload WHERE upid = %d)
ORDER BY dateofupload ASC
""" % (upid, upid)
r = c.query(sql)
s = ['The following uploads have been uploaded concerning the same Package:']
for row in r.getresult():
(rowupid, rowdate) = (row[0], row[1])
s.append("""Comments for upload of %s
""" % (rowupid, rowdate))
if (not (rowupid == upid)):
s.append(" (debdiff)" % (rowupid, upid))
s.append("
")
s.append( """
Date | Reviewer | Comment | Advocating | Actions |
%s
""" % (getcomments(c, currentuser, currentlevel, rowupid)))
s.append('')
return "\n".join(s)
def _checkUser(req, c):
s = Session(req)
s.load()
if not s.is_new() and s.has_key('email') and s.has_key('password'):
u = User.User(s['email'], s['password'], c)
if u.isAuthed():
return (u.email, u.accesslevel, u.usid)
return (None, None, None)
def _getuploader(c, upid):
sql = """SELECT email FROM Users us JOIN Upload up ON us.usid = up.usid
WHERE up.upid = '%d'
""" % int(upid)
r = c.query(sql)
if r.ntuples() == 1:
return r.dictresult()[0]['email']
def _commentform(req, c, login, upid, level):
if login is None:
return 'please login at main page'
if (level == 'Contributor') and (_getuploader(c, upid) != login):
return 'Sorry, Commenting for contributors only on their own uploads'
tmpl = cfg.getTemplatesPath('commentform.html')
vars = { 'login' : login,
'upid': upid,
'level': level }
return psp.PSP(req, tmpl, vars=vars )
def _detailpage(req, c, upid, currentuser, currentlevel, commentform):
vars = { "dirindex" : _packageindex(c, upid),
"comments" : '',
"concerninguploads" : _concerninguploads(c, upid, currentuser, currentlevel),
"commentform": commentform,
"package" : getPackageName(c, upid),
"uploader" : _getuploader(c, upid),
"date" : upload_date(c, upid) }
tmpl = cfg.getTemplatesPath('details.html')
m = psp.PSP(req, tmpl, vars=vars)
return m
def index(req):
"""Called by default from apache
"""
fs = util.FieldStorage(req)
global cfg
cfg = Config(req)
c = cfg.getConnection()
if not fs.has_key('upid'):
return 'please specify a package'
upid = int(fs['upid'])
uploaddir = cfg.getIncomingDir() + basedir(c, upid)
if not os.access(uploaddir, os.F_OK):
return 'directory (%s) of upload (%d) not found' % (uploaddir, int(upid))
package = getPackageName(c, upid)
if package is None or package == '':
return 'upload %d invalid or has been nuked' % upid
(login, level, usid) = _checkUser(req,c)
# Adding comment to this upload
if fs.has_key('text') and login is not None:
if fs.has_key('advocate'):
addcomment(c, getUSID(c, login), int(upid), fs['text'], fs['advocate'])
else:
addcomment(c, getUSID(c, login), int(upid), fs['text'], 'no')
if fs.has_key('deletecomment') and login is not None:
deletecomment(c, int(fs['deletecomment']), level, usid)
if fs.has_key('addadvocate') and (login is not None) and ((level == 'Reviewer') or (level == 'Admin')):
addadvocate(c, int(fs['addadvocate']), usid)
if fs.has_key('removeadvocate') and login is not None:
removeadvocate(c, int(fs['removeadvocate']), usid)
comments = getcomments(c, usid, level, upid)
commentform = _commentform(req, c, login, upid, level)
return _detailpage(req, c, upid, usid, level, commentform)