Created
January 24, 2013 17:25
-
-
Save blaxter/4625404 to your computer and use it in GitHub Desktop.
Create symlinks for python modules installed in /usr/share/pyshared in /usr/lib/pymodules/python2.7/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def touch(fname, times=None): | |
with file(fname, 'a'): | |
os.utime(fname, times) | |
def create_pyshare_symlinks(package): | |
base_subdir = '/'.join(package.split('.')) | |
base_from = '/usr/share/pyshared/' + base_subdir | |
base_to = '/usr/lib/pymodules/python2.7/' + base_subdir | |
if not os.path.exists(base_to): | |
os.makedirs(base_to) | |
for dirname, dirnames, filenames in os.walk(base_from): | |
basedir_to = os.path.join(base_to, dirname[len(base_from)+1:]) | |
if not os.path.exists(basedir_to): | |
os.makedirs(basedir_to) | |
for filename in filenames: | |
file_from = os.path.join(dirname, filename) | |
file_to = os.path.join(basedir_to, filename) | |
try: | |
os.symlink(file_from, file_to) | |
except OSError: | |
print "Failed ln -s %s %s" % (file_from, file_to) | |
if '__init__.py' not in filenames: | |
touch(os.path.join(basedir_to, '__init__.py')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment