Package bodhi :: Module new
[hide private]
[frames] | no frames]

Source Code for Module bodhi.new

 1  # $Id: new.py,v 1.8 2007/01/06 08:03:21 lmacken Exp $ 
 2  # This program is free software; you can redistribute it and/or modify 
 3  # it under the terms of the GNU General Public License as published by 
 4  # the Free Software Foundation; version 2 of the License. 
 5  # 
 6  # This program is distributed in the hope that it will be useful, 
 7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 9  # GNU Library General Public License for more details. 
10  # 
11  # You should have received a copy of the GNU General Public License 
12  # along with this program; if not, write to the Free Software 
13  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
14   
15  import os 
16   
17  from os.path import join 
18  from bodhi.widgets import NewUpdateForm 
19  from turbogears import expose, controllers, identity, config, url, flash 
20   
21  update_form = NewUpdateForm() 
22   
23 -class NewUpdateController(controllers.Controller):
24 25 build_dir = config.get('build_dir') 26 packages = [] 27
28 - def build_pkglist(self):
29 """ Cache a list of packages used for the package AutoCompleteField """ 30 try: 31 self.packages = os.listdir(self.build_dir) 32 except (OSError, TypeError): 33 flash("Warning: build_dir either invalid or not set in app.cfg")
34 35 @identity.require(identity.not_anonymous()) 36 @expose(template="bodhi.templates.form")
37 - def index(self, *args, **kw):
38 self.build_pkglist() 39 return dict(form=update_form, values=kw, action=url("/save"))
40 41 @expose(format="json")
42 - def search(self, name):
43 """ 44 Called automagically by the AutoCompleteWidget. 45 If a package is specified (or 'pkg-'), return a list of available 46 n-v-r's. This method also auto-completes packages. 47 """ 48 matches = [] 49 if not self.packages: self.build_pkglist() 50 if name[-1] == '-' and name[:-1] and name[:-1] in self.packages: 51 name = name[:-1] 52 for version in os.listdir(join(self.build_dir, name)): 53 for release in os.listdir(join(self.build_dir, name, version)): 54 matches.append('-'.join((name, version, release))) 55 else: 56 for pkg in self.packages: 57 if name == pkg: 58 for version in os.listdir(join(self.build_dir, name)): 59 for release in os.listdir(join(self.build_dir, name, 60 version)): 61 matches.append('-'.join((name, version, release))) 62 break 63 elif pkg.startswith(name): 64 matches.append(pkg) 65 matches.reverse() 66 return dict(pkgs=matches)
67