1. Cat's Eye Technologies
  2. toolshelf


catseye  committed b96dd23

Beginnings of a link farm for shared objects. Scary stuff...

  • Participants
  • Parent commits 1aef4ba
  • Branches default

Comments (0)

Files changed (2)

File init.sh

View file
  • Ignore whitespace
   echo "error: TOOLSHELF does not refer to a valid directory"
   export PATH="$TOOLSHELF/.toolshelf/bin:$TOOLSHELF/.bin:$PATH"
   # `toolshelf` itself can't change the shell's idea of the current working
   # directory, but a shell function can utilize `toolshelf` to do so.  Since

File src/toolshelf.py

View file
  • Ignore whitespace
 TOOLSHELF = os.environ.get('TOOLSHELF')
-# TODO: there will eventually be multiple link farms (.lib, etc)
-LINK_FARM_DIR = os.path.join(TOOLSHELF, '.bin')
+BIN_LINK_FARM_DIR = os.path.join(TOOLSHELF, '.bin')
+LIB_LINK_FARM_DIR = os.path.join(TOOLSHELF, '.lib')
 # TODO: these should be regexes
     'build-cygwin.sh', 'make-cygwin.sh', 'install-cygwin.sh',
     'build.pl', 'make.pl', 'install.pl', 'test.pl',
     'configure', 'config.status', 'config.sub', 'config.guess',
-    'missing', 'mkinstalldirs', 'install-sh', 'autogen.sh',
+    'missing', 'mkinstalldirs', 'install-sh', 'autogen.sh', 'ltmain.sh',
+    '.gitignore', '__init__.py', 'setup.py',
+    'Makefile', 'make-bindist.sh', 'index.html',
+    'run', 'runme', 'buildme', 'compile',
     # these executables are not considered "interesting" because if you happen
     # to dock a source which builds an executable by one of these names and
     # toolshelf puts it on the path, you may just have a *wee* problem when
     basename = os.path.basename(filename)
         return False
+    if basename.endswith('.so'):
+        return False
     return os.path.isfile(filename) and os.access(filename, os.X_OK)
+def is_shared_object(filename):
+    match = re.match('^.*?\.so$', filename)
+    return os.path.isfile(filename) and match and os.access(filename, os.X_OK)
 def run(*args, **kwargs):
     note("Running `%s`..." % ' '.join(args))
     subprocess.check_call(args, **kwargs)
     def create_link(self, filename):
         filename = os.path.abspath(filename)
-        linkname = os.path.basename(filename)
-        linkname = os.path.join(self.dirname, linkname)
+        linkname = os.path.join(self.dirname, os.path.basename(filename))
         # We do trample existing links
         if os.path.islink(linkname):
+            note("Trampling existing link %s" % linkname)
         symlink(filename, linkname)
                     return False
         return True
-    def linkable_executables(self):
+    def linkable_files(self, predicate):
         for root, dirs, files in os.walk(self.dir):
             if '.git' in dirs:
             for name in files:
                 filename = os.path.join(self.dir, root, name)
-                if is_executable(filename):
+                if predicate(filename):
                     note("    %s" % filename)
                     yield filename
 class Toolshelf(object):
     def __init__(self, options=DefaultOptions(), cookies=None,
-                       link_farm=LinkFarm(LINK_FARM_DIR), errors=None):
+                       bin_link_farm=LinkFarm(BIN_LINK_FARM_DIR),
+                       lib_link_farm=LinkFarm(LIB_LINK_FARM_DIR),
+                       errors=None):
         self.options = options
         if cookies is None:
             cookies = Cookies()
                 TOOLSHELF, '.toolshelf', 'local-cookies.catalog'
         self.cookies = cookies
-        self.link_farm = link_farm
+        self.bin_link_farm = bin_link_farm
+        self.lib_link_farm = lib_link_farm
         if errors is None:
             errors = {}
         self.errors = errors
         sources = self.make_sources_from_specs(specs)
         note("Adding the following executables to your link farm...")
         for source in sources:
-            self.link_farm.clean(prefix=source.dir)
-            for filename in source.linkable_executables():
-                self.link_farm.create_link(filename)
+            self.bin_link_farm.clean(prefix=source.dir)
+            for filename in source.linkable_files(is_executable):
+                self.bin_link_farm.create_link(filename)
+            self.lib_link_farm.clean(prefix=source.dir)
+            for filename in source.linkable_files(is_shared_object):
+                self.lib_link_farm.create_link(filename)
     def disable(self, args):
         specs = expand_docked_specs(args, default_all=True)
         sources = self.make_sources_from_specs(specs)
         for source in sources:
-            self.link_farm.clean(prefix=source.dir)
+            self.bin_link_farm.clean(prefix=source.dir)
+            self.lib_link_farm.clean(prefix=source.dir)
     def show(self, args):
         specs = expand_docked_specs(args, default_all=True)