]> git.ipfire.org Git - pakfire.git/commitdiff
Add "clean all" command to pakfire and pakfire-builder.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2011 12:52:20 +0000 (14:52 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2011 12:52:20 +0000 (14:52 +0200)
12 files changed:
pakfire/api.py
pakfire/base.py
pakfire/cli.py
pakfire/repository/__init__.py
pakfire/repository/base.py
pakfire/repository/cache.py
pakfire/repository/index.py
po/pakfire.pot
src/_pakfiremodule.c
src/repo.c
src/repo.h
src/solvable.c

index 16c6bb51b7f057e5290438b51b5bf607a1845bf5..d61b35debd1cc11a9f34f8d70634ccf039a36f95 100644 (file)
@@ -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()
index 68d833f765bf3d0a3d8970875ad52963c6b55628..281ff2f823e9d145db412fbeff722665871600da 100644 (file)
@@ -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()
index 0d011d51594c144d783af7a4f63fa387c74e4594..49c60701a1dce9a49936b33e972ff5802c7452e1 100644 (file)
@@ -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
index 9c0960b3a44a0f0da6d9a1b8e96c588a2b70cba1..3246e478b1cb65e6a828be1afad58c881b6bf461 100644 (file)
@@ -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()
index 2b60829eb27a0b2647134b995e541627254c5fc8..6b0b7aa04b0641a4cfe2f0c672b25e99c0ef9236 100644 (file)
@@ -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):
        """
index f6b044cab21416b0f542b37a1dfdb141e42b771d..948eb383152c66f9d59926212f814c89e6bf8f1a 100644 (file)
@@ -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)
index 5a7494b8379e7dc9ed862a90ec628d6a5df693c4..3fc2cb2ab0436313f4d7190a5a7013efe5714107 100644 (file)
@@ -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):
index ce52ad698368951664d8fda2d565018d609cfe95..d91bbcd5f6c740f85caccadd68ecb271b0109970 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""
 
index e616ea069cb8f939949f09f4c31e3307adf47da7..0c3b1fe025a7819d8390cc969b3d3f7fcb5f457c 100644 (file)
@@ -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 }
 };
 
index cab9a0070522ec78fdccf807590efa654f0c8eec..f08b67d1083ab7a6cccd0c7dc7b07b804f594bea 100644 (file)
@@ -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;
+}
index 8c76341ce37de1578de90b617f7ed0a13f9971cb..c790ed5c97c8f5d99b802ba43acd6f3603f0a75c 100644 (file)
@@ -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;
 
index feb1a0095900b36257383a819c1dd360393db9ef..493148a3586a12faec350dd47b214eca4a641648 100644 (file)
@@ -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);