1
1
# -*- coding: utf-8 -*-
3
# (C) Copyright 2009, APT-Portal Developers
4
# https://launchpad.net/~apt-portal-devs
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# /packages/ controller
21
2
from cherrypy_mako import *
22
3
from models.package import *
23
4
from models.application import *
24
from sqlalchemy import asc
28
repos_commands_dir = "rep_commands"
30
7
class Packages(object):
32
@cherrypy.tools.expires(secs=0)
33
9
def index(self, q=None):
35
The is the main page which presents the list of packages
36
if no key (q) is specified only the packages needing an action
39
if not userinfo.is_admin():
40
raise cherrypy.HTTPError(403)
15
if not userinfo.is_admin():
16
raise cherrypy.HTTPError(403)
47
18
db_packages = Package.query.filter_by(package=q).order_by(\
48
asc(Package.package), asc(Package.version)).all()
19
Package.package, Package.source).all()
50
22
db_packages = Package.query.order_by( \
51
asc(Package.package), asc(Package.version)).all()
23
Package.package, Package.source).all()
53
25
last_package_version = None
56
27
# Walk the packages list, skip classified and linked
57
28
for package in db_packages:
58
29
package_version = package.package+"-"+package.version
59
30
if package_version == last_package_version:
61
if len(package.lists) == 0: # package is not in a repos
63
32
last_package_version = package_version
111
77
results += "%s|%d\n" % (package.package, package.id)
115
def remove(self, package_id, list_id, confirm=None):
116
""" Create a command to remove a package from the repository """
117
if not userinfo.is_admin():
118
raise cherrypy.HTTPError(403)
119
package_id = long(package_id)
120
list_id = long(list_id)
121
package = Package.query.filter_by(id = package_id).first()
122
packagelist = PackageList.query.filter_by(id = list_id).first()
124
return "Package %d not found" % package_id
126
return "List %d not found" % list_id
128
return serve_template("package_remove.html" \
129
, package = package, packagelist = packagelist)
130
source_package = package.source or package.package
131
user = userinfo.find_user()
132
action = "%s %s %s %s %s" % (user.email, 'remove' \
133
, packagelist.suite, source_package, package.version)
135
time_now = time.strftime("%Y%m%d.%H%M%S", time.localtime())
136
filename = "%s_%s_%s" % (source_package, package.version, time_now)
137
if not os.path.isdir(repos_commands_dir):
138
return "%s directory is not available, " \
139
"repository commands are not supported" % repos_commands_dir
141
f = open(os.path.join(repos_commands_dir, filename), 'w')
145
return serve_template("package_remove.html" \
146
, ticket_name = filename, confirm='Y')
149
def copy(self, package_id, source_list_id, target_list):
150
""" Create a command to copy a package to another repository """
151
if not userinfo.is_admin():
152
raise cherrypy.HTTPError(403)
153
package_id = long(package_id)
154
source_list_id = long(source_list_id)
155
package = Package.query.filter_by(id = package_id).first()
156
source_packagelist = PackageList.query.filter_by(id = source_list_id).first()
157
target_packagelist = PackageList.query.filter_by(suite = target_list).first()
159
return "Package %d not found" % package_id
160
if not source_packagelist:
161
return "List %d not found" % list_id
162
if target_list and not target_packagelist:
163
return "Repository %s not found" % target_list
165
for plist in PackageList.query.all():
166
if plist.suite == source_packagelist.suite:
168
if plist.suite not in repository_list:
169
repository_list.append(plist.suite)
170
if len(target_list) < 2:
171
return serve_template("package_copy.html" \
172
, package = package \
173
, source_packagelist = source_packagelist \
174
, target_packagelist = target_packagelist \
175
, repository_list = repository_list \
176
, package_id = package_id \
177
, source_list_id = source_list_id \
178
, target_list = target_list \
181
source_package = package.source or package.package
182
user = userinfo.find_user()
183
action = "%s %s %s %s %s %s" % (user.email, 'copy' \
184
, target_packagelist.suite, source_packagelist.suite, source_package, package.version)
186
time_now = time.strftime("%Y%m%d.%H%M%S", time.localtime())
187
filename = "%s_%s_%s" % (source_package, package.version, time_now)
188
if not os.path.isdir(repos_commands_dir):
189
return "%s directory is not available, " \
190
"repository commands are not supported" % repos_commands_dir
192
f = open(os.path.join(repos_commands_dir, filename), 'w')
196
return serve_template("package_copy.html" \
197
, ticket_name = filename \
201
81
cherrypy.root.packages = Packages()