diff options
author | Lianhao Lu <lianhao.lu@intel.com> | 2011-12-22 15:29:11 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-01-11 10:37:43 +0000 |
commit | a05e3a57c6f567578faeb31fae89b20e22850af4 (patch) | |
tree | 0fb66b3c74a9c011190179f0004024be5927570c /meta/lib | |
parent | 6bde156c5ce58c8e55cd6f5fd5f87982a919ba34 (diff) | |
download | poky-a05e3a57c6f567578faeb31fae89b20e22850af4.tar.gz |
meta/PRService: Added export/import fuctions.
[YOCTO #1556]
- Modified meta/class/package.bbclass and prserv.bbclass according to
the change in PR service by adding PACKAGE_ARCH into the query tuple.
- Added prexport.bbclass, primport.bbclass to export/import AUTOPR
values from/to PRService.
- Move PR service related common code to lib/oe/prservice.py.
- Supported reading the AUTOPR values from the exported .inc file
instead of reading it from remote PR service.
- Created a new script bitbake-prserv-tool to export/import the AUTOPR
values from/to the PR service.
Typical usage scenario of the export/import is:
1. bitbake-prserv-tool export <file> to export the AUTOPR values from
the current PR service into an exported .inc file.
2. Others may use that exported .inc file(to be included in the
local.conf) to lockdown and reproduce the same AUTOPR when generating
package feeds.
3. Others may "bitbake-prserv-tool import <file>" to import the AUTOPR
values into their own PR service and the AUTOPR values will be
incremented from there.
(From OE-Core rev: 9979107d8eaf503efd921564385859b1e83dbb3c)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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) | ||