Package bodhi :: Package tools :: Module init
[hide private]
[frames] | no frames]

Source Code for Module bodhi.tools.init

 1  #!/usr/bin/env python 
 2  # 
 3  # $Id: $ 
 4  # 
 5  # This program is free software; you can redistribute it and/or modify 
 6  # it under the terms of the GNU General Public License as published by 
 7  # the Free Software Foundation; version 2 of the License. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU Library General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with this program; if not, write to the Free Software 
16  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
17   
18  """ Bodhi Initialization """ 
19   
20  from os.path import isfile 
21  from turbogears import config, update_config 
22  from turbogears.database import PackageHub 
23   
24  hub = PackageHub("bodhi") 
25  __connection__ = hub 
26   
27  releases = ( 
28      { 
29          'name'      : 'F7', 
30          'long_name' : 'Fedora 7', 
31          'dist_tag'  : 'dist-fc7', 
32          'id_prefix' : 'FEDORA' 
33      }, 
34  ) 
35   
36 -def import_releases():
37 """ Import the releases """ 38 from bodhi.model import Release 39 print "\nInitializing Release table..." 40 41 for release in releases: 42 rel = Release(name=release['name'], long_name=release['long_name'], 43 id_prefix=release['id_prefix'], 44 dist_tag=release['dist_tag']) 45 print rel
46
47 -def import_rebootpkgs():
48 """ 49 Add packages that should suggest a reboot. Other than these packages, we 50 add a package to the database when its first update is added to the system 51 """ 52 from bodhi.model import Package 53 for pkg in config.get('reboot_pkgs').split(): 54 Package(name=pkg, suggest_reboot=True)
55
56 -def clean_tables():
57 from bodhi.model import Release, Package 58 print "Cleaning out tables" 59 Release.dropTable(ifExists=True, cascade=True) 60 Package.dropTable(ifExists=True, cascade=True) 61 hub.commit() 62 Release.createTable(ifNotExists=True) 63 Package.createTable(ifNotExists=True)
64
65 -def load_config():
66 """ Load the appropriate configuration so we can get at the values """ 67 configfile = 'prod.cfg' 68 if not isfile(configfile): 69 configfile = 'dev.cfg' 70 update_config(configfile=configfile, modulename='bodhi.config')
71 72 ## 73 ## Initialize the package/release/multilib tables 74 ## 75 if __name__ == '__main__': 76 print "Initializing Bodhi\n" 77 load_config() 78 hub.begin() 79 clean_tables() 80 import_releases() 81 import_rebootpkgs() 82 hub.commit() 83