LAmerge.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. """Usage:
  3. LAmerge.py DB <args>
  4. Run LAcheck on each input in args. Exclude any failures from
  5. the arglist. Then run LAmerge on the remaining arglist.
  6. This differs from LAsort.py in that the first las file is actually
  7. an *explicit* output, whereas LAsort relies on *implicit* outputs.
  8. """
  9. import sys
  10. import os
  11. def log(msg):
  12. sys.stderr.write(msg + '\n')
  13. def system(call, checked=False):
  14. log('!{}'.format(call))
  15. rc = os.system(call)
  16. if rc:
  17. msg = '{} <- {!r}'.format(rc, call)
  18. if checked:
  19. raise Exception(msg)
  20. log(msg)
  21. return rc
  22. def main(argv=sys.argv):
  23. db = argv[1]
  24. args = argv[2:] # Skip program name
  25. lass = list()
  26. new_args = list()
  27. new_args.append('LAmerge')
  28. for arg in args:
  29. if arg.startswith('-'):
  30. new_args.append(arg)
  31. else:
  32. lass.append(arg)
  33. outlas = lass[0]
  34. new_args.append(outlas) # This is the output las.
  35. for las in lass[1:]:
  36. rc = system('LAcheck -vS {} {}.las'.format(db, las)) # Assume sorted.
  37. if rc:
  38. log('Skipping {}.las'.format(las))
  39. else:
  40. new_args.append(las)
  41. system(' '.join(new_args))
  42. system('LAcheck -vS {} {}.las'.format(db, outlas)) # Assume sorted.
  43. if __name__ == "__main__":
  44. main()