summaryrefslogtreecommitdiffstats
path: root/leafymiracle/models.py
blob: 0e86aa1392ca0fd602449c7dd3f2ca69d5cb62fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright (C) 2011 Luke Macken <lmacken@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from sqlalchemy import Integer, Column, Unicode, UnicodeText, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, scoped_session, sessionmaker

from kitchen.text.converters import to_unicode

DBSession = scoped_session(sessionmaker())
Base = declarative_base()
Base.query = DBSession.query_property()

# Icon Hack. Throw these in a config file.
icons = ['admin-tools', 'apps', 'authoring-and-publishing', 'base-system', 'base-x', 'clustering', 'content', 'core', 'desktops', 'development', 'development-tools', 'dial-up', 'directory-server', 'eclipse', 'editors', 'education', 'electronic-lab', 'engineering-and-scientific', 'font-design', 'fonts', 'games', 'gnome-desktop', 'gnome-software-development', 'graphical-internet', 'graphics', 'hardware-support', 'haskell', 'input-methods', 'java-development', 'java', 'kde-desktop', 'kde-software-development', 'language-support', 'legacy-fonts', 'legacy-network-server', 'lxde-desktop', 'mail-server', 'mysql', 'office', 'printing', 'ruby', 'server-cfg', 'servers', 'sound-and-video', 'sql-server', 'sugar-desktop', 'system-tools', 'text-internet', 'uncategorized', 'virtualization', 'window-managers', 'xfce-desktop', 'xfce-software-development', 'x-software-development']
icon_link = '<img src="http://lmacken.fedorapeople.org/comps-extras/%s.png"/ style="vertical-align:middle;"> %s'


class Root(Base):
    __tablename__ = 'root'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode(255), unique=True)

    categories = relationship("Category", backref="root")

    def __init__(self, name):
        self.name = to_unicode(name)

    def __unicode__(self):
        return icon_link % (self.name.lower(), self.name)


class Category(Base):
    __tablename__ = 'categories'

    id = Column(Integer, primary_key=True)
    category_id = Column(Unicode(255), unique=True)
    name = Column(Unicode(255), unique=True)
    description = Column(UnicodeText)
    root_id = Column(Integer, ForeignKey('root.id'))

    groups = relationship("Group", backref="category")

    def __init__(self, id, name, description):
        self.category_id = to_unicode(id)
        self.name = to_unicode(name)
        self.description = to_unicode(description)

    def __unicode__(self):
        if self.category_id in icons:
            return icon_link % (self.category_id, self.name)
        return self.name


class Group(Base):
    __tablename__ = 'groups'

    id = Column(Integer, primary_key=True)
    group_id = Column(Unicode(255), unique=True)
    name = Column(Unicode(255), unique=True)
    description = Column(UnicodeText)
    category_id = Column(Integer, ForeignKey('categories.id'))

    packages = relationship("Package", backref="group")

    def __init__(self, id, name, description):
        self.group_id = to_unicode(id)
        self.name = to_unicode(name)
        self.description = to_unicode(description)

    def __unicode__(self):
        if self.group_id in icons:
            return icon_link % (self.group_id, self.name)
        return self.name


class Package(Base):
    __tablename__ = 'packages'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode(255), unique=True)

    group_id = Column(Integer, ForeignKey('groups.id'))

    def __init__(self, name):
        self.name = to_unicode(name)

    def __unicode__(self):
        return self.name

    def __jit_data__(self):
        return {
            'hover_html' : """
            <h2>{name}</h2>
            <li><img src="https://admin.fedoraproject.org/community/images/16_pkgdb.png"/><a href="https://admin.fedoraproject.org/community/?package={name}#package_maintenance/details/downloads" target="_blank">Downloads</a></li>
            <li><img src="https://admin.fedoraproject.org/community/images/16_koji.png"/><a href="http://koji.fedoraproject.org/koji/search?terms={name}&type=package&match=exact" target="_blank">Builds</a></li>
            <li><img src="https://admin.fedoraproject.org/community/images/16_bodhi.png"/><a href="https://admin.fedoraproject.org/updates/{name}" target="_blank">Updates</a></li>
            <li><img src="https://admin.fedoraproject.org/community/images/16_bugs.png"/><a href="https://admin.fedoraproject.org/pkgdb/acls/bugs/{name}" target="_blank">Bugs</a></li>
            <li><img src="https://admin.fedoraproject.org/community/images/16_sources.png"/><a href="http://pkgs.fedoraproject.org/gitweb/?p={name}.git" target="_blank">Source</a></li>
            <li><img src="https://admin.fedoraproject.org/community/images/16_pkgdb.png"/><a href="https://admin.fedoraproject.org/pkgdb/acls/name/{name}" target="_blank">Package Info</a></li>
            </ul>
            """.format(**self.__dict__)
        }


def initialize_sql(engine):
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)