def uninstall(self,recipe): """Uninstall the named recipe from this myppy env.""" # TODO: remove things depending on it with self: q = "DELETE FROM installed_recipes WHERE recipe=?" self._db.execute(q,(recipe,)) q = "SELECT filepath FROM installed_files WHERE recipe=?"\ " ORDER BY filepath DESC" files = [r[0] for r in self._db.execute(q,(recipe,))] q = "DELETE FROM installed_files WHERE recipe=?" self._db.execute(q,(recipe,)) for file in files: assert util.relpath(file) == file if self._old_files_cache is not None: self._old_files_cache.remove(file) for file in files: filepath = os.path.join(self.rootdir,file) if not os.path.exists(filepath): continue if filepath.endswith(os.sep): print "PRUNING", filepath util.prune_dir(filepath) else: print "REMOVING", filepath os.unlink(filepath) dirpath = os.path.dirname(filepath) + os.sep if not os.listdir(dirpath): q = "SELECT * FROM installed_files WHERE filepath=?" if not self._is_oldfile(dirpath): print "PRUNING", filepath util.prune_dir(dirpath)
def record_files(self,recipe,files): """Record the given list of files as installed for the given recipe.""" files = list(files) assert files, "recipe '%s' didn't install any files" % (recipe,) for file in files: file = file[len(self.rootdir)+1:] assert util.relpath(file) == file self._db.execute("INSERT INTO installed_files VALUES (?,?)", (recipe,file,)) if self._old_files_cache is not None: self._old_files_cache.add(file)
def _is_oldfile(self,file): if self._old_files_cache is None: self._old_files_cache = set() for r in self._db.execute("SELECT filepath FROM installed_files"): self._old_files_cache.add(r[0]) file = file[len(self.rootdir)+1:] assert util.relpath(file) == file if file in self._old_files_cache: return True q = "SELECT * FROM installed_files WHERE filepath=?" if self._db.execute(q,(file,)).fetchone(): return True return False