From 31267a64f492b460340cb936372b554e806675da Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 21 Jul 2011 14:52:20 +0200 Subject: [PATCH] Add "clean all" command to pakfire and pakfire-builder. --- pakfire/api.py | 5 ++ pakfire/base.py | 6 ++ pakfire/cli.py | 21 ++++++ pakfire/repository/__init__.py | 6 ++ pakfire/repository/base.py | 10 +++ pakfire/repository/cache.py | 6 ++ pakfire/repository/index.py | 6 ++ po/pakfire.pot | 116 ++++++++++++++++++--------------- src/_pakfiremodule.c | 1 + src/repo.c | 6 ++ src/repo.h | 1 + src/solvable.c | 4 +- 12 files changed, 133 insertions(+), 55 deletions(-) diff --git a/pakfire/api.py b/pakfire/api.py index 16c6bb51..d61b35de 100644 --- a/pakfire/api.py +++ b/pakfire/api.py @@ -78,3 +78,8 @@ def repo_list(**pakfire_args): pakfire = Pakfire(**pakfire_args) return pakfire.repo_list() + +def clean_all(**pakfire_args): + pakfire = Pakfire(**pakfire_args) + + return pakfire.clean_all() diff --git a/pakfire/base.py b/pakfire/base.py index 68d833f7..281ff2f8 100644 --- a/pakfire/base.py +++ b/pakfire/base.py @@ -391,3 +391,9 @@ class Pakfire(object): def repo_list(self): return [r for r in self.repos] + + def clean_all(self): + logging.debug("Cleaning up everything...") + + # Clean up repository caches. + self.repos.clean() diff --git a/pakfire/cli.py b/pakfire/cli.py index 0d011d51..49c60701 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -37,6 +37,7 @@ class Cli(object): self.parse_command_grouplist() self.parse_command_groupinstall() self.parse_command_repolist() + self.parse_command_clean() # Finally parse all arguments from the command line and save them. self.args = self.parser.parse_args() @@ -52,6 +53,7 @@ class Cli(object): "grouplist" : self.handle_grouplist, "groupinstall" : self.handle_groupinstall, "repolist" : self.handle_repolist, + "clean_all" : self.handle_clean_all, } @property @@ -160,6 +162,18 @@ class Cli(object): help=_("List all currently enabled repositories.")) sub_repolist.add_argument("action", action="store_const", const="repolist") + def parse_command_clean(self): + sub_clean = self.sub_commands.add_parser("clean", help=_("Cleanup commands.")) + + sub_clean_commands = sub_clean.add_subparsers() + + self.parse_command_clean_all(sub_clean_commands) + + def parse_command_clean_all(self, sub_commands): + sub_create = sub_commands.add_parser("all", + help=_("Cleanup all temporary files.")) + sub_create.add_argument("action", action="store_const", const="clean_all") + def run(self): action = self.args.action @@ -228,6 +242,11 @@ class Cli(object): print FORMAT % (repo.name, repo.enabled, repo.priority, len(repo)) + def handle_clean_all(self): + print _("Cleaning up everything...") + + pakfire.clean_all(**self.pakfire_args) + class CliBuilder(Cli): def __init__(self): @@ -249,6 +268,7 @@ class CliBuilder(Cli): self.parse_command_provides() self.parse_command_grouplist() self.parse_command_repolist() + self.parse_command_clean() # Finally parse all arguments from the command line and save them. self.args = self.parser.parse_args() @@ -263,6 +283,7 @@ class CliBuilder(Cli): "provides" : self.handle_provides, "grouplist" : self.handle_grouplist, "repolist" : self.handle_repolist, + "clean_all" : self.handle_clean_all, } @property diff --git a/pakfire/repository/__init__.py b/pakfire/repository/__init__.py index 9c0960b3..3246e478 100644 --- a/pakfire/repository/__init__.py +++ b/pakfire/repository/__init__.py @@ -122,3 +122,9 @@ class Repositories(object): def whatprovides(self, what): for solv in self.pool.providers(what): yield packages.SolvPackage(self.pakfire, solv) + + def clean(self): + logging.info("Cleaning up all repository caches...") + + for repo in self: + repo.clean() diff --git a/pakfire/repository/base.py b/pakfire/repository/base.py index 2b60829e..6b0b7aa0 100644 --- a/pakfire/repository/base.py +++ b/pakfire/repository/base.py @@ -86,6 +86,16 @@ class RepositoryFactory(object): self.index.update(force) + def clean(self): + """ + Cleanup all temporary files of this repository. + """ + logging.info("Cleaning up repository '%s'..." % self.name) + self.cache.destroy() + + assert self.index + self.index.clear() + class RepositoryDummy(RepositoryFactory): """ diff --git a/pakfire/repository/cache.py b/pakfire/repository/cache.py index f6b044ca..948eb383 100644 --- a/pakfire/repository/cache.py +++ b/pakfire/repository/cache.py @@ -98,3 +98,9 @@ class RepositoryCache(object): filename = self.abspath(filename) os.unlink(filename) + def destroy(self): + """ + Remove all files from this cache. + """ + if self.created: + util.rm(self.path) diff --git a/pakfire/repository/index.py b/pakfire/repository/index.py index 5a7494b8..3fc2cb2a 100644 --- a/pakfire/repository/index.py +++ b/pakfire/repository/index.py @@ -150,6 +150,12 @@ class Index(object): rel = self.create_relation(file) solvable.add_provides(rel) + def clear(self): + """ + Forget all packages from memory. + """ + self.solver_repo.clear() + class IndexSolv(Index): def check(self): diff --git a/po/pakfire.pot b/po/pakfire.pot index ce52ad69..d91bbcd5 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-21 14:14+0200\n" +"POT-Creation-Date: 2011-07-21 14:50+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -30,195 +30,207 @@ msgstr "" msgid "The path where pakfire should operate in." msgstr "" -#: ../pakfire/cli.py:74 +#: ../pakfire/cli.py:76 msgid "Enable verbose output." msgstr "" -#: ../pakfire/cli.py:77 +#: ../pakfire/cli.py:79 msgid "Path to a configuration file to load." msgstr "" -#: ../pakfire/cli.py:80 +#: ../pakfire/cli.py:82 msgid "Disable a repository temporarily." msgstr "" -#: ../pakfire/cli.py:83 +#: ../pakfire/cli.py:85 msgid "Enable a repository temporarily." msgstr "" -#: ../pakfire/cli.py:88 +#: ../pakfire/cli.py:90 msgid "Install one or more packages to the system." msgstr "" -#: ../pakfire/cli.py:90 +#: ../pakfire/cli.py:92 msgid "Give name of at least one package to install." msgstr "" -#: ../pakfire/cli.py:96 +#: ../pakfire/cli.py:98 msgid "Install one or more packages from the filesystem." msgstr "" -#: ../pakfire/cli.py:98 +#: ../pakfire/cli.py:100 msgid "Give filename of at least one package." msgstr "" -#: ../pakfire/cli.py:104 +#: ../pakfire/cli.py:106 msgid "Remove one or more packages from the system." msgstr "" -#: ../pakfire/cli.py:106 +#: ../pakfire/cli.py:108 msgid "Give name of at least one package to remove." msgstr "" -#: ../pakfire/cli.py:112 +#: ../pakfire/cli.py:114 msgid "Update the whole system or one specific package." msgstr "" -#: ../pakfire/cli.py:114 +#: ../pakfire/cli.py:116 msgid "Give a name of a package to update or leave emtpy for all." msgstr "" -#: ../pakfire/cli.py:120 +#: ../pakfire/cli.py:122 msgid "Print some information about the given package(s)." msgstr "" -#: ../pakfire/cli.py:122 +#: ../pakfire/cli.py:124 msgid "Give at least the name of one package." msgstr "" -#: ../pakfire/cli.py:128 +#: ../pakfire/cli.py:130 msgid "Search for a given pattern." msgstr "" -#: ../pakfire/cli.py:130 +#: ../pakfire/cli.py:132 msgid "A pattern to search for." msgstr "" -#: ../pakfire/cli.py:136 +#: ../pakfire/cli.py:138 msgid "Get a list of packages that provide a given file or feature." msgstr "" -#: ../pakfire/cli.py:138 +#: ../pakfire/cli.py:140 msgid "File or feature to search for." msgstr "" -#: ../pakfire/cli.py:144 +#: ../pakfire/cli.py:146 msgid "Get list of packages that belong to the given group." msgstr "" -#: ../pakfire/cli.py:146 +#: ../pakfire/cli.py:148 msgid "Group name to search for." msgstr "" -#: ../pakfire/cli.py:152 +#: ../pakfire/cli.py:154 msgid "Install all packages that belong to the given group." msgstr "" -#: ../pakfire/cli.py:154 +#: ../pakfire/cli.py:156 msgid "Group name." msgstr "" -#: ../pakfire/cli.py:160 +#: ../pakfire/cli.py:162 msgid "List all currently enabled repositories." msgstr "" -#: ../pakfire/cli.py:220 ../pakfire/transaction.py:248 +#: ../pakfire/cli.py:166 +msgid "Cleanup commands." +msgstr "" + +#: ../pakfire/cli.py:174 +msgid "Cleanup all temporary files." +msgstr "" + +#: ../pakfire/cli.py:234 ../pakfire/transaction.py:248 msgid "Repository" msgstr "" -#: ../pakfire/cli.py:220 +#: ../pakfire/cli.py:234 msgid "Enabled" msgstr "" -#: ../pakfire/cli.py:220 +#: ../pakfire/cli.py:234 msgid "Priority" msgstr "" -#: ../pakfire/cli.py:220 +#: ../pakfire/cli.py:234 msgid "Packages" msgstr "" -#: ../pakfire/cli.py:235 +#: ../pakfire/cli.py:246 +msgid "Cleaning up everything..." +msgstr "" + +#: ../pakfire/cli.py:254 msgid "Pakfire builder command line interface." msgstr "" -#: ../pakfire/cli.py:283 +#: ../pakfire/cli.py:304 msgid "Update the package indexes." msgstr "" -#: ../pakfire/cli.py:289 +#: ../pakfire/cli.py:310 msgid "Build one or more packages." msgstr "" -#: ../pakfire/cli.py:291 +#: ../pakfire/cli.py:312 msgid "Give name of at least one package to build." msgstr "" -#: ../pakfire/cli.py:295 +#: ../pakfire/cli.py:316 msgid "Build the package for the given architecture." msgstr "" -#: ../pakfire/cli.py:297 ../pakfire/cli.py:319 +#: ../pakfire/cli.py:318 ../pakfire/cli.py:340 msgid "Path were the output files should be copied to." msgstr "" -#: ../pakfire/cli.py:302 +#: ../pakfire/cli.py:323 msgid "Go into a shell." msgstr "" -#: ../pakfire/cli.py:304 +#: ../pakfire/cli.py:325 msgid "Give name of a package." msgstr "" -#: ../pakfire/cli.py:308 +#: ../pakfire/cli.py:329 msgid "Emulated architecture in the shell." msgstr "" -#: ../pakfire/cli.py:313 +#: ../pakfire/cli.py:334 msgid "Generate a source package." msgstr "" -#: ../pakfire/cli.py:315 +#: ../pakfire/cli.py:336 msgid "Give name(s) of a package(s)." msgstr "" -#: ../pakfire/cli.py:390 +#: ../pakfire/cli.py:411 msgid "Pakfire repo command line interface." msgstr "" -#: ../pakfire/cli.py:415 +#: ../pakfire/cli.py:436 msgid "Repository management commands." msgstr "" -#: ../pakfire/cli.py:423 +#: ../pakfire/cli.py:444 msgid "Create a new repository index." msgstr "" -#: ../pakfire/cli.py:424 +#: ../pakfire/cli.py:445 msgid "Path to the packages." msgstr "" -#: ../pakfire/cli.py:425 +#: ../pakfire/cli.py:446 msgid "Path to input packages." msgstr "" -#: ../pakfire/cli.py:437 +#: ../pakfire/cli.py:458 msgid "Pakfire master command line interface." msgstr "" -#: ../pakfire/cli.py:465 +#: ../pakfire/cli.py:486 msgid "Update the sources." msgstr "" -#: ../pakfire/cli.py:475 +#: ../pakfire/cli.py:496 msgid "Pakfire server command line interface." msgstr "" -#: ../pakfire/cli.py:505 +#: ../pakfire/cli.py:526 msgid "Request a build job from the server." msgstr "" -#: ../pakfire/cli.py:511 +#: ../pakfire/cli.py:532 msgid "Send a keepalive to the server." msgstr "" @@ -290,19 +302,19 @@ msgstr "" msgid "Requires" msgstr "" -#: ../pakfire/repository/index.py:215 +#: ../pakfire/repository/index.py:221 #, python-format msgid "%s: package database" msgstr "" #. Create progress bar. -#: ../pakfire/repository/index.py:289 +#: ../pakfire/repository/index.py:295 #, python-format msgid "Loading from %s" msgstr "" #. Add all packages from the database to the index. -#: ../pakfire/repository/index.py:339 +#: ../pakfire/repository/index.py:345 msgid "Loading installed packages" msgstr "" diff --git a/src/_pakfiremodule.c b/src/_pakfiremodule.c index e616ea06..0c3b1fe0 100644 --- a/src/_pakfiremodule.c +++ b/src/_pakfiremodule.c @@ -57,6 +57,7 @@ static PyMethodDef Repo_methods[] = { {"set_priority", (PyCFunction)Repo_set_priority, METH_VARARGS, NULL}, {"write", (PyCFunction)Repo_write, METH_VARARGS, NULL}, {"read", (PyCFunction)Repo_read, METH_VARARGS, NULL}, + {"clear", (PyCFunction)Repo_clear, METH_NOARGS, NULL}, { NULL, NULL, 0, NULL } }; diff --git a/src/repo.c b/src/repo.c index cab9a007..f08b67d1 100644 --- a/src/repo.c +++ b/src/repo.c @@ -139,3 +139,9 @@ PyObject *Repo_read(RepoObject *self, PyObject *args) { Py_RETURN_NONE; } + +PyObject *Repo_clear(RepoObject *self) { + repo_empty(self->_repo, 1); + + Py_RETURN_NONE; +} diff --git a/src/repo.h b/src/repo.h index 8c76341c..c790ed5c 100644 --- a/src/repo.h +++ b/src/repo.h @@ -22,6 +22,7 @@ extern PyObject *Repo_get_priority(RepoObject *self); extern PyObject *Repo_set_priority(RepoObject *self, PyObject *args); extern PyObject *Repo_write(RepoObject *self, PyObject *args); extern PyObject *Repo_read(RepoObject *self, PyObject *args); +extern PyObject *Repo_clear(RepoObject *self); extern PyTypeObject RepoType; diff --git a/src/solvable.c b/src/solvable.c index feb1a009..493148a3 100644 --- a/src/solvable.c +++ b/src/solvable.c @@ -123,10 +123,8 @@ PyObject *_Solvable_get_dependencies(Solvable *solv, Offset deps) { Repo *repo = solv->repo; Pool *pool = repo->pool; - PyObject *dep; - const char *dep_str; - Id id, *ids; + const char *dep_str; PyObject *list = PyList_New(0); -- 2.39.2