def _add_bacon(self, package_dir, target_dir): """ Link packages from package_dir into target_dir. Recurse a level if target_dir/(package) already exists. """ if os.path.exists(package_dir): if islink(target_dir): self.logger.warn("Warning: (While processing package directory %s) Link already exists at %s. Skipping." % (package_dir, target_dir)) return elif not os.path.exists(target_dir): if not makedirs(target_dir): self.logger.warn("Warning: (While processing package directory %s) Link already exists at %s. Skipping." % (package_dir, target_dir)) return for package_name in [p for p in os.listdir(package_dir) if not p.startswith('.')]: package_location = os.path.join(package_dir, package_name) if not os.path.isdir(package_location): # skip ordinary files continue link_location = os.path.join(target_dir, package_name) if islink(link_location): self.logger.warn("Warning: (While processing package %s) Link already exists. Skipping." % package_location) elif os.path.isdir(link_location): self._add_bacon(package_location, link_location) else: symlink(package_location, link_location) else: self.logger.warn("Warning: Product directory %s not found. Skipping." % package_dir)
def makedirs(target, is_namespace=False): """ Similar to os.makedirs, but adds __init__.py files as it goes. Returns a boolean indicating success. """ drive, path = os.path.splitdrive(target) parts = path.split(os.path.sep) current = drive + os.path.sep for part in parts: current = os.path.join(current, part) if islink(current): return False if not os.path.exists(current): os.mkdir(current) init_filename = os.path.join(current, '__init__.py') if not os.path.exists(init_filename): init_file = open(init_filename, 'w') if is_namespace or part == 'Products': init_file.write(NAMESPACE_STANZA) else: init_file.write('# mushroom') init_file.close() return True