symlink.py 758 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import sys
  4. import os
  5. import platform
  6. from subprocess import call
  7. def symlink():
  8. if len(sys.argv) < 3:
  9. print("Usage: symlink.py <source> <target>", file=sys.stderr)
  10. sys.exit(1)
  11. source = sys.argv[1]
  12. target = sys.argv[2]
  13. print("Making a symbolic link from {0} to {1}".format(source, target))
  14. sysName = platform.system()
  15. if sysName == "Windows": # and not os.path.exists(target)
  16. if os.path.isdir(source):
  17. call(["mklink", "/D", target, source], shell=True)
  18. else:
  19. call(["mklink", target, source], shell=True)
  20. else:
  21. call(["ln", "-f", "-s", "-n", source, target])
  22. if __name__ == '__main__':
  23. symlink()