def test_order_paths(self): self.assertEqual([], order_paths([], [])) self.assertEqual(['bar', 'baz'], order_paths(['bar', 'baz'], ['foo'])) self.assertEqual(['foo', 'bar'], order_paths(['bar', 'foo'], ['foo'])) self.assertEqual(['baz', 'foo', 'bar'], order_paths(['bar', 'foo', 'baz'], ['baz', 'foo'])) self.assertEqual(['foo' + os.sep + 'bim', 'bar'], order_paths(['bar', 'foo' + os.sep + 'bim'], ['foo']))
def main(): """ Order a list of paths according to a list of prefixes which define the order. """ parser = ArgumentParser( description= 'Utility to order a list of paths according to a list of prefixes. Creates a file with CMake set command setting a variable.' ) parser.add_argument('outfile', help='The filename of the generated CMake file') parser.add_argument('--paths-to-order', nargs='*', help='The semicolon-separated paths to order') parser.add_argument( '--prefixes', nargs='*', help='The semicolon-separated prefixes defining the order') args = parser.parse_args() ordered_paths = order_paths(args.paths_to_order, args.prefixes) # create directory if necessary outdir = os.path.dirname(args.outfile) if not os.path.exists(outdir): os.makedirs(outdir) with open(args.outfile, 'w') as fh: fh.write('set(ORDERED_PATHS "%s")' % ';'.join(ordered_paths))
def test_order_paths_with_symlink(self): root_dir = tempfile.mkdtemp() try: foo = os.path.join(root_dir, 'foo') foo_inc = os.path.join(foo, 'include') foo_ln = os.path.join(root_dir, 'foo_symlink') try: os.symlink(foo, foo_ln) except (AttributeError, OSError): self.skipTest('requires symlink availability') self.assertEqual([foo, 'bar'], order_paths(['bar', foo], [foo_ln])) self.assertEqual([foo_ln, 'bar'], order_paths(['bar', foo_ln], [foo])) self.assertEqual([foo_inc, 'bar'], order_paths(['bar', foo_inc], [foo_ln])) finally: shutil.rmtree(root_dir)
def main(): """ Order a list of paths according to a list of prefixes which define the order. """ parser = ArgumentParser( description="Utility to order a list of paths according to a list of prefixes. Creates a file with CMake set command setting a variable." ) parser.add_argument("outfile", help="The filename of the generated CMake file") parser.add_argument("--paths-to-order", nargs="*", help="The semicolon-separated paths to order") parser.add_argument("--prefixes", nargs="*", help="The semicolon-separated prefixes defining the order") args = parser.parse_args() ordered_paths = order_paths(args.paths_to_order, args.prefixes) # create directory if necessary outdir = os.path.dirname(args.outfile) if not os.path.exists(outdir): os.makedirs(outdir) with open(args.outfile, "w") as fh: fh.write('set(ORDERED_PATHS "%s")' % ";".join(ordered_paths))