def link(self, selected=None): undo_log = [] for bundle in self._selected_bundles(selected): try: self._link_bundle(bundle, undo_log) except utils.NotASymlink as e: utils.undo_operations(undo_log) raise NotASymlink(str(e)) except: utils.undo_operations(undo_log) raise else: if self._is_custom_bundle(bundle): self.custom_bundle_state.append(bundle)
def unlink(self, clear_custom_bundle_state=True): undo_log = [] matching, non_matching = self.bundle_breakdown() for bundle in sorted(matching | non_matching): try: self._unlink_bundle(bundle, undo_log) except utils.NotASymlink as e: utils.undo_operations(undo_log) raise NotASymlink(str(e)) except: utils.undo_operations(undo_log) raise if clear_custom_bundle_state: self.custom_bundle_state.clear()
def untrack(self, path): dst_path = utils.truepath(path) if not os.path.exists(dst_path): raise Exception("Path '%s' not found" % dst_path) if not os.path.islink(dst_path): raise Exception("Path '%s' is not a symlink" % dst_path) src_path = os.path.realpath(dst_path) undo_log = [] utils.remove_symlink(dst_path, dry_run=self.dry_run, undo_log=undo_log) try: utils.rename(src_path, dst_path, dry_run=self.dry_run) except: utils.undo_operations(undo_log) raise self.git.rm(src_path) self.git.commit(message="Untracking '%s'" % path)
def track(self, path, bundle=None): """Track a file or a directory.""" # We don't use kwarg default, because None represents default to # callers bundle = bundle or 'Default' src_path = utils.truepath(path) is_directory = os.path.isdir(src_path) if self.root_path not in src_path: raise Exception('Cannot track files outside of root path') bundle_path = os.path.join(self.repo_path, bundle) dst_path = os.path.join( bundle_path, utils.relpath(self.root_path, src_path)) undo_log = [] dst_dir = os.path.dirname(dst_path) if not os.path.exists(dst_dir): utils.makedirs(dst_dir, dry_run=self.dry_run, undo_log=undo_log) try: utils.rename(src_path, dst_path, dry_run=self.dry_run, undo_log=undo_log) try: utils.symlink(dst_path, src_path, dry_run=self.dry_run) except: utils.undo_operations(undo_log) raise except: utils.undo_operations(undo_log) raise self.git.add(dst_path) if is_directory: marker = self._track_directory(dst_path) self.git.add(marker) self.git.commit(message="Tracking '%s'" % path)