def main(args):
    import optparse
    p = optparse.OptionParser(
        '%prog INFILE [OUTFILE]')

    opts, args = p.parse_args(args)
    if len(args) > 2:
        sys.stderr.write('We only support 2 filenames, not %d\n' % (len(args),))
        return -1
    if len(args) < 1:
        sys.stderr.write("Must supply INFILE\n")
        return -1

    def source():
        infile, cleanup = files.open_file(args[0])
        for obj in loader.iter_objs(infile):
            yield obj
        cleanup()
    if len(args) == 1:
        outfile = sys.stdout
    else:
        outfile = open(args[1], 'wb')
    for _, obj in loader.remove_expensive_references(source, show_progress=True):
        outfile.write(obj.to_json() + '\n')   
    outfile.flush()
def main(args):
    import optparse
    p = optparse.OptionParser('%prog INFILE [OUTFILE]')

    opts, args = p.parse_args(args)
    if len(args) > 2:
        sys.stderr.write('We only support 2 filenames, not %d\n' %
                         (len(args), ))
        return -1
    if len(args) < 1:
        sys.stderr.write("Must supply INFILE\n")
        return -1

    def source():
        infile, cleanup = files.open_file(args[0])
        for obj in loader.iter_objs(infile):
            yield obj
        cleanup()

    if len(args) == 1:
        outfile = sys.stdout
    else:
        outfile = open(args[1], 'wb')
    for _, obj in loader.remove_expensive_references(source,
                                                     show_progress=True):
        outfile.write(obj.to_json() + '\n')
    outfile.flush()
示例#3
0
 def test_remove_expensive_references(self):
     lines = list(_example_dump)
     lines.pop(-1) # Remove the old module
     lines.append('{"address": 8, "type": "module", "size": 12'
                  ', "name": "mymod", "refs": [9]}')
     lines.append('{"address": 9, "type": "dict", "size": 124'
                  ', "refs": [10, 11]}')
     lines.append('{"address": 10, "type": "module", "size": 12'
                  ', "name": "mod2", "refs": [12]}')
     lines.append('{"address": 11, "type": "str", "size": 27'
                  ', "value": "boo", "refs": []}')
     lines.append('{"address": 12, "type": "dict", "size": 124'
                  ', "refs": []}')
     source = lambda:loader.iter_objs(lines)
     mymod_dict = list(source())[8]
     self.assertEqual([10, 11], mymod_dict.children)
     result = list(loader.remove_expensive_references(source))
     null_obj = result[0][1]
     self.assertEqual(0, null_obj.address)
     self.assertEqual('<ex-reference>', null_obj.type_str)
     self.assertEqual([11, 0], result[9][1].children)
示例#4
0
 def test_remove_expensive_references(self):
     lines = list(_example_dump)
     lines.pop(-1) # Remove the old module
     lines.append('{"address": 8, "type": "module", "size": 12'
                  ', "name": "mymod", "refs": [9]}')
     lines.append('{"address": 9, "type": "dict", "size": 124'
                  ', "refs": [10, 11]}')
     lines.append('{"address": 10, "type": "module", "size": 12'
                  ', "name": "mod2", "refs": [12]}')
     lines.append('{"address": 11, "type": "str", "size": 27'
                  ', "value": "boo", "refs": []}')
     lines.append('{"address": 12, "type": "dict", "size": 124'
                  ', "refs": []}')
     source = lambda:loader.iter_objs(lines)
     mymod_dict = list(source())[8]
     self.assertEqual([10, 11], mymod_dict.children)
     result = list(loader.remove_expensive_references(source))
     null_obj = result[0][1]
     self.assertEqual(0, null_obj.address)
     self.assertEqual('<ex-reference>', null_obj.type_str)
     self.assertEqual([11, 0], result[9][1].children)