summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalph Bean <ralph.bean@gmail.com>2011-04-12 18:15:58 -0400
committerRalph Bean <ralph.bean@gmail.com>2011-04-12 18:18:16 -0400
commita549f749323b56679f3bba657a045078207e18c3 (patch)
treed2ee40caad78b4fff2870323a794a4d64d3d640a
parent340a0886d9aaa3e83c3317580aa3234c84bf3909 (diff)
downloadleafymiracle-a549f749323b56679f3bba657a045078207e18c3.zip
leafymiracle-a549f749323b56679f3bba657a045078207e18c3.tar.gz
leafymiracle-a549f749323b56679f3bba657a045078207e18c3.tar.xz
basic model and scraping for dependencies.
-rw-r--r--leafymiracle/models.py18
-rw-r--r--leafymiracle/populate.py19
2 files changed, 35 insertions, 2 deletions
diff --git a/leafymiracle/models.py b/leafymiracle/models.py
index 0e86aa1..0edbdd4 100644
--- a/leafymiracle/models.py
+++ b/leafymiracle/models.py
@@ -13,7 +13,7 @@
# 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 import Integer, Column, Unicode, UnicodeText, ForeignKey, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, scoped_session, sessionmaker
@@ -115,6 +115,22 @@ class Package(Base):
""".format(**self.__dict__)
}
+dependencies_mapping = Table(
+ 'packages_dependencies_mapping', Base.metadata,
+ Column('depender_id', Integer,
+ ForeignKey('packages.id'), primary_key=True),
+ Column('dependee_id', Integer,
+ ForeignKey('packages.id'), primary_key=True))
+
+Package.__mapper__.add_property('dependencies', relationship(
+ Package,
+ primaryjoin=Package.id==dependencies_mapping.c.dependee_id,
+ secondaryjoin=dependencies_mapping.c.depender_id==Package.id,
+ secondary=dependencies_mapping,
+ doc="List of this packages' dependencies!",
+))
+
+
def initialize_sql(engine):
DBSession.configure(bind=engine)
diff --git a/leafymiracle/populate.py b/leafymiracle/populate.py
index 9f78fc5..cb3c7d4 100644
--- a/leafymiracle/populate.py
+++ b/leafymiracle/populate.py
@@ -19,7 +19,8 @@ from kitchen.text.converters import to_unicode
from models import Root, Category, Group, Package, DBSession, initialize_sql
-def populate(comps='comps-f16'):
+
+def populate(comps='comps-f16', do_dependencies=True):
from yum.comps import Comps
session = DBSession()
@@ -58,6 +59,22 @@ def populate(comps='comps-f16'):
session.flush()
+ if do_dependencies:
+ yumobj = yum.YumBase()
+ yumobj.setCacheDir()
+ for package in session.query(Package).all():
+ deps = yumobj.pkgSack.searchNevra(name=package.name)[0]
+ deps_d = pkg.findDeps([pkg])
+ deps = [tup[0] for tup in deps_d[deps_d.keys()[0]].keys()]
+
+ for dep in deps:
+ dep_as_package = session.query(Package)\
+ .filter_by(name=dep).one()
+ if dep_as_package not in package.dependencies:
+ package.dependencies.append(dep_as_package)
+
+
+
session.commit()
def build_comps():