2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
7 # archive-conf -- save off a config file in the dispatch-conf archive dir
9 # Written by Wayne Davison <gentoo@blorf.net> with code snagged from
10 # Jeremy Wohl's dispatch-conf script and the portage chkcontents script.
17 from os import path as osp
18 sys.path.insert(0, osp.join(osp.dirname(osp.dirname(__file__)), "pym"))
23 FIND_EXTANT_CONTENTS = "find %s -name CONTENTS"
25 MANDATORY_OPTS = [ 'archive-dir' ]
29 def perform_checksum(filename): return fchksum.fmd5t(filename)
32 def md5_to_hex(md5sum):
34 for ix in xrange(len(md5sum)):
35 hexform = hexform + "%02x" % ord(md5sum[ix])
36 return hexform.lower()
38 def perform_checksum(filename):
39 f = open(filename, 'rb')
41 data = f.read(blocksize)
46 size = size + len(data)
47 data = f.read(blocksize)
48 return (md5_to_hex(sum.digest()),size)
55 options = portage.dispatch_conf.read_config(MANDATORY_OPTS)
57 for conf in sys.argv[1:]:
58 if not os.path.isabs(conf):
59 conf = os.path.abspath(conf)
61 md5_match_hash[conf] = ''
63 # Find all the CONTENT files in VDB_PATH.
64 content_files += os.popen(FIND_EXTANT_CONTENTS % (portage.root+portage.VDB_PATH)).readlines()
66 # Search for the saved md5 checksum of all the specified config files
67 # and see if the current file is unmodified or not.
70 for file in content_files:
73 contents = open(file, "r")
75 print >> sys.stderr, 'archive-conf: Unable to open %s: %s' % (file, e)
77 lines = contents.readlines()
83 stored = items[2].lower()
84 real = perform_checksum(conf)[0].lower()
86 md5_match_hash[conf] = conf
94 archive = os.path.join(options['archive-dir'], conf.lstrip('/'))
95 if options['use-rcs'] == 'yes':
96 portage.dispatch_conf.rcs_archive(archive, conf, md5_match_hash[conf], '')
97 if md5_match_hash[conf]:
98 portage.dispatch_conf.rcs_archive_post_process(archive)
100 portage.dispatch_conf.file_archive(archive, conf, md5_match_hash[conf], '')
101 if md5_match_hash[conf]:
102 portage.dispatch_conf.file_archive_post_process(archive)
105 if len(sys.argv) > 1:
108 print >> sys.stderr, 'Usage: archive-conf /CONFIG/FILE [/CONFIG/FILE...]'