Subversion Repositories apt-scan


Blame | Last modification | View Log | RSS feed

#!/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')