Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import argparse
  4. import glob
  5. import os
  6. import shutil
  7. import subprocess
  8.  
  9.  
  10. def main():
  11. # CLI
  12. descr = "Run latexdiff and generate a pdf"
  13. parser = argparse.ArgumentParser(description=descr,
  14. formatter_class=argparse.RawDescriptionHelpFormatter)
  15. r1 = 'Starting commit/revision/tag.'
  16. parser.add_argument('r1', help=r1)
  17. r2 = 'Ending commit/revision/tag. Defaults to HEAD.'
  18. parser.add_argument('--r2', help=r2, default='HEAD')
  19. args = parser.parse_args()
  20.  
  21. # args from CLI
  22. r1 = args.r1
  23. r2 = args.r2
  24.  
  25. # save files
  26. files = glob.glob('*.tex')
  27. for f in files:
  28. shutil.copyfile(f, '.' + f)
  29.  
  30. # generate diffs
  31. cmd = "latexdiff-vc -r {} -r {}"
  32. subprocess.check_call(cmd.format(r1, r2).split() + files)
  33.  
  34. # build pdf
  35. diff_file = lambda f, r1, r2: "{}-diff{}-{}.{}".format(
  36. f[:-4], r1, r2, f[-3:])
  37. for f in files:
  38. shutil.copyfile(diff_file(f, r1, r2), f)
  39. subprocess.check_call('make')
  40. shutil.copyfile('paper.pdf', diff_file('paper.pdf', r1, r2))
  41.  
  42. # clean up
  43. for f in files:
  44. shutil.copyfile('.' + f, f)
  45. rm = glob.glob(diff_file('*.tex', r1, r2)) + glob.glob('*oldtmp*.tex')
  46. for f in set(rm):
  47. os.remove(f)
  48.  
  49.  
  50. if __name__ == '__main__':
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement