Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
2 | ddosia | 1 | #!/usr/bin/env python2.5 |
2 | |||
3 | import sqlalchemy.orm |
||
4 | import optparse |
||
5 | |||
6 | import pkg.entities |
||
7 | from pkg.entities import Distr, Codename, Suite, Path |
||
8 | import pkg.scanner |
||
9 | |||
10 | cmd_parser = optparse.OptionParser(usage = "usage: %prog [options] scan_dir", |
||
11 | description="%prog - scans scan_dir and finds all repos", |
||
12 | version = "0.0.1") |
||
13 | |||
14 | cmd_parser.add_option("--create-db", action="store_true", dest="create_db", default=False, |
||
15 | help = "create a database, does not effect if database already exists",) |
||
16 | cmd_parser.add_option("--tbl-prefix", type="string", action="store", dest="sql_tbl_prfx", |
||
17 | help = "this prefix will be used during creation database`s tables" ) |
||
18 | cmd_parser.add_option("--connect-str", type="string", action="store", dest="sql_connect_str", default="sqlite:///repo.db", |
||
19 | help = "this option set current sql-engine and additionally username and password." + |
||
20 | "For more instructions see \"sqlalchemy\" 'create_engine'`s references manual. default value is 'sqlite:///repo.db'") |
||
21 | cmd_parser.add_option("--fill-tbls", action="store_true", dest="verbose", dest="fill_tbls", default=False, |
||
22 | help = "fill main tables with persist information"); |
||
23 | cmd_parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False); |
||
24 | |||
25 | (options, args) = cmd_parser.parse_args() |
||
26 | |||
27 | if len(args) != 1: |
||
28 | cmd_parser.error("incorrect number of arguments") |
||
29 | if options.verbose: |
||
30 | pkg.entities.Base.metadata.bind.echo=True |
||
31 | if options.create_db: |
||
32 | pkg.entities.Base.metadata.create_all() |
||
33 | else: |
||
34 | if options.sql_tbl_prfx != None: |
||
35 | cmd_parser.error("incorrect syntax: --tbl-prefix can be used only with --create-db") |
||
36 | |||
37 | sess = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=pkg.entities.Base.metadata.bind)) |
||
38 | |||
39 | if options.fill_tbls: |
||
40 | ub = Distr('ubuntu') |
||
41 | ub.codenames = [Codename("intrepid")] |
||
42 | |||
43 | deb = Distr('debian') |
||
44 | deb.codenames = [Codename("etch"), Codename("lenny")] |
||
45 | |||
46 | sess.add_all([ub, deb]) |
||
47 | sess.commit() |
||
48 | |||
49 | scan_inf = pkg.scanner.start(args[0]) |
||
50 | cns_r = dict([ [cn.caption, cn] for cn in sess.query(Codename).order_by(Codename.id) ]) |
||
51 | |||
52 | for cn_l in scan_inf: |
||
53 | if cn_l in cns_r: |
||
54 | sts_r = dict([ [st_r.caption, st_r] for st_r in cns_r[cn_l].suites ]) |
||
55 | for st_l in scan_inf[cn_l]: |
||
56 | if st_l in sts_r: |
||
57 | print (sts_r[st_l].pathes, '<<---') |
||
58 | else: |
||
59 | cns_r[cn_l].suites.append(Suite(st_l)) |
||
60 | sts_r[st_l] = Suite(st_l) |
||
61 | sts_r[st_l].codename = cns_r[cn_l] |
||
62 | print (sess.dirty) |
||
63 | |||
64 | sess.commit() |
||
65 | # print (cns_r[cn_l], cns_r[cn_l].distr) |
||
66 | |||
67 | #for dn_r in dst_inf: |
||
68 | #cn_inf = dict([[cn.caption, cn] for cn in dst_inf[dn_r].codenames]) |
||
69 | #print (scan_inf | cn_inf) |
||
70 | #for cn_l in scan_inf: |
||
71 | #if cn_l in cn_inf: |
||
72 | #print (cn_l, "in", dn_r) |
||
73 | |||
74 | # d = dict([(cn.caption, cn) for cn in dst_inf[dn].codenames]) |
||
75 | # print |
||
76 | # for cn in scan_inf: |
||
77 | # print (cn, "in", dn) |
||
78 | |||
79 | |||
80 | |||
81 | #for cn in repoinf: |
||
82 | #print (cn) |
||
83 | #for st in repoinf[cn]: |
||
84 | #print ("====", st) |
||
85 | #for p in repoinf[cn][st]: |
||
86 | #print ("========", p) |
||
87 | |||
88 | |||
89 | #distr = ents.Distr('ubuntu') |
||
90 | |||
91 | #sess.add(distr) |
||
92 | #sess.commit() |
||
93 |