2
# Copyright (C) 2009 Canonical Ltd
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License version 3 as
6
# published by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
"""Remove expensive references.
18
This script takes 1 or two filenames and filters the first into either std out,
19
or the second filename.
27
from meliae import files, loader
32
p = optparse.OptionParser(
33
'%prog INFILE [OUTFILE]')
35
opts, args = p.parse_args(args)
37
sys.stderr.write('We only support 2 filenames, not %d\n' % (len(args),))
40
sys.stderr.write("Must supply INFILE\n")
44
infile, cleanup = files.open_file(args[0])
45
for obj in loader.iter_objs(infile):
51
outfile = open(args[1], 'wb')
52
for _, obj in loader.remove_expensive_references(source, show_progress=True):
53
outfile.write(obj.to_json() + '\n')
57
if __name__ == '__main__':
58
sys.exit(main(sys.argv[1:]))