Skip to content

Instantly share code, notes, and snippets.

@Jeswang
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeswang/75a1fd827dd2ea983875 to your computer and use it in GitHub Desktop.
Save Jeswang/75a1fd827dd2ea983875 to your computer and use it in GitHub Desktop.
Fix soft links for the zip file downloaded from https://github.com/phracker/MacOSX-SDKs
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Jeswang<wangyi724@gmail.com>
# http://blog.jeswang.org
# Created on 2014-10-22 13:03:12
import os
def file_exists(filename):
try:
with open(filename) as f:
return True
except IOError:
return False
def folder_exists(foldername):
try:
os.walk(foldername).next()
return True
except StopIteration:
return False
def generateSoftLink(realfile, linkfile):
print("%s -> %s" % (linkfile, realfile))
os.symlink(realfile, linkfile)
def generateSoftLinkForPath(path):
list_of_files = {}
for (dirpath, dirnames, filenames) in os.walk(path):
for filename in filenames:
print filename
linkfile = dirpath+"/"+filename
if os.path.islink(linkfile) or os.path.getsize(linkfile) > 200:
continue
f = open(linkfile)
relpath = f.readline()
f.close()
if len(relpath) == 0:
continue
relpath = relpath.replace("\n", "")
if len(relpath.replace("/", "")) == 0:
continue
realfile = dirpath+"/"+relpath
if file_exists(realfile) or folder_exists(realfile):
os.remove(linkfile)
generateSoftLink(relpath, linkfile)
if __name__ == "__main__":
generateSoftLinkForPath("/Users/jeswang/Downloads/MacOSX-SDKs-master")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment