-
Notifications
You must be signed in to change notification settings - Fork 152
/
cleandb.py
63 lines (46 loc) · 1.56 KB
/
cleandb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
import sys, re
import os
from prjxray import util
def run(globaldb, localdb, verbose=False):
local_db_files = list()
work_db_files = list()
# get DB files
global_entries = {}
local_entries = {}
final_entries = {}
verbose and print("removing %s from %s" % (localdb, globaldb))
# parse global db
for line, (tag, bits, mode) in util.parse_db_lines(globaldb):
global_entries[tag] = bits
# parse local db
for line, (tag, bits, mode) in util.parse_db_lines(localdb):
local_entries[tag] = bits
for entry in global_entries:
if entry not in local_entries:
final_entries[entry] = global_entries[entry]
else:
verbose and print("Removing entry %s" % entry)
util.write_db_lines(globaldb, final_entries)
def main():
import argparse
parser = argparse.ArgumentParser(
description="Remove partial DB from global DB")
parser.add_argument('--verbose', action='store_true', help='')
parser.add_argument(
'--localdb', action='store', help='Path to work database')
parser.add_argument(
'--globaldb', action='store', help='Path to global database')
args = parser.parse_args()
run(args.globaldb, args.localdb, args.verbose)
if __name__ == '__main__':
main()