createrepo/__init__.py createrepo/utils.py createrepo/yumbased.py docs/createrepo.8

[email protected] (Seth Vidal)
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
 createrepo/__init__.py |   12 +++++++++---
 createrepo/utils.py    |   12 ++++++++++++
 createrepo/yumbased.py |   47 ++++++++++++++++++++++++++++++++++++++++-------
 docs/createrepo.8      |    3 +++
 4 files changed, 64 insertions(+), 10 deletions(-)

New commits:
commit 6844035a77d6160493868b08b86ea9c7102deac4
Author: Seth Vidal <[email protected]>
Date:   Tue Mar 11 16:18:19 2008 -0400

    more or less complete createrepo --database-only

diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 4d5e470..2a8b06a 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -827,7 +827,10 @@ class MetaDataGenerator:
     def setup_sqlite_dbs(self, initdb=True):
         """sets up the sqlite dbs w/table schemas and db_infos"""
         destdir = os.path.join(self.conf.outputdir, self.conf.tempdir)
-        self.md_sqlite = MetaDataSqlite(destdir)
+        try:
+            self.md_sqlite = MetaDataSqlite(destdir)
+        except sqlite.OperationalError, e:
+            raise MDError, _('Cannot create sqlite databases: %s.\nMaybe you need to clean up a .repodata dir?') % e
         
     
     
@@ -947,7 +950,8 @@ class MetaDataSqlite(object):
              DELETE FROM provides WHERE pkgKey = old.pkgKey;    
              DELETE FROM conflicts WHERE pkgKey = old.pkgKey;    
              DELETE FROM obsoletes WHERE pkgKey = old.pkgKey;
-             END;"""
+             END;""",
+         """INSERT into db_info values (%s, 'direct_create');""" % sqlitecachec.DBVERSION,
              ]
         
         for cmd in schema:
@@ -964,7 +968,8 @@ class MetaDataSqlite(object):
             """CREATE TRIGGER remove_filelist AFTER DELETE ON packages  
                    BEGIN    
                    DELETE FROM filelist WHERE pkgKey = old.pkgKey;  
-                   END;"""
+                   END;""",
+         """INSERT into db_info values (%s, 'direct_create');""" % sqlitecachec.DBVERSION,                   
             ]
         for cmd in schema:
             executeSQL(self.filelists_cursor, cmd)
@@ -980,6 +985,7 @@ class MetaDataSqlite(object):
                  BEGIN    
                  DELETE FROM changelog WHERE pkgKey = old.pkgKey;  
                  END;""",
+         """INSERT into db_info values (%s, 'direct_create');""" % sqlitecachec.DBVERSION,                 
             ]
             
         for cmd in schema:
diff --git a/createrepo/utils.py b/createrepo/utils.py
index 6ba3855..a8a8fb7 100644
--- a/createrepo/utils.py
+++ b/createrepo/utils.py
@@ -136,6 +136,18 @@ def checksum_and_rename(fn_path):
     return (csum, csum_path)
 
 
+
+def encodefilenamelist(filenamelist):
+    return '/'.join(filenamelist)
+
+def encodefiletypelist(filetypelist):
+    result = ''
+
+    for x in filetypelist:
+        result += x[0]
+    return result
+
+
 class MDError(Exception):
     def __init__(self, value=None):
         Exception.__init__(self)
diff --git a/createrepo/yumbased.py b/createrepo/yumbased.py
index 095cbcc..f5f9ab9 100644
--- a/createrepo/yumbased.py
+++ b/createrepo/yumbased.py
@@ -322,8 +322,8 @@ class CreateRepoPackage(YumLocalPackage):
         # - that's what it is
         newflag = flag
         if flag is not None:
-            newflag = flag & 64
-            if newflag == 64:
+            newflag = flag & rpm.RPMSENSE_PREREQ
+            if newflag == rpm.RPMSENSE_PREREQ:
                 return 1
             else:
                 return 0
@@ -492,14 +492,47 @@ class CreateRepoPackage(YumLocalPackage):
 
     def do_filelists_sqlite_dump(self, cur):
         """inserts filelists data in place, this assumes the tables exist"""
-        #FIXME    
-        pass
-
+        # insert packagenumber + checksum into 'packages' table
+        q = 'insert into packages values (?, ?)'
+        p = (self.crp_packagenumber, self.checksum)
+        
+        cur.execute(q, p)
+        
+        # break up filelists and encode them
+        dirs = {}
+        for (filetype, files) in [('file', self.filelist), ('dir', self.dirlist),
+                                  ('ghost', self.ghostlist)]:
+            for filename in files:
+                (dirname,filename) = (os.path.split(filename))
+                if not dirs.has_key(dirname):
+                    dirs[dirname] = {'files':[], 'types':[]}
+                dirs[dirname]['files'].append(filename)
+                dirs[dirname]['types'].append(filetype)
+
+        # insert packagenumber|dir|files|types into files table
+        p = []
+        for (dirname,direc) in dirs.items():
+            p.append((self.crp_packagenumber, dirname, 
+                 utils.encodefilenamelist(direc['files']),
+                 utils.encodefiletypelist(direc['types'])))
+        if p:
+            q = 'insert into filelist values (?, ?, ?, ?)'
+            cur.executemany(q, p)
+        
+        
     def do_other_sqlite_dump(self, cur):
         """inserts changelog data in place, this assumes the tables exist"""    
-        #FIXME
-        pass
+        # insert packagenumber + checksum into 'packages' table
+        q = 'insert into packages values (?, ?)'
+        p = (self.crp_packagenumber, self.checksum)
         
+        cur.execute(q, p)
+
+        if self.changelog:
+            q = 'insert into changelog ("pkgKey", "date", "author", "changelog") values (%s, ?, ?, ?)' % self.crp_packagenumber
+            cur.executemany(q, self.changelog)
+
+       
     def do_sqlite_dump(self, md_sqlite):
         """write the metadata out to the sqlite dbs"""
         self.do_primary_sqlite_dump(md_sqlite.primary_cursor)
diff --git a/docs/createrepo.8 b/docs/createrepo.8
index 419e872..52a5280 100644
--- a/docs/createrepo.8
+++ b/docs/createrepo.8
@@ -63,6 +63,9 @@ Show help menu.
 .IP "\fB\-d --database\fP"
 Generate sqlite databases for use with yum.
 
+.IP "\fB\--database-only\fP"
+Generate only the sqlite dbs. Do not create the xml metadata at all.
+
 .SH "EXAMPLES"
 Here is an example of a repository with a groups file. Note that the
 groups file should be in the same directory as the rpm packages
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.