~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to contrib/python/compare_records_config.py

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Licensed to the Apache Software Foundation (ASF) under one
 
4
# or more contributor license agreements.  See the NOTICE file
 
5
# distributed with this work for additional information
 
6
# regarding copyright ownership.  The ASF licenses this file
 
7
# to you under the Apache License, Version 2.0 (the
 
8
# "License"); you may not use this file except in compliance
 
9
# with the License.  You may obtain a copy of the License at
 
10
#
 
11
#      http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
# Unless required by applicable law or agreed to in writing, software
 
14
# distributed under the License is distributed on an "AS IS" BASIS,
 
15
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
# See the License for the specific language governing permissions and
 
17
# limitations under the License.
 
18
 
 
19
# Compares two records.config files, printing which items are different and
 
20
# what the before/after values are.
 
21
# Ignores FLOAT differences and @foo@ values from the source code defaults.
 
22
import sys
 
23
 
 
24
def parse_records_file(filename):
 
25
    fh = open(filename)
 
26
    settings = {}
 
27
    for line in fh:
 
28
        line = line.strip()
 
29
        if line.startswith('CONFIG') or line.startswith('LOCAL'):
 
30
            parts = line.split()
 
31
            if parts[2] == 'FLOAT':
 
32
                parts[3] = parts[3].rstrip('0')
 
33
            if parts[2] == 'INT' and parts[3][-1] in 'KMG':
 
34
                unit = parts[3][-1]
 
35
                val = parts[3][:-1]
 
36
                if unit == 'K':
 
37
                    val = int(val) * 1024
 
38
                if unit == 'M':
 
39
                    val = int(val) * 1048576
 
40
                if unit == 'G':
 
41
                    val = int(val) * 1073741824
 
42
                parts[3] = str(val)
 
43
            try:
 
44
                settings[parts[1]] = parts[3]
 
45
            except IndexError:
 
46
                sys.stderr.write("Skipping malformed line: %s\n" % line)
 
47
                continue
 
48
    return settings
 
49
 
 
50
def compare_settings(old, new):
 
51
    for key in sorted(tuple(set(old) | set(new))):
 
52
        if key not in old:
 
53
            old[key] = "missing"
 
54
        if key not in new:
 
55
            new[key] = "missing"
 
56
 
 
57
    for key in sorted(old):
 
58
        if old[key].startswith('@') and old[key].endswith('@'):
 
59
            # Skip predefined values
 
60
            continue
 
61
        if old[key] != new[key]:
 
62
            print "%s %s -> %s" % (key, old[key], new[key])
 
63
 
 
64
if __name__ == '__main__':
 
65
    settings_orig = parse_records_file(sys.argv[1])
 
66
    settings_new = parse_records_file(sys.argv[2])
 
67
    compare_settings(settings_orig, settings_new)