Subversion Repositories apt-scan

Compare Revisions

Ignore whitespace Rev 1 → Rev 2

New file
0,0 → 1,48
import os
import os.path
def start(spath):
this function takes one argument "spath", directory
which from we should start to search repos
and returns dict with search result
repoinf = dict()
for root, dirs, files in os.walk(spath):
#python2.6`s os.walk() has new param "followsymlinks" and this hack will be removed as soon as possible
for dname in dirs:
lrepoinf = dict()
if os.path.islink(os.path.join(root, dname)):
lrepoinf = start(os.path.join(root, dname))
for cn in lrepoinf:
if cn in repoinf:
for st in lrepoinf[cn]:
if st in repoinf[cn]:
repoinf[cn][st] = lrepoinf[cn][st]
repoinf[cn] = lrepoinf[cn]
if "Release" in files:
cn = "" #codename
st = "" #suite
rfile = open (os.path.join(root, "Release"))
for l in rfile:
if l.startswith("Codename"):
#a little hack, coz of "infra"`s stupid "Codename"s like "interpid-security" instadeof "interpid"
cn = l[9:].strip().split("-")[0]
elif l.startswith("Suite"):
st = l[6:].strip()
if len(cn) > 0 and len(st) > 0:
if cn in repoinf:
if st in repoinf[cn]:
repoinf[cn][st] = set((root, ))
repoinf[cn] = dict()
repoinf[cn][st] = set((root,))
return repoinf
New file
0,0 → 1,4
__all__ = ["entities"]
__doc__ = """
this is a top package
New file
0,0 → 1,63
import sqlalchemy.orm
import sqlalchemy.ext
import sqlalchemy.ext.declarative
import sqlite3
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine, UniqueConstraint
from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base
DB_STRING = "sqlite:///repo.db"
Base = declarative_base(bind = create_engine(DB_STRING, module = sqlite3.dbapi2, echo = False))
class Distr(Base):
__tablename__= 'distr'
id = Column("d_id", Integer, primary_key=True)
caption = Column("d_caption", String(50), nullable=False, unique=True)
codenames = relation("Codename", primaryjoin=" == Codename.distr_id", order_by="Codename.distr_id", backref="distr")
def __init__(self, caption):
self.caption = caption
def __repr__(self):
return "<Distr('%s')>" % (self.caption)
class Codename(Base):
__tablename__ = "codename"
id = Column("cn_id", Integer, primary_key=True)
distr_id = Column("d_id", Integer, ForeignKey("distr.d_id"), nullable=False)
caption = Column("cn_caption", String(50), nullable=False)
UniqueConstraint("distr_id", "caption")
suites = relation("Suite", primaryjoin=" == Suite.codename_id", order_by="Suite.codename_id", backref="suite")
def __init__(self, caption):
self.caption = caption
def __repr__(self):
return "<Codename('%s')>" % (self.caption)
class Suite(Base):
__tablename__ = "suite"
id = Column("st_id", Integer, primary_key=True)
codename_id = Column ("cn_id", Integer, ForeignKey("codename.cn_id"), nullable=False)
caption = Column ("st_caption", String(50), nullable=False)
UniqueConstraint ("cn_id", "st_caption")
pathes = relation("Path", primaryjoin=" == Path.suite_id", order_by="Path.suite_id", backref="suite")
def __init__(self, caption):
self.caption = caption
def __repr__(self):
return "<Suite('%s')>" % (self.caption)
class Path(Base):
__tablename__ = "path"
suite_id = Column("st_id", Integer, ForeignKey("suite.st_id"), primary_key=True)
path = Column ("st_caption", String(50), primary_key=True)
def __init__(self, path):
self.path = path
def __repr__(self):
return "<Path('%s')>" % (self.path)
New file
0,0 → 1,93
#!/usr/bin/env python2.5
import sqlalchemy.orm
import optparse
import pkg.entities
from pkg.entities import Distr, Codename, Suite, Path
import pkg.scanner
cmd_parser = optparse.OptionParser(usage = "usage: %prog [options] scan_dir",
description="%prog - scans scan_dir and finds all repos",
version = "0.0.1")
cmd_parser.add_option("--create-db", action="store_true", dest="create_db", default=False,
help = "create a database, does not effect if database already exists",)
cmd_parser.add_option("--tbl-prefix", type="string", action="store", dest="sql_tbl_prfx",
help = "this prefix will be used during creation database`s tables" )
cmd_parser.add_option("--connect-str", type="string", action="store", dest="sql_connect_str", default="sqlite:///repo.db",
help = "this option set current sql-engine and additionally username and password." +
"For more instructions see \"sqlalchemy\" 'create_engine'`s references manual. default value is 'sqlite:///repo.db'")
cmd_parser.add_option("--fill-tbls", action="store_true", dest="verbose", dest="fill_tbls", default=False,
help = "fill main tables with persist information");
cmd_parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False);
(options, args) = cmd_parser.parse_args()
if len(args) != 1:
cmd_parser.error("incorrect number of arguments")
if options.verbose:
if options.create_db:
if options.sql_tbl_prfx != None:
cmd_parser.error("incorrect syntax: --tbl-prefix can be used only with --create-db")
sess = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=pkg.entities.Base.metadata.bind))
if options.fill_tbls:
ub = Distr('ubuntu')
ub.codenames = [Codename("intrepid")]
deb = Distr('debian')
deb.codenames = [Codename("etch"), Codename("lenny")]
sess.add_all([ub, deb])
scan_inf = pkg.scanner.start(args[0])
cns_r = dict([ [cn.caption, cn] for cn in sess.query(Codename).order_by( ])
for cn_l in scan_inf:
if cn_l in cns_r:
sts_r = dict([ [st_r.caption, st_r] for st_r in cns_r[cn_l].suites ])
for st_l in scan_inf[cn_l]:
if st_l in sts_r:
print (sts_r[st_l].pathes, '<<---')
sts_r[st_l] = Suite(st_l)
sts_r[st_l].codename = cns_r[cn_l]
print (sess.dirty)
# print (cns_r[cn_l], cns_r[cn_l].distr)
#for dn_r in dst_inf:
#cn_inf = dict([[cn.caption, cn] for cn in dst_inf[dn_r].codenames])
#print (scan_inf | cn_inf)
#for cn_l in scan_inf:
#if cn_l in cn_inf:
#print (cn_l, "in", dn_r)
# d = dict([(cn.caption, cn) for cn in dst_inf[dn].codenames])
# print
# for cn in scan_inf:
# print (cn, "in", dn)
#for cn in repoinf:
#print (cn)
#for st in repoinf[cn]:
#print ("====", st)
#for p in repoinf[cn][st]:
#print ("========", p)
#distr = ents.Distr('ubuntu')
Property changes:
Added: svn:executable
## -0,0 +1 ##
\ No newline at end of property