diff --git a/amber/model.py b/amber/model.py index d956981..e6ff5fa 100644 --- a/amber/model.py +++ b/amber/model.py @@ -19,7 +19,7 @@ from turbogears.database import session from fedora.tg.json import SABase # Bind us to the database defined in the config file. -get_engine() +#get_engine() # Questions: # How are tags different from categories diff --git a/init.py b/init.py index 456280f..7384cc4 100644 --- a/init.py +++ b/init.py @@ -1,165 +1,168 @@ #!/usr/bin/python -tt from turbogears import config, update_config -from turbogears.database import PackageHub -from amber.model import Application, ApplicationSuite, \ - Category, Tag, OSRelease, Package, \ - ApplicationPackageRelationship +from turbogears.database import metadata, mapper, session, get_engine +from amber.model import Application, Suite, \ + Category, Tag, Collection, Package, \ + ApplicationPackage update_config(configfile='dev.cfg', modulename='amber.config') - -hub = PackageHub("amber") -__connection__ = hub +get_engine() ## Add a bunch of random apps and categorys categories = [ { - 'name' : 'Games', - 'desc' : 'Games, toys, playtime' + 'name' : u'Games', + 'desc' : u'Games, toys, playtime' }, { - 'name' : 'Office', - 'desc' : 'Office applications. Bo-ring' + 'name' : u'Office', + 'desc' : u'Office applications. Bo-ring' }, ] apps = [ { - 'name': 'Evince', - 'desc' : 'Evince is a document viewer for multiple document formats. It currently supports pdf, postscript, djvu, tiff and dvi. The goal of evince is to replace the multiple document viewers that exist on the GNOME Desktop with a single simple application.', - 'categories': ['Games'], - 'tags': ['suck','w00t','pants'] + 'name': u'Evince', + 'desc' : u'Evince is a document viewer for multiple document formats. It currently supports pdf, postscript, djvu, tiff and dvi. The goal of evince is to replace the multiple document viewers that exist on the GNOME Desktop with a single simple application.', + 'categories': [u'Games'], + 'tags': [u'suck',u'w00t',u'pants'] }, { - 'name' : 'gedit', - 'desc' : 'Lightweight but powerful text editor of the GNOME project.', - 'categories': ['Games'], - 'tags': ['suck','baz','bippy'] + 'name' : u'gedit', + 'desc' : u'Lightweight but powerful text editor of the GNOME project.', + 'categories': [u'Games'], + 'tags': [u'suck',u'baz',u'bippy'] }, { - 'name' : 'Thunderbird', - 'desc' : 'Enjoy safe, fast, and easy email, with intelligent spam filters, quick message search, and customizable views. Brought to you by Mozilla, Thunderbird makes email better.', - 'categories': ['Games'], + 'name' : u'Thunderbird', + 'desc' : u'Enjoy safe, fast, and easy email, with intelligent spam filters, quick message search, and customizable views. Brought to you by Mozilla, Thunderbird makes email better.', + 'categories': [u'Games'], 'tags': [] }, { - 'name' : 'Evolution', - 'desc' : 'Evolution provides integrated mail, addressbook and calendaring functionality to users of the GNOME desktop', - 'categories': ['Games'], + 'name' : u'Evolution', + 'desc' : u'Evolution provides integrated mail, addressbook and calendaring functionality to users of the GNOME desktop', + 'categories': [u'Games'], 'tags': [] }, { - 'name' : 'Nautilus', - 'desc' : 'Nautilus is a graphical shell for the GNOME desktop enviornment that makes it easy to manage your files and the rest of your system.', - 'categories': ['Games'], + 'name' : u'Nautilus', + 'desc' : u'Nautilus is a graphical shell for the GNOME desktop enviornment that makes it easy to manage your files and the rest of your system.', + 'categories': [u'Games'], 'tags': [] }, { - 'name' : 'Open Office Writer', - 'desc' : 'Create and edit text and graphics in letters, reports, documents, and web pages.', - 'categories': ['Office'], + 'name' : u'Open Office Writer', + 'desc' : u'Create and edit text and graphics in letters, reports, documents, and web pages.', + 'categories': [u'Office'], 'tags': [] }, { - 'name' : 'Open Office Math', - 'desc' : 'Equation editor module for openoffice.org', - 'categories': ['Office'], + 'name' : u'Open Office Math', + 'desc' : u'Equation editor module for openoffice.org', + 'categories': [u'Office'], 'tags': [] } ] app_suites = [ { - 'name' : 'Open Office.Org', - 'desc' : 'The Open Office.Org Suite of applications.', - 'apps' : ['Open Office Writer', 'Open Office Math'] + 'name' : u'Open Office.Org', + 'desc' : u'The Open Office.Org Suite of applications.', + 'apps' : [u'Open Office Writer', u'Open Office Math'] } ] packages = [ { - 'name': 'thunderbird', - 'desc': 'Mozilla Thunderbird mail/newsgroup client', - 'summary': 'Mozilla Thunderbird is a standalone mail and newsgroup client.' + 'name': u'thunderbird', + 'desc': u'Mozilla Thunderbird mail/newsgroup client', + 'summary': u'Mozilla Thunderbird is a standalone mail and newsgroup client.' }, { - 'name': 'openoffice.org-writer', - 'desc': 'The wordprocessor application of openoffice.org.', - 'summary': 'Word Processor module for openoffice.org' + 'name': u'openoffice.org-writer', + 'desc': u'The wordprocessor application of openoffice.org.', + 'summary': u'Word Processor module for openoffice.org' } ] os_releases = [ { - 'name': 'Fedora', - 'version': '9' + 'name': u'Fedora', + 'version': u'9' } ] application_package_relationships = [ { - 'app_name': 'Thunderbird', - 'package_name': 'thunderbird', - 'os_name': 'Fedora', - 'os_version': '9' + 'app_name': u'Thunderbird', + 'package_name': u'thunderbird', + 'os_name': u'Fedora', + 'os_version': u'9' }, { - 'app_name': 'Open Office Writer', - 'package_name': 'openoffice.org-writer', - 'os_name': 'Fedora', - 'os_version': '9' + 'app_name': u'Open Office Writer', + 'package_name': u'openoffice.org-writer', + 'os_name': u'Fedora', + 'os_version': u'10' }, ] -hub.begin() - for os in os_releases: - OSRelease(name=os['name'], version=os['version']) + Collection(name=os['name'], version=os['version']) + +session.flush() for category in categories: Category(name=category['name'], description=category['desc']) +session.flush() + for app in apps: - appobj = Application(name=app['name'], - description=app['desc'], - ) + appobj = Application(name=app['name'], description=app['desc']) for catname in app['categories']: - category = Category.byName(catname) - appobj.addCategory(category) + category = session.query(Category).filter_by(name=catname).one() + appobj.categories.append(category) + + session.flush() for tagname in app['tags']: - tag = None - tag = Tag.byName(tagname) + tag = session.query(Tag).filter_by(name=tagname) - if not tag: + if not tag.count(): + print "Creating new tag", tagname tag = Tag(name=tagname) + else: + tag = tag.one() - appobj.addTag(tag) + appobj.tags.append(tag) + session.flush() for app_suite in app_suites: - suiteobj = ApplicationSuite(name=app_suite['name'], - description=app_suite['desc']) + suiteobj = Suite(name=app_suite['name'], description=app_suite['desc']) for app_name in app_suite['apps']: - app = Application.byName(app_name) - suiteobj.addApplication(app) + app = session.query(Application).filter_by(name=app_name).one() + # FIXME: Make this work + #suiteobj.applications.append(app) + + session.flush() for package in packages: Package(name=package['name'], description=package['desc'], summary=package['summary']) - -osrel_query = OSRelease.select(AND(OSRelease.q.name == 'Fedora', OSRelease.q.version == '9')) -os_rel = list(osrel_query)[0] - -for rel in application_package_relationships: - app = Application.byName(rel['app_name']) - package = Package.byName(rel['package_name']) + session.flush() - relationship_obj = ApplicationPackageRelationship(application=app, - package=package, - os_release=os_rel) +os_rel = session.query(Collection).filter_by(name=u'Fedora', version=u'9').one() - -hub.commit() +for rel in application_package_relationships: + app = session.query(Application).filter_by(name=rel['app_name']).one() + package = session.query(Package).filter_by(name=rel['package_name']).one() + relationship_obj = ApplicationPackage(application=app, + package=package, + os_release=os_rel, + relationship_type=u'uhh?') +session.flush()