2 # Copyright 1999-2013 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
6 # archive-conf -- save off a config file in the dispatch-conf archive dir
8 # Written by Wayne Davison <gentoo@blorf.net> with code snagged from
9 # Jeremy Wohl's dispatch-conf script and the portage chkcontents script.
12 from __future__ import print_function
16 from os import path as osp
17 pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
18 sys.path.insert(0, pym_path)
20 portage._internal_caller = True
22 import portage.dispatch_conf
23 from portage import os
24 from portage.checksum import perform_md5
26 FIND_EXTANT_CONTENTS = "find %s -name CONTENTS"
28 MANDATORY_OPTS = [ 'archive-dir' ]
35 options = portage.dispatch_conf.read_config(MANDATORY_OPTS)
37 for conf in sys.argv[1:]:
38 if not os.path.isabs(conf):
39 conf = os.path.abspath(conf)
41 md5_match_hash[conf] = ''
43 # Find all the CONTENT files in VDB_PATH.
44 with os.popen(FIND_EXTANT_CONTENTS % (os.path.join(portage.settings['EROOT'], portage.VDB_PATH))) as f:
45 content_files += f.readlines()
47 # Search for the saved md5 checksum of all the specified config files
48 # and see if the current file is unmodified or not.
51 for filename in content_files:
52 filename = filename.rstrip()
54 contents = open(filename, "r")
56 print('archive-conf: Unable to open %s: %s' % (filename, e), file=sys.stderr)
58 lines = contents.readlines()
64 stored = items[2].lower()
65 real = perform_md5(conf).lower()
67 md5_match_hash[conf] = conf
75 archive = os.path.join(options['archive-dir'], conf.lstrip('/'))
76 if options['use-rcs'] == 'yes':
77 portage.dispatch_conf.rcs_archive(archive, conf, md5_match_hash[conf], '')
78 if md5_match_hash[conf]:
79 portage.dispatch_conf.rcs_archive_post_process(archive)
81 portage.dispatch_conf.file_archive(archive, conf, md5_match_hash[conf], '')
82 if md5_match_hash[conf]:
83 portage.dispatch_conf.file_archive_post_process(archive)
89 print('Usage: archive-conf /CONFIG/FILE [/CONFIG/FILE...]', file=sys.stderr)