~hanno-stock/revu/updated-revu-workflow

175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
1
# Copyright (C) 2008 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
2
#
3
# All rights reserved.
4
# 
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions are met:
7
# 
8
#     * Redistributions of source code must retain the above copyright notice,
9
#     this list of conditions and the following disclaimer.
10
# 
11
#     * Redistributions in binary form must reproduce the above copyright
12
#     notice, this list of conditions and the following disclaimer in the
13
#     documentation and/or other materials provided with the distribution.
14
# 
15
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
# POSSIBILITY OF SUCH DAMAGE.
26
#
27
# DESCRIPTION:
28
# This page takes a package name as argument and provides a static URL
29
# that always refers to the latest .dsc file from that package.
30
#
31
32
import os
33
import sys
34
35
from common import *
337 by Siegfried-Angel Gevatter Pujals
- Remove scripts/nuke_upload.py as it wasn't being used and the web interface provides the same option.
36
from config import config, connection
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
37
from Uploads import basedir
38
39
def index(req):
40
	
41
	if not req.form.has_key('package') or not req.form['package']:
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
42
		return '1\n\nNo package selected.'
43
	
44
	extension = '.dsc'
45
	package = req.form['package']
46
	for ext in ('.dsc', '.diff.gz', '.orig.tar.gz', '.tar.gz'):
47
		if package.endswith(ext):
48
			package = package[:-len(ext)]
49
			extension = ext
50
	
51
	if not is_format_package_name(package):
52
		return '2\n\nNot a valid package name.'
53
	
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
54
	sql = """
55
		SELECT upid FROM upload u
56
		INNER JOIN sourcepackage s
57
		ON u.sid=s.sid WHERE s.name='%s' 
58
		ORDER BY u.dateofupload DESC LIMIT 1
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
59
		""" % package
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
60
	
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
61
	result = connection.query(sql)
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
62
	if result.ntuples() == 1:
63
		upid = int(result.dictresult()[0]['upid'])
64
		del result
65
	else:
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
66
		return '3\n\nPackage "%s" is not in our database.' % package
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
67
	
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
68
	directory_name = basedir(upid)
69
	upload_directory = os.path.join(config.getIncomingDir(), directory_name)
70
	file = None
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
71
	
175.1.5 by Siegfried-Angel Gevatter Pujals
Add &url option to dsc.py, to let it print the url to the .dsc instead.
72
	for file in os.listdir(upload_directory):
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
73
		if file.endswith(extension):
74
			file = os.path.join(upload_directory, file)
175.1.5 by Siegfried-Angel Gevatter Pujals
Add &url option to dsc.py, to let it print the url to the .dsc instead.
75
			break
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
76
	
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
77
	if not file:
78
		return '4\n\nFile not found. Invalid upload?'
175.1.4 by Siegfried-Angel Gevatter Pujals
Add './dsc.py?package=' (LP: #192715).
79
	
175.1.5 by Siegfried-Angel Gevatter Pujals
Add &url option to dsc.py, to let it print the url to the .dsc instead.
80
	if req.form.has_key('url'):
307 by Siegfried-Angel Gevatter Pujals
Update dsc.py.
81
		return 'http://' + req.hostname + os.path.join(config.getBaseUrlPath(), directory_name, file)
82
	
83
	return open(file, 'r').read()