symlink.py 714 B

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