[csw-devel] SF.net SVN: gar:[20534] csw/mgar/gar/v2/lib
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Fri Mar 29 17:11:56 CET 2013
Revision: 20534
http://gar.svn.sourceforge.net/gar/?rev=20534&view=rev
Author: wahwah
Date: 2013-03-29 16:11:55 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
pkgdb: Store user and datestamp who added a pkg
An additional timestamp to keep track which package was added when to a catalog
in the database. It doesn't have to be the package maintainer, just someone
who did the adding. User name is retrieved from HTTP auth, or it's the system
user when run from the console.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/checkpkg_lib.py
csw/mgar/gar/v2/lib/python/database.py
csw/mgar/gar/v2/lib/python/models.py
csw/mgar/gar/v2/lib/python/pkgdb.py
csw/mgar/gar/v2/lib/web/releases_web.py
Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py 2013-03-29 16:11:39 UTC (rev 20533)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py 2013-03-29 16:11:55 UTC (rev 20534)
@@ -6,6 +6,7 @@
import copy
from Cheetah import Template
import logging
+import getpass
import package_stats
import package_checks
import sqlobject
@@ -1014,10 +1015,12 @@
m.Srv4FileInCatalog.q.srv4file!=sqo_srv4))
return res
- def AddSrv4ToCatalog(self, sqo_srv4, osrel, arch, catrel):
+ def AddSrv4ToCatalog(self, sqo_srv4, osrel, arch, catrel, who=None):
"""Registers a srv4 file in a catalog."""
- logging.debug("AddSrv4ToCatalog(%s, %s, %s, %s)",
- sqo_srv4, osrel, arch, catrel)
+ logging.debug("AddSrv4ToCatalog(%s, %s, %s, %s, %s)",
+ sqo_srv4, osrel, arch, catrel, who)
+ if not who:
+ who = 'unknown'
# There are only i386 and sparc catalogs.
if arch != 'i386' and arch != 'sparc':
raise CatalogDatabaseError("Wrong architecture: %s" % arch)
@@ -1069,7 +1072,8 @@
arch=sqo_arch,
osrel=sqo_osrel,
catrel=sqo_catrel,
- srv4file=sqo_srv4)
+ srv4file=sqo_srv4,
+ created_by=getpass.getuser())
def RemoveSrv4(self, sqo_srv4, osrel, arch, catrel):
sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
Modified: csw/mgar/gar/v2/lib/python/database.py
===================================================================
--- csw/mgar/gar/v2/lib/python/database.py 2013-03-29 16:11:39 UTC (rev 20533)
+++ csw/mgar/gar/v2/lib/python/database.py 2013-03-29 16:11:55 UTC (rev 20534)
@@ -10,7 +10,7 @@
import system_pkgmap
CONFIG_DB_SCHEMA = "db_schema_version"
-DB_SCHEMA_VERSION = 10L
+DB_SCHEMA_VERSION = 12L
TABLES_THAT_NEED_UPDATES = (m.CswFile,)
# This list of tables is sensitive to the order in which tables are created.
Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py 2013-03-29 16:11:39 UTC (rev 20533)
+++ csw/mgar/gar/v2/lib/python/models.py 2013-03-29 16:11:55 UTC (rev 20534)
@@ -423,6 +423,10 @@
osrel = sqlobject.ForeignKey('OsRelease', notNone=True)
catrel = sqlobject.ForeignKey('CatalogRelease', notNone=True)
srv4file = sqlobject.ForeignKey('Srv4FileStats', notNone=True)
+ created_on = sqlobject.DateTimeCol(
+ notNone=True,
+ default=sqlobject.DateTimeCol.now)
+ created_by = sqlobject.UnicodeCol(length=50, notNone=True)
uniqueness_idx = sqlobject.DatabaseIndex(
'arch', 'osrel', 'catrel', 'srv4file',
unique=True)
Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py 2013-03-29 16:11:39 UTC (rev 20533)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py 2013-03-29 16:11:55 UTC (rev 20534)
@@ -12,6 +12,7 @@
import configuration
import database
import datetime
+import getpass
import logging
import models as m
import optparse
@@ -283,6 +284,7 @@
logging.info(
" + %s",
cat_entry_by_md5[md5]["file_basename"])
+ user = getpass.getuser()
# Remove
# We could use checkpkg_lib.Catalog.RemoveSrv4(), but it would redo
# many of the database queries and would be much slower.
@@ -309,7 +311,8 @@
package_stats.PackageStats.ImportPkg(stats, True)
try:
db_catalog.AddSrv4ToCatalog(
- sqo_srv4, osrel, arch, catrel)
+ sqo_srv4, osrel, arch, catrel,
+ who=user)
except checkpkg_lib.CatalogDatabaseError, e:
logging.warning(
"Could not insert %s (%s) into the database. %s",
@@ -489,6 +492,7 @@
elif command == 'add-to-cat':
if len(args) <= 3:
raise UsageError("Not enough arguments, see usage.")
+ user = getpass.getuser()
osrel, arch, catrel= args[:3]
c = checkpkg_lib.Catalog()
md5_sums = args[3:]
@@ -497,7 +501,7 @@
try:
sqo_srv4 = m.Srv4FileStats.select(
m.Srv4FileStats.q.md5_sum==md5_sum).getOne()
- c.AddSrv4ToCatalog(sqo_srv4, osrel, arch, catrel)
+ c.AddSrv4ToCatalog(sqo_srv4, osrel, arch, catrel, who=user)
except sqlobject.main.SQLObjectNotFound, e:
logging.warning("Srv4 file %s was not found in the database.",
md5_sum)
Modified: csw/mgar/gar/v2/lib/web/releases_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/releases_web.py 2013-03-29 16:11:39 UTC (rev 20533)
+++ csw/mgar/gar/v2/lib/web/releases_web.py 2013-03-29 16:11:55 UTC (rev 20534)
@@ -6,6 +6,7 @@
import os
sys.path.append(os.path.join(os.path.split(__file__)[0], "..", ".."))
+import base64
import web
import sqlobject
import json
@@ -189,7 +190,16 @@
for pkg_in_catalog in res:
srv4_to_remove = pkg_in_catalog.srv4file
c.RemoveSrv4(srv4_to_remove, osrel_name, arch_name, catrel_name)
- c.AddSrv4ToCatalog(srv4, osrel_name, arch_name, catrel_name)
+
+ # Retrieving authentication data from the HTTP environment.
+ # If the auth data isn't there, this code will fail.
+ auth = web.ctx.env.get('HTTP_AUTHORIZATION')
+ if not auth:
+ raise web.forbidden()
+ auth = re.sub('^Basic ','',auth)
+ username, password = base64.decodestring(auth).split(':')
+
+ c.AddSrv4ToCatalog(srv4, osrel_name, arch_name, catrel_name, who=username)
web.header(
'Content-type',
'application/x-vnd.opencsw.pkg;type=catalog-update')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list