Update README for archival
[reddit.git] / r2 / updateini.py
blob56bbe327e576cc6150b378463fb9de0cfb88c2f9
1 #!/usr/bin/env python
2 # The contents of this file are subject to the Common Public Attribution
3 # License Version 1.0. (the "License"); you may not use this file except in
4 # compliance with the License. You may obtain a copy of the License at
5 # http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
6 # License Version 1.1, but Sections 14 and 15 have been added to cover use of
7 # software over a computer network and provide for limited attribution for the
8 # Original Developer. In addition, Exhibit A has been modified to be consistent
9 # with Exhibit B.
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13 # the specific language governing rights and limitations under the License.
15 # The Original Code is reddit.
17 # The Original Developer is the Initial Developer. The Initial Developer of
18 # the Original Code is reddit Inc.
20 # All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
21 # Inc. All Rights Reserved.
22 ###############################################################################
24 from ConfigParser import MissingSectionHeaderError
25 from StringIO import StringIO
26 import sys
28 from r2.lib.utils import parse_ini_file
30 HEADER = '''
31 # YOU DO NOT NEED TO EDIT THIS FILE
32 # This is a generated file. To update the configuration,
33 # edit the *.update file of the same name, and then
34 # run 'make ini'
35 # Configuration settings in the *.update file will override
36 # or be added to the base 'example.ini' file.
37 '''
39 def main(source_ini, update_ini):
40 with open(source_ini) as source:
41 parser = parse_ini_file(source)
42 with open(update_ini) as f:
43 updates = f.read()
44 try:
45 # Existing *.update files don't include section
46 # headers; inject a [DEFAULT] header if the parsing
47 # fails
48 parser.readfp(StringIO(updates))
49 except MissingSectionHeaderError:
50 updates = "[DEFAULT]\n" + updates
51 parser.readfp(StringIO(updates))
52 print HEADER
53 parser.write(sys.stdout)
55 if __name__ == '__main__':
56 args = sys.argv
57 if len(args) != 3:
58 print 'usage: %s [source] [update]' % sys.argv[0]
59 sys.exit(1)
60 else:
61 main(sys.argv[1], sys.argv[2])