diff options
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/prservice.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/meta/lib/oe/prservice.py b/meta/lib/oe/prservice.py new file mode 100644 index 0000000000..fa6718e914 --- /dev/null +++ b/meta/lib/oe/prservice.py | |||
@@ -0,0 +1,113 @@ | |||
1 | import bb | ||
2 | |||
3 | def prserv_make_conn(d): | ||
4 | import prserv.serv | ||
5 | host = d.getVar("PRSERV_HOST",True) | ||
6 | port = d.getVar("PRSERV_PORT",True) | ||
7 | try: | ||
8 | conn = None | ||
9 | conn = prserv.serv.PRServerConnection(host,int(port)) | ||
10 | d.setVar("__PRSERV_CONN",conn) | ||
11 | except Exception, exc: | ||
12 | bb.fatal("Connecting to PR service %s:%s failed: %s" % (host, port, str(exc))) | ||
13 | |||
14 | return conn | ||
15 | |||
16 | def prserv_dump_db(d): | ||
17 | if d.getVar('USE_PR_SERV', True) != "1": | ||
18 | bb.error("Not using network based PR service") | ||
19 | return None | ||
20 | |||
21 | conn = d.getVar("__PRSERV_CONN", True) | ||
22 | if conn is None: | ||
23 | conn = prserv_make_conn(d) | ||
24 | if conn is None: | ||
25 | bb.error("Making connection failed to remote PR service") | ||
26 | return None | ||
27 | |||
28 | #dump db | ||
29 | opt_version = d.getVar('PRSERV_DUMPOPT_VERSION', True) | ||
30 | opt_pkgarch = d.getVar('PRSERV_DUMPOPT_PKGARCH', True) | ||
31 | opt_checksum = d.getVar('PRSERV_DUMPOPT_CHECKSUM', True) | ||
32 | opt_col = ("1" == d.getVar('PRSERV_DUMPOPT_COL', True)) | ||
33 | return conn.export(opt_version, opt_pkgarch, opt_checksum, opt_col) | ||
34 | |||
35 | def prserv_import_db(d, filter_version=None, filter_pkgarch=None, filter_checksum=None): | ||
36 | if d.getVar('USE_PR_SERV', True) != "1": | ||
37 | bb.error("Not using network based PR service") | ||
38 | return None | ||
39 | |||
40 | conn = d.getVar("__PRSERV_CONN", True) | ||
41 | if conn is None: | ||
42 | conn = prserv_make_conn(d) | ||
43 | if conn is None: | ||
44 | bb.error("Making connection failed to remote PR service") | ||
45 | return None | ||
46 | #get the entry values | ||
47 | imported = [] | ||
48 | prefix = "PRAUTO$" | ||
49 | for v in d.keys(): | ||
50 | if v.startswith(prefix): | ||
51 | (remain, sep, checksum) = v.rpartition('$') | ||
52 | (remain, sep, pkgarch) = remain.rpartition('$') | ||
53 | (remain, sep, version) = remain.rpartition('$') | ||
54 | if (remain + '$' != prefix) or \ | ||
55 | (filter_version and filter_version != version) or \ | ||
56 | (filter_pkgarch and filter_pkgarch != pkgarch) or \ | ||
57 | (filter_checksum and filter_checksum != checksum): | ||
58 | continue | ||
59 | try: | ||
60 | value = int(d.getVar(remain + '$' + version + '$' + pkgarch + '$' + checksum, True)) | ||
61 | except BaseException as exc: | ||
62 | bb.debug("Not valid value of %s:%s" % (v,str(exc))) | ||
63 | continue | ||
64 | ret = conn.importone(version,pkgarch,checksum,value) | ||
65 | if ret != value: | ||
66 | bb.error("importing(%s,%s,%s,%d) failed. DB may have larger value %d" % (version,pkgarch,checksum,value,ret)) | ||
67 | else: | ||
68 | imported.append((version,pkgarch,checksum,value)) | ||
69 | return imported | ||
70 | |||
71 | def prserv_export_tofile(d, metainfo, datainfo, lockdown, nomax=False): | ||
72 | import bb.utils | ||
73 | #initilize the output file | ||
74 | bb.utils.mkdirhier(d.getVar('PRSERV_DUMPDIR', True)) | ||
75 | df = d.getVar('PRSERV_DUMPFILE', True) | ||
76 | #write data | ||
77 | lf = bb.utils.lockfile("%s.lock" % df) | ||
78 | f = open(df, "a") | ||
79 | if metainfo: | ||
80 | #dump column info | ||
81 | f.write("#PR_core_ver = \"%s\"\n\n" % metainfo['core_ver']); | ||
82 | f.write("#Table: %s\n" % metainfo['tbl_name']) | ||
83 | f.write("#Columns:\n") | ||
84 | f.write("#name \t type \t notn \t dflt \t pk\n") | ||
85 | f.write("#----------\t --------\t --------\t --------\t ----\n") | ||
86 | for i in range(len(metainfo['col_info'])): | ||
87 | f.write("#%10s\t %8s\t %8s\t %8s\t %4s\n" % | ||
88 | (metainfo['col_info'][i]['name'], | ||
89 | metainfo['col_info'][i]['type'], | ||
90 | metainfo['col_info'][i]['notnull'], | ||
91 | metainfo['col_info'][i]['dflt_value'], | ||
92 | metainfo['col_info'][i]['pk'])) | ||
93 | f.write("\n") | ||
94 | |||
95 | if lockdown: | ||
96 | f.write("PRSERV_LOCKDOWN = \"1\"\n\n") | ||
97 | |||
98 | if datainfo: | ||
99 | idx = {} | ||
100 | for i in range(len(datainfo)): | ||
101 | pkgarch = datainfo[i]['pkgarch'] | ||
102 | value = datainfo[i]['value'] | ||
103 | if not idx.has_key(pkgarch): | ||
104 | idx[pkgarch] = i | ||
105 | elif value > datainfo[idx[pkgarch]]['value']: | ||
106 | idx[pkgarch] = i | ||
107 | f.write("PRAUTO$%s$%s$%s = \"%s\"\n" % | ||
108 | (str(datainfo[i]['version']), pkgarch, str(datainfo[i]['checksum']), str(value))) | ||
109 | if not nomax: | ||
110 | for i in idx: | ||
111 | f.write("PRAUTO_%s_%s = \"%s\"\n" % (str(datainfo[idx[i]]['version']),str(datainfo[idx[i]]['pkgarch']),str(datainfo[idx[i]]['value']))) | ||
112 | f.close() | ||
113 | bb.utils.unlockfile(lf) | ||