Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | PRSERV_DUMPDIR ??= "${LOG_DIR}/db" |
| 2 | LOCALCOUNT_DUMPFILE ??= "${PRSERV_DUMPDIR}/prserv-localcount-exports.inc" |
| 3 | |
| 4 | python migrate_localcount_handler () { |
| 5 | import bb.event |
| 6 | if not e.data: |
| 7 | return |
| 8 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | pv = e.data.getVar('PV') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | if not 'AUTOINC' in pv: |
| 11 | return |
| 12 | |
| 13 | localcounts = bb.persist_data.persist('BB_URI_LOCALCOUNT', e.data) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | pn = e.data.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | revs = localcounts.get_by_pattern('%%-%s_rev' % pn) |
| 16 | counts = localcounts.get_by_pattern('%%-%s_count' % pn) |
| 17 | if not revs or not counts: |
| 18 | return |
| 19 | |
| 20 | if len(revs) != len(counts): |
| 21 | bb.warn("The number of revs and localcounts don't match in %s" % pn) |
| 22 | return |
| 23 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | version = e.data.getVar('PRAUTOINX') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | srcrev = bb.fetch2.get_srcrev(e.data) |
| 26 | base_ver = 'AUTOINC-%s' % version[:version.find(srcrev)] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | pkgarch = e.data.getVar('PACKAGE_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | value = max(int(count) for count in counts) |
| 29 | |
| 30 | if len(revs) == 1: |
| 31 | if srcrev != ('AUTOINC+%s' % revs[0]): |
| 32 | value += 1 |
| 33 | else: |
| 34 | value += 1 |
| 35 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | bb.utils.mkdirhier(e.data.getVar('PRSERV_DUMPDIR')) |
| 37 | df = e.data.getVar('LOCALCOUNT_DUMPFILE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | flock = bb.utils.lockfile("%s.lock" % df) |
| 39 | with open(df, 'a') as fd: |
| 40 | fd.write('PRAUTO$%s$%s$%s = "%s"\n' % |
| 41 | (base_ver, pkgarch, srcrev, str(value))) |
| 42 | bb.utils.unlockfile(flock) |
| 43 | } |
| 44 | |
| 45 | addhandler migrate_localcount_handler |
| 46 | migrate_localcount_handler[eventmask] = "bb.event.RecipeParsed" |