Exemplo n.º 1
0
    def test_parsing(self):
        """Test parsing functionality"""
        nodetext = 'node_1 10\nnode_2 100'
        parsed = parse_string(nodetext)
        self.assertEqual(parsed[0], ('node_1', 10))
        self.assertEqual(parsed[1], ('node_2', 100))
        longtext = generate_text(100, 'nodes', upper=100, lower=10)
        parsed = parse_string(longtext)
        nnames, sizes = list(zip(*parsed))
        sizes = np.array(sizes)
        # Check text generator
        self.assertTrue((sizes >= 10).all())
        self.assertTrue((sizes <= 100).all())
        self.assertTrue(all([name.startswith('nodes') for name in nnames]))

        # Check invocation from strings
        dist = Distribution.from_strings(longtext, longtext)

        with tempfile.ScratchDir('.'):
            with open('files.txt', 'w') as f:
                f.write(longtext)
            with open('nodes.txt', 'w') as f:
                f.write(longtext)
            dist = Distribution.from_filenames('nodes.txt', 'files.txt')
Exemplo n.º 2
0
# Argument parsing
desc = """
Program that takes two filename inputs corresponding to lists
of files and nodes and distributes the files onto the nodes
such that the absolute loads are evenly distributed
"""

arg_parser = argparse.ArgumentParser(description=desc)
arg_parser.add_argument('-f', '--files', help='File containing file list',
                        required=True)
arg_parser.add_argument('-n', '--nodes', help='File containing node list',
                        required=True)
arg_parser.add_argument('-o', '--output',
                        help='output file, optional, default is stdout')
arg_parser.add_argument('-p', '--plot', action='store_true',
                        help='plotting flag, plots nodes/files on bar chart')
arg_parser.add_argument('-pl', '--plotly', action='store_true',
                        help='plotting flag, plots nodes/files on bar chart'
                             'in plotly')
args = arg_parser.parse_args()

# Main body
if __name__ == "__main__":
    dist = Distribution.from_filenames(args.nodes, args.files)
    dist.summary(args.output)

    if args.plot:
        ply = dist.plot()
    if args.plotly:
        plt = dist.get_plotly()