Merge lp:~cire831/computer-janitor/bug-726616 into lp:computer-janitor
- bug-726616
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Barry Warsaw |
Proposed branch: | lp:~cire831/computer-janitor/bug-726616 |
Merge into: | lp:computer-janitor |
Diff against target: |
10575 lines (+10103/-0) (has conflicts) 83 files modified
COPYING (+676/-0) CoverageTestRunner.py (+203/-0) Makefile (+52/-0) NEWS (+262/-0) README (+31/-0) TODO (+30/-0) computer-janitor (+41/-0) computer-janitor-gtk (+68/-0) computer-janitor-gtk.8 (+36/-0) computer-janitor.8 (+222/-0) computerjanitorapp/__init__.py (+44/-0) computerjanitorapp/cli/main.py (+312/-0) computerjanitorapp/gtk/dialogs.py (+125/-0) computerjanitorapp/gtk/main.py (+32/-0) computerjanitorapp/gtk/store.py (+162/-0) computerjanitorapp/gtk/ui.py (+594/-0) computerjanitorapp/terminalsize.py (+63/-0) computerjanitorapp/tests/test_all.py (+29/-0) computerjanitorapp/tests/test_terminalsize.py (+54/-0) computerjanitorapp/tests/test_utilities.py (+70/-0) computerjanitorapp/utilities.py (+51/-0) computerjanitord/application.py (+90/-0) computerjanitord/authenticator.py (+85/-0) computerjanitord/collector.py (+168/-0) computerjanitord/data/com.ubuntu.ComputerJanitor.conf (+15/-0) computerjanitord/data/com.ubuntu.ComputerJanitor.service (+4/-0) computerjanitord/data/com.ubuntu.computerjanitor.policy (+19/-0) computerjanitord/errors.py (+95/-0) computerjanitord/main.py (+120/-0) computerjanitord/service.py (+288/-0) computerjanitord/state.py (+92/-0) computerjanitord/tests/data/etc/apt/sources.list (+1/-0) computerjanitord/tests/data/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_intrepid_restricted_binary-i386_Packages (+54/-0) computerjanitord/tests/data/var/lib/dpkg/status (+28/-0) computerjanitord/tests/test_all.py (+41/-0) computerjanitord/tests/test_application.py (+105/-0) computerjanitord/tests/test_authenticator.py (+97/-0) computerjanitord/tests/test_collector.py (+225/-0) computerjanitord/tests/test_state.py (+141/-0) computerjanitord/tests/test_whitelist.py (+119/-0) computerjanitord/whitelist.py (+86/-0) data/ComputerJanitor.ui (+552/-0) data/computer-janitor-gtk.desktop.in (+11/-0) debian/changelog (+561/-0) debian/compat (+1/-0) debian/computer-janitor-gtk.install (+6/-0) debian/computer-janitor-gtk.lintian-overrides (+2/-0) debian/computer-janitor.docs (+1/-0) debian/computer-janitor.install (+8/-0) debian/computer-janitor.postinst (+28/-0) debian/computer-janitor.postrm (+18/-0) debian/control (+56/-0) debian/copyright (+35/-0) debian/default.whitelist (+4/-0) debian/pycompat (+1/-0) debian/rules (+41/-0) debian/watch (+3/-0) janitord (+27/-0) license-check (+72/-0) license-exceptions (+24/-0) plugins/add_nfs_common_plugin.py (+58/-0) plugins/autoremoval_plugin.py (+40/-0) plugins/autoremoval_plugin_tests.py (+54/-0) plugins/check_admin_group_plugin.py (+85/-0) plugins/dpkg_dotfile_plugin.py (+87/-0) plugins/dpkg_dotfile_plugin_tests.py (+107/-0) plugins/fstab_plugin.py (+124/-0) plugins/fstab_plugin_tests.py (+123/-0) plugins/landscape_stub_plugin.py (+59/-0) plugins/landscape_stub_plugin_tests.py (+87/-0) plugins/unsupported_plugin.py (+131/-0) plugins/unsupported_plugin_tests.py (+103/-0) po/POTFILES.in (+29/-0) po/computerjanitor.pot (+289/-0) po/es.po (+427/-0) po/fi.po (+427/-0) po/fr.po (+426/-0) po/ja.po (+422/-0) po/pl.po (+401/-0) run_from_checkout.sh (+10/-0) setup.cfg (+5/-0) setup.py (+97/-0) test-env (+31/-0) Conflict adding file COPYING. Moved existing file to COPYING.moved. Conflict adding file CoverageTestRunner.py. Moved existing file to CoverageTestRunner.py.moved. Conflict adding file Makefile. Moved existing file to Makefile.moved. Conflict adding file NEWS. Moved existing file to NEWS.moved. Conflict adding file README. Moved existing file to README.moved. Conflict adding file TODO. Moved existing file to TODO.moved. Conflict adding file computer-janitor-gtk.8. Moved existing file to computer-janitor-gtk.8.moved. Conflict adding file computer-janitor-gtk. Moved existing file to computer-janitor-gtk.moved. Conflict adding file computer-janitor.8. Moved existing file to computer-janitor.8.moved. Conflict adding file computer-janitor. Moved existing file to computer-janitor.moved. Conflict adding file computerjanitorapp. Moved existing file to computerjanitorapp.moved. Conflict adding file computerjanitord. Moved existing file to computerjanitord.moved. Conflict adding file data. Moved existing file to data.moved. Conflict adding file debian. Moved existing file to debian.moved. Conflict adding file janitord. Moved existing file to janitord.moved. Conflict adding file license-check. Moved existing file to license-check.moved. Conflict adding file license-exceptions. Moved existing file to license-exceptions.moved. Conflict adding file plugins. Moved existing file to plugins.moved. Conflict adding file po. Moved existing file to po.moved. Conflict adding file run_from_checkout.sh. Moved existing file to run_from_checkout.sh.moved. Conflict adding file setup.cfg. Moved existing file to setup.cfg.moved. Conflict adding file setup.py. Moved existing file to setup.py.moved. Conflict adding file test-env. Moved existing file to test-env.moved. |
To merge this branch: | bzr merge lp:~cire831/computer-janitor/bug-726616 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Barry Warsaw | Disapprove | ||
Review via email: mp+51610@code.launchpad.net |
Commit message
Description of the change
Unmerged revisions
- 26. By Eric B. Decker
-
NEWS: fixed a typo. (LP: #726616)
- 25. By Barry Warsaw
-
[ Loïc Minier ]
* debian/control: computer-janitor- gtk depends gir1.2-pango-1.0 not
gir1.2-pango-2.0. (LP: #720529)[ Barry Warsaw ]
* setup.py, computer-janitor- gtk.install: Install 24x24.png into
/usr/share/computer- janitor which is where gtk expects it to be.
(LP: #720743)
* Fix various apt_cache deprecation warnings.
* debian/rules:
- Switch to dh_python2.
- Run the unit tests at build time.
- Add --keep to dh_installchangelogs.
- Remove override_dh_pysupport.
* debian/control:
- Add Build-Depends on python-dbus and update-manager-core so that the
unit tests can be run at build time. Remove B-D on python-support.
Change B-D to python-all for tests under all available Python versions.
- Fix typo in descriptions.
- Remove XB-Python-Version and add X-Python-Version for dh_python2.
* Note: 2.1.0-0ubuntu2 was a quick fix upload to the archive containing
the above debian/control file fix. - 24. By Loïc Minier
-
* control: computer-
janitor- gtk depends gir1.2-pango-1.0 not
gir1.2-pango-2.0; LP: #720529.
* Temporarily comment out Vcs-Bzr as I can't commit to it. - 23. By Barry Warsaw
-
[ Martin Pitt ]
* data/ComputerJanitor.ui: Drop obsolete has_separator properties.
* run_from_checkout. sh: Drop setting of $PYTHONPATH. Current directory is
there by default anyway, and this breaks setting it from the environment.
* computerjanitorapp/gtk/ *: Port from pygtk2 to pygi. Works fully with GTK3
now, with GTK2 we need to disable the right-click popup menu
(popup_for_device( ) is introspection safe, but only exists in GTK3.
popup() isn't introspectable).
* computerjanitorapp/gtk/ ui.py: Force GTK2 for now, as we do not yet have a
GTK3 theme in Natty, and don't carry the GTK3 stack in the default
install.
* debian/control: Update dependencies for the pygtk → pygi switch.
* debian/control: Drop obsolete system-cleaner conflicts and gksu
dependency.[ Barry Warsaw ]
* Add Edit menu items for selecting and deselecting cruft.
* Bump version number.
* Update copyright years.
* Python style, whitespace, and import cleanups.
* Print error messages via logger instead of stderr. - 22. By Barry Warsaw
-
* python-dbus cannot type-convert a set, so use a tuple for the package
set when --all is given to the computer-janitor cli. (LP: #601585)
* Fix exceptoin when the user de-selects all cruft in the ui, then clicks
on the 'Do' button. Instead, a dialog pops up that says there's nothing
to do. (LP: #591433)
* Clean up some unused imports. - 21. By Barry Warsaw
-
* debian/control: Add explicit dependency on dbus since depending on
python-dbus does not yield an implicit dependency on dbus. (LP: #665740)
* computerjanitord/authenticator .py: Explicitly convert start-time to a
UInt64(0). Under Natty, implicit conversion uses a UInt32 which does
not match the CheckAuthorization signature. (LP: #676488) - 20. By Matthias Klose
-
Rebuild with python 2.7 as the python default.
- 19. By Barry Warsaw
-
Fix icon; given by Pavol Klačanský. (LP: #434431)
- 18. By Barry Warsaw
-
Remove dependency on python-fstab since the fstab_plugin is disabled
now and no package provides python-fstab any more. - 17. By Barry Warsaw
-
* Fixes for translation support.
- Turn {foo} string substitutions back into %(foo)s strings since
gettext does not yet support validation of {foo} or $foo
substitutions. (LP: #621723)
- Ensure that POTFILES.in has the proper type information for the
ComputerJanitor.ui file. (LP: #612493)
Preview Diff
1 | === added file 'COPYING' | |||
2 | --- COPYING 1970-01-01 00:00:00 +0000 | |||
3 | +++ COPYING 2011-02-28 19:09:32 +0000 | |||
4 | @@ -0,0 +1,676 @@ | |||
5 | 1 | |||
6 | 2 | GNU GENERAL PUBLIC LICENSE | ||
7 | 3 | Version 3, 29 June 2007 | ||
8 | 4 | |||
9 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
10 | 6 | Everyone is permitted to copy and distribute verbatim copies | ||
11 | 7 | of this license document, but changing it is not allowed. | ||
12 | 8 | |||
13 | 9 | Preamble | ||
14 | 10 | |||
15 | 11 | The GNU General Public License is a free, copyleft license for | ||
16 | 12 | software and other kinds of works. | ||
17 | 13 | |||
18 | 14 | The licenses for most software and other practical works are designed | ||
19 | 15 | to take away your freedom to share and change the works. By contrast, | ||
20 | 16 | the GNU General Public License is intended to guarantee your freedom to | ||
21 | 17 | share and change all versions of a program--to make sure it remains free | ||
22 | 18 | software for all its users. We, the Free Software Foundation, use the | ||
23 | 19 | GNU General Public License for most of our software; it applies also to | ||
24 | 20 | any other work released this way by its authors. You can apply it to | ||
25 | 21 | your programs, too. | ||
26 | 22 | |||
27 | 23 | When we speak of free software, we are referring to freedom, not | ||
28 | 24 | price. Our General Public Licenses are designed to make sure that you | ||
29 | 25 | have the freedom to distribute copies of free software (and charge for | ||
30 | 26 | them if you wish), that you receive source code or can get it if you | ||
31 | 27 | want it, that you can change the software or use pieces of it in new | ||
32 | 28 | free programs, and that you know you can do these things. | ||
33 | 29 | |||
34 | 30 | To protect your rights, we need to prevent others from denying you | ||
35 | 31 | these rights or asking you to surrender the rights. Therefore, you have | ||
36 | 32 | certain responsibilities if you distribute copies of the software, or if | ||
37 | 33 | you modify it: responsibilities to respect the freedom of others. | ||
38 | 34 | |||
39 | 35 | For example, if you distribute copies of such a program, whether | ||
40 | 36 | gratis or for a fee, you must pass on to the recipients the same | ||
41 | 37 | freedoms that you received. You must make sure that they, too, receive | ||
42 | 38 | or can get the source code. And you must show them these terms so they | ||
43 | 39 | know their rights. | ||
44 | 40 | |||
45 | 41 | Developers that use the GNU GPL protect your rights with two steps: | ||
46 | 42 | (1) assert copyright on the software, and (2) offer you this License | ||
47 | 43 | giving you legal permission to copy, distribute and/or modify it. | ||
48 | 44 | |||
49 | 45 | For the developers' and authors' protection, the GPL clearly explains | ||
50 | 46 | that there is no warranty for this free software. For both users' and | ||
51 | 47 | authors' sake, the GPL requires that modified versions be marked as | ||
52 | 48 | changed, so that their problems will not be attributed erroneously to | ||
53 | 49 | authors of previous versions. | ||
54 | 50 | |||
55 | 51 | Some devices are designed to deny users access to install or run | ||
56 | 52 | modified versions of the software inside them, although the manufacturer | ||
57 | 53 | can do so. This is fundamentally incompatible with the aim of | ||
58 | 54 | protecting users' freedom to change the software. The systematic | ||
59 | 55 | pattern of such abuse occurs in the area of products for individuals to | ||
60 | 56 | use, which is precisely where it is most unacceptable. Therefore, we | ||
61 | 57 | have designed this version of the GPL to prohibit the practice for those | ||
62 | 58 | products. If such problems arise substantially in other domains, we | ||
63 | 59 | stand ready to extend this provision to those domains in future versions | ||
64 | 60 | of the GPL, as needed to protect the freedom of users. | ||
65 | 61 | |||
66 | 62 | Finally, every program is threatened constantly by software patents. | ||
67 | 63 | States should not allow patents to restrict development and use of | ||
68 | 64 | software on general-purpose computers, but in those that do, we wish to | ||
69 | 65 | avoid the special danger that patents applied to a free program could | ||
70 | 66 | make it effectively proprietary. To prevent this, the GPL assures that | ||
71 | 67 | patents cannot be used to render the program non-free. | ||
72 | 68 | |||
73 | 69 | The precise terms and conditions for copying, distribution and | ||
74 | 70 | modification follow. | ||
75 | 71 | |||
76 | 72 | TERMS AND CONDITIONS | ||
77 | 73 | |||
78 | 74 | 0. Definitions. | ||
79 | 75 | |||
80 | 76 | "This License" refers to version 3 of the GNU General Public License. | ||
81 | 77 | |||
82 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of | ||
83 | 79 | works, such as semiconductor masks. | ||
84 | 80 | |||
85 | 81 | "The Program" refers to any copyrightable work licensed under this | ||
86 | 82 | License. Each licensee is addressed as "you". "Licensees" and | ||
87 | 83 | "recipients" may be individuals or organizations. | ||
88 | 84 | |||
89 | 85 | To "modify" a work means to copy from or adapt all or part of the work | ||
90 | 86 | in a fashion requiring copyright permission, other than the making of an | ||
91 | 87 | exact copy. The resulting work is called a "modified version" of the | ||
92 | 88 | earlier work or a work "based on" the earlier work. | ||
93 | 89 | |||
94 | 90 | A "covered work" means either the unmodified Program or a work based | ||
95 | 91 | on the Program. | ||
96 | 92 | |||
97 | 93 | To "propagate" a work means to do anything with it that, without | ||
98 | 94 | permission, would make you directly or secondarily liable for | ||
99 | 95 | infringement under applicable copyright law, except executing it on a | ||
100 | 96 | computer or modifying a private copy. Propagation includes copying, | ||
101 | 97 | distribution (with or without modification), making available to the | ||
102 | 98 | public, and in some countries other activities as well. | ||
103 | 99 | |||
104 | 100 | To "convey" a work means any kind of propagation that enables other | ||
105 | 101 | parties to make or receive copies. Mere interaction with a user through | ||
106 | 102 | a computer network, with no transfer of a copy, is not conveying. | ||
107 | 103 | |||
108 | 104 | An interactive user interface displays "Appropriate Legal Notices" | ||
109 | 105 | to the extent that it includes a convenient and prominently visible | ||
110 | 106 | feature that (1) displays an appropriate copyright notice, and (2) | ||
111 | 107 | tells the user that there is no warranty for the work (except to the | ||
112 | 108 | extent that warranties are provided), that licensees may convey the | ||
113 | 109 | work under this License, and how to view a copy of this License. If | ||
114 | 110 | the interface presents a list of user commands or options, such as a | ||
115 | 111 | menu, a prominent item in the list meets this criterion. | ||
116 | 112 | |||
117 | 113 | 1. Source Code. | ||
118 | 114 | |||
119 | 115 | The "source code" for a work means the preferred form of the work | ||
120 | 116 | for making modifications to it. "Object code" means any non-source | ||
121 | 117 | form of a work. | ||
122 | 118 | |||
123 | 119 | A "Standard Interface" means an interface that either is an official | ||
124 | 120 | standard defined by a recognized standards body, or, in the case of | ||
125 | 121 | interfaces specified for a particular programming language, one that | ||
126 | 122 | is widely used among developers working in that language. | ||
127 | 123 | |||
128 | 124 | The "System Libraries" of an executable work include anything, other | ||
129 | 125 | than the work as a whole, that (a) is included in the normal form of | ||
130 | 126 | packaging a Major Component, but which is not part of that Major | ||
131 | 127 | Component, and (b) serves only to enable use of the work with that | ||
132 | 128 | Major Component, or to implement a Standard Interface for which an | ||
133 | 129 | implementation is available to the public in source code form. A | ||
134 | 130 | "Major Component", in this context, means a major essential component | ||
135 | 131 | (kernel, window system, and so on) of the specific operating system | ||
136 | 132 | (if any) on which the executable work runs, or a compiler used to | ||
137 | 133 | produce the work, or an object code interpreter used to run it. | ||
138 | 134 | |||
139 | 135 | The "Corresponding Source" for a work in object code form means all | ||
140 | 136 | the source code needed to generate, install, and (for an executable | ||
141 | 137 | work) run the object code and to modify the work, including scripts to | ||
142 | 138 | control those activities. However, it does not include the work's | ||
143 | 139 | System Libraries, or general-purpose tools or generally available free | ||
144 | 140 | programs which are used unmodified in performing those activities but | ||
145 | 141 | which are not part of the work. For example, Corresponding Source | ||
146 | 142 | includes interface definition files associated with source files for | ||
147 | 143 | the work, and the source code for shared libraries and dynamically | ||
148 | 144 | linked subprograms that the work is specifically designed to require, | ||
149 | 145 | such as by intimate data communication or control flow between those | ||
150 | 146 | subprograms and other parts of the work. | ||
151 | 147 | |||
152 | 148 | The Corresponding Source need not include anything that users | ||
153 | 149 | can regenerate automatically from other parts of the Corresponding | ||
154 | 150 | Source. | ||
155 | 151 | |||
156 | 152 | The Corresponding Source for a work in source code form is that | ||
157 | 153 | same work. | ||
158 | 154 | |||
159 | 155 | 2. Basic Permissions. | ||
160 | 156 | |||
161 | 157 | All rights granted under this License are granted for the term of | ||
162 | 158 | copyright on the Program, and are irrevocable provided the stated | ||
163 | 159 | conditions are met. This License explicitly affirms your unlimited | ||
164 | 160 | permission to run the unmodified Program. The output from running a | ||
165 | 161 | covered work is covered by this License only if the output, given its | ||
166 | 162 | content, constitutes a covered work. This License acknowledges your | ||
167 | 163 | rights of fair use or other equivalent, as provided by copyright law. | ||
168 | 164 | |||
169 | 165 | You may make, run and propagate covered works that you do not | ||
170 | 166 | convey, without conditions so long as your license otherwise remains | ||
171 | 167 | in force. You may convey covered works to others for the sole purpose | ||
172 | 168 | of having them make modifications exclusively for you, or provide you | ||
173 | 169 | with facilities for running those works, provided that you comply with | ||
174 | 170 | the terms of this License in conveying all material for which you do | ||
175 | 171 | not control copyright. Those thus making or running the covered works | ||
176 | 172 | for you must do so exclusively on your behalf, under your direction | ||
177 | 173 | and control, on terms that prohibit them from making any copies of | ||
178 | 174 | your copyrighted material outside their relationship with you. | ||
179 | 175 | |||
180 | 176 | Conveying under any other circumstances is permitted solely under | ||
181 | 177 | the conditions stated below. Sublicensing is not allowed; section 10 | ||
182 | 178 | makes it unnecessary. | ||
183 | 179 | |||
184 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | ||
185 | 181 | |||
186 | 182 | No covered work shall be deemed part of an effective technological | ||
187 | 183 | measure under any applicable law fulfilling obligations under article | ||
188 | 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | ||
189 | 185 | similar laws prohibiting or restricting circumvention of such | ||
190 | 186 | measures. | ||
191 | 187 | |||
192 | 188 | When you convey a covered work, you waive any legal power to forbid | ||
193 | 189 | circumvention of technological measures to the extent such circumvention | ||
194 | 190 | is effected by exercising rights under this License with respect to | ||
195 | 191 | the covered work, and you disclaim any intention to limit operation or | ||
196 | 192 | modification of the work as a means of enforcing, against the work's | ||
197 | 193 | users, your or third parties' legal rights to forbid circumvention of | ||
198 | 194 | technological measures. | ||
199 | 195 | |||
200 | 196 | 4. Conveying Verbatim Copies. | ||
201 | 197 | |||
202 | 198 | You may convey verbatim copies of the Program's source code as you | ||
203 | 199 | receive it, in any medium, provided that you conspicuously and | ||
204 | 200 | appropriately publish on each copy an appropriate copyright notice; | ||
205 | 201 | keep intact all notices stating that this License and any | ||
206 | 202 | non-permissive terms added in accord with section 7 apply to the code; | ||
207 | 203 | keep intact all notices of the absence of any warranty; and give all | ||
208 | 204 | recipients a copy of this License along with the Program. | ||
209 | 205 | |||
210 | 206 | You may charge any price or no price for each copy that you convey, | ||
211 | 207 | and you may offer support or warranty protection for a fee. | ||
212 | 208 | |||
213 | 209 | 5. Conveying Modified Source Versions. | ||
214 | 210 | |||
215 | 211 | You may convey a work based on the Program, or the modifications to | ||
216 | 212 | produce it from the Program, in the form of source code under the | ||
217 | 213 | terms of section 4, provided that you also meet all of these conditions: | ||
218 | 214 | |||
219 | 215 | a) The work must carry prominent notices stating that you modified | ||
220 | 216 | it, and giving a relevant date. | ||
221 | 217 | |||
222 | 218 | b) The work must carry prominent notices stating that it is | ||
223 | 219 | released under this License and any conditions added under section | ||
224 | 220 | 7. This requirement modifies the requirement in section 4 to | ||
225 | 221 | "keep intact all notices". | ||
226 | 222 | |||
227 | 223 | c) You must license the entire work, as a whole, under this | ||
228 | 224 | License to anyone who comes into possession of a copy. This | ||
229 | 225 | License will therefore apply, along with any applicable section 7 | ||
230 | 226 | additional terms, to the whole of the work, and all its parts, | ||
231 | 227 | regardless of how they are packaged. This License gives no | ||
232 | 228 | permission to license the work in any other way, but it does not | ||
233 | 229 | invalidate such permission if you have separately received it. | ||
234 | 230 | |||
235 | 231 | d) If the work has interactive user interfaces, each must display | ||
236 | 232 | Appropriate Legal Notices; however, if the Program has interactive | ||
237 | 233 | interfaces that do not display Appropriate Legal Notices, your | ||
238 | 234 | work need not make them do so. | ||
239 | 235 | |||
240 | 236 | A compilation of a covered work with other separate and independent | ||
241 | 237 | works, which are not by their nature extensions of the covered work, | ||
242 | 238 | and which are not combined with it such as to form a larger program, | ||
243 | 239 | in or on a volume of a storage or distribution medium, is called an | ||
244 | 240 | "aggregate" if the compilation and its resulting copyright are not | ||
245 | 241 | used to limit the access or legal rights of the compilation's users | ||
246 | 242 | beyond what the individual works permit. Inclusion of a covered work | ||
247 | 243 | in an aggregate does not cause this License to apply to the other | ||
248 | 244 | parts of the aggregate. | ||
249 | 245 | |||
250 | 246 | 6. Conveying Non-Source Forms. | ||
251 | 247 | |||
252 | 248 | You may convey a covered work in object code form under the terms | ||
253 | 249 | of sections 4 and 5, provided that you also convey the | ||
254 | 250 | machine-readable Corresponding Source under the terms of this License, | ||
255 | 251 | in one of these ways: | ||
256 | 252 | |||
257 | 253 | a) Convey the object code in, or embodied in, a physical product | ||
258 | 254 | (including a physical distribution medium), accompanied by the | ||
259 | 255 | Corresponding Source fixed on a durable physical medium | ||
260 | 256 | customarily used for software interchange. | ||
261 | 257 | |||
262 | 258 | b) Convey the object code in, or embodied in, a physical product | ||
263 | 259 | (including a physical distribution medium), accompanied by a | ||
264 | 260 | written offer, valid for at least three years and valid for as | ||
265 | 261 | long as you offer spare parts or customer support for that product | ||
266 | 262 | model, to give anyone who possesses the object code either (1) a | ||
267 | 263 | copy of the Corresponding Source for all the software in the | ||
268 | 264 | product that is covered by this License, on a durable physical | ||
269 | 265 | medium customarily used for software interchange, for a price no | ||
270 | 266 | more than your reasonable cost of physically performing this | ||
271 | 267 | conveying of source, or (2) access to copy the | ||
272 | 268 | Corresponding Source from a network server at no charge. | ||
273 | 269 | |||
274 | 270 | c) Convey individual copies of the object code with a copy of the | ||
275 | 271 | written offer to provide the Corresponding Source. This | ||
276 | 272 | alternative is allowed only occasionally and noncommercially, and | ||
277 | 273 | only if you received the object code with such an offer, in accord | ||
278 | 274 | with subsection 6b. | ||
279 | 275 | |||
280 | 276 | d) Convey the object code by offering access from a designated | ||
281 | 277 | place (gratis or for a charge), and offer equivalent access to the | ||
282 | 278 | Corresponding Source in the same way through the same place at no | ||
283 | 279 | further charge. You need not require recipients to copy the | ||
284 | 280 | Corresponding Source along with the object code. If the place to | ||
285 | 281 | copy the object code is a network server, the Corresponding Source | ||
286 | 282 | may be on a different server (operated by you or a third party) | ||
287 | 283 | that supports equivalent copying facilities, provided you maintain | ||
288 | 284 | clear directions next to the object code saying where to find the | ||
289 | 285 | Corresponding Source. Regardless of what server hosts the | ||
290 | 286 | Corresponding Source, you remain obligated to ensure that it is | ||
291 | 287 | available for as long as needed to satisfy these requirements. | ||
292 | 288 | |||
293 | 289 | e) Convey the object code using peer-to-peer transmission, provided | ||
294 | 290 | you inform other peers where the object code and Corresponding | ||
295 | 291 | Source of the work are being offered to the general public at no | ||
296 | 292 | charge under subsection 6d. | ||
297 | 293 | |||
298 | 294 | A separable portion of the object code, whose source code is excluded | ||
299 | 295 | from the Corresponding Source as a System Library, need not be | ||
300 | 296 | included in conveying the object code work. | ||
301 | 297 | |||
302 | 298 | A "User Product" is either (1) a "consumer product", which means any | ||
303 | 299 | tangible personal property which is normally used for personal, family, | ||
304 | 300 | or household purposes, or (2) anything designed or sold for incorporation | ||
305 | 301 | into a dwelling. In determining whether a product is a consumer product, | ||
306 | 302 | doubtful cases shall be resolved in favor of coverage. For a particular | ||
307 | 303 | product received by a particular user, "normally used" refers to a | ||
308 | 304 | typical or common use of that class of product, regardless of the status | ||
309 | 305 | of the particular user or of the way in which the particular user | ||
310 | 306 | actually uses, or expects or is expected to use, the product. A product | ||
311 | 307 | is a consumer product regardless of whether the product has substantial | ||
312 | 308 | commercial, industrial or non-consumer uses, unless such uses represent | ||
313 | 309 | the only significant mode of use of the product. | ||
314 | 310 | |||
315 | 311 | "Installation Information" for a User Product means any methods, | ||
316 | 312 | procedures, authorization keys, or other information required to install | ||
317 | 313 | and execute modified versions of a covered work in that User Product from | ||
318 | 314 | a modified version of its Corresponding Source. The information must | ||
319 | 315 | suffice to ensure that the continued functioning of the modified object | ||
320 | 316 | code is in no case prevented or interfered with solely because | ||
321 | 317 | modification has been made. | ||
322 | 318 | |||
323 | 319 | If you convey an object code work under this section in, or with, or | ||
324 | 320 | specifically for use in, a User Product, and the conveying occurs as | ||
325 | 321 | part of a transaction in which the right of possession and use of the | ||
326 | 322 | User Product is transferred to the recipient in perpetuity or for a | ||
327 | 323 | fixed term (regardless of how the transaction is characterized), the | ||
328 | 324 | Corresponding Source conveyed under this section must be accompanied | ||
329 | 325 | by the Installation Information. But this requirement does not apply | ||
330 | 326 | if neither you nor any third party retains the ability to install | ||
331 | 327 | modified object code on the User Product (for example, the work has | ||
332 | 328 | been installed in ROM). | ||
333 | 329 | |||
334 | 330 | The requirement to provide Installation Information does not include a | ||
335 | 331 | requirement to continue to provide support service, warranty, or updates | ||
336 | 332 | for a work that has been modified or installed by the recipient, or for | ||
337 | 333 | the User Product in which it has been modified or installed. Access to a | ||
338 | 334 | network may be denied when the modification itself materially and | ||
339 | 335 | adversely affects the operation of the network or violates the rules and | ||
340 | 336 | protocols for communication across the network. | ||
341 | 337 | |||
342 | 338 | Corresponding Source conveyed, and Installation Information provided, | ||
343 | 339 | in accord with this section must be in a format that is publicly | ||
344 | 340 | documented (and with an implementation available to the public in | ||
345 | 341 | source code form), and must require no special password or key for | ||
346 | 342 | unpacking, reading or copying. | ||
347 | 343 | |||
348 | 344 | 7. Additional Terms. | ||
349 | 345 | |||
350 | 346 | "Additional permissions" are terms that supplement the terms of this | ||
351 | 347 | License by making exceptions from one or more of its conditions. | ||
352 | 348 | Additional permissions that are applicable to the entire Program shall | ||
353 | 349 | be treated as though they were included in this License, to the extent | ||
354 | 350 | that they are valid under applicable law. If additional permissions | ||
355 | 351 | apply only to part of the Program, that part may be used separately | ||
356 | 352 | under those permissions, but the entire Program remains governed by | ||
357 | 353 | this License without regard to the additional permissions. | ||
358 | 354 | |||
359 | 355 | When you convey a copy of a covered work, you may at your option | ||
360 | 356 | remove any additional permissions from that copy, or from any part of | ||
361 | 357 | it. (Additional permissions may be written to require their own | ||
362 | 358 | removal in certain cases when you modify the work.) You may place | ||
363 | 359 | additional permissions on material, added by you to a covered work, | ||
364 | 360 | for which you have or can give appropriate copyright permission. | ||
365 | 361 | |||
366 | 362 | Notwithstanding any other provision of this License, for material you | ||
367 | 363 | add to a covered work, you may (if authorized by the copyright holders of | ||
368 | 364 | that material) supplement the terms of this License with terms: | ||
369 | 365 | |||
370 | 366 | a) Disclaiming warranty or limiting liability differently from the | ||
371 | 367 | terms of sections 15 and 16 of this License; or | ||
372 | 368 | |||
373 | 369 | b) Requiring preservation of specified reasonable legal notices or | ||
374 | 370 | author attributions in that material or in the Appropriate Legal | ||
375 | 371 | Notices displayed by works containing it; or | ||
376 | 372 | |||
377 | 373 | c) Prohibiting misrepresentation of the origin of that material, or | ||
378 | 374 | requiring that modified versions of such material be marked in | ||
379 | 375 | reasonable ways as different from the original version; or | ||
380 | 376 | |||
381 | 377 | d) Limiting the use for publicity purposes of names of licensors or | ||
382 | 378 | authors of the material; or | ||
383 | 379 | |||
384 | 380 | e) Declining to grant rights under trademark law for use of some | ||
385 | 381 | trade names, trademarks, or service marks; or | ||
386 | 382 | |||
387 | 383 | f) Requiring indemnification of licensors and authors of that | ||
388 | 384 | material by anyone who conveys the material (or modified versions of | ||
389 | 385 | it) with contractual assumptions of liability to the recipient, for | ||
390 | 386 | any liability that these contractual assumptions directly impose on | ||
391 | 387 | those licensors and authors. | ||
392 | 388 | |||
393 | 389 | All other non-permissive additional terms are considered "further | ||
394 | 390 | restrictions" within the meaning of section 10. If the Program as you | ||
395 | 391 | received it, or any part of it, contains a notice stating that it is | ||
396 | 392 | governed by this License along with a term that is a further | ||
397 | 393 | restriction, you may remove that term. If a license document contains | ||
398 | 394 | a further restriction but permits relicensing or conveying under this | ||
399 | 395 | License, you may add to a covered work material governed by the terms | ||
400 | 396 | of that license document, provided that the further restriction does | ||
401 | 397 | not survive such relicensing or conveying. | ||
402 | 398 | |||
403 | 399 | If you add terms to a covered work in accord with this section, you | ||
404 | 400 | must place, in the relevant source files, a statement of the | ||
405 | 401 | additional terms that apply to those files, or a notice indicating | ||
406 | 402 | where to find the applicable terms. | ||
407 | 403 | |||
408 | 404 | Additional terms, permissive or non-permissive, may be stated in the | ||
409 | 405 | form of a separately written license, or stated as exceptions; | ||
410 | 406 | the above requirements apply either way. | ||
411 | 407 | |||
412 | 408 | 8. Termination. | ||
413 | 409 | |||
414 | 410 | You may not propagate or modify a covered work except as expressly | ||
415 | 411 | provided under this License. Any attempt otherwise to propagate or | ||
416 | 412 | modify it is void, and will automatically terminate your rights under | ||
417 | 413 | this License (including any patent licenses granted under the third | ||
418 | 414 | paragraph of section 11). | ||
419 | 415 | |||
420 | 416 | However, if you cease all violation of this License, then your | ||
421 | 417 | license from a particular copyright holder is reinstated (a) | ||
422 | 418 | provisionally, unless and until the copyright holder explicitly and | ||
423 | 419 | finally terminates your license, and (b) permanently, if the copyright | ||
424 | 420 | holder fails to notify you of the violation by some reasonable means | ||
425 | 421 | prior to 60 days after the cessation. | ||
426 | 422 | |||
427 | 423 | Moreover, your license from a particular copyright holder is | ||
428 | 424 | reinstated permanently if the copyright holder notifies you of the | ||
429 | 425 | violation by some reasonable means, this is the first time you have | ||
430 | 426 | received notice of violation of this License (for any work) from that | ||
431 | 427 | copyright holder, and you cure the violation prior to 30 days after | ||
432 | 428 | your receipt of the notice. | ||
433 | 429 | |||
434 | 430 | Termination of your rights under this section does not terminate the | ||
435 | 431 | licenses of parties who have received copies or rights from you under | ||
436 | 432 | this License. If your rights have been terminated and not permanently | ||
437 | 433 | reinstated, you do not qualify to receive new licenses for the same | ||
438 | 434 | material under section 10. | ||
439 | 435 | |||
440 | 436 | 9. Acceptance Not Required for Having Copies. | ||
441 | 437 | |||
442 | 438 | You are not required to accept this License in order to receive or | ||
443 | 439 | run a copy of the Program. Ancillary propagation of a covered work | ||
444 | 440 | occurring solely as a consequence of using peer-to-peer transmission | ||
445 | 441 | to receive a copy likewise does not require acceptance. However, | ||
446 | 442 | nothing other than this License grants you permission to propagate or | ||
447 | 443 | modify any covered work. These actions infringe copyright if you do | ||
448 | 444 | not accept this License. Therefore, by modifying or propagating a | ||
449 | 445 | covered work, you indicate your acceptance of this License to do so. | ||
450 | 446 | |||
451 | 447 | 10. Automatic Licensing of Downstream Recipients. | ||
452 | 448 | |||
453 | 449 | Each time you convey a covered work, the recipient automatically | ||
454 | 450 | receives a license from the original licensors, to run, modify and | ||
455 | 451 | propagate that work, subject to this License. You are not responsible | ||
456 | 452 | for enforcing compliance by third parties with this License. | ||
457 | 453 | |||
458 | 454 | An "entity transaction" is a transaction transferring control of an | ||
459 | 455 | organization, or substantially all assets of one, or subdividing an | ||
460 | 456 | organization, or merging organizations. If propagation of a covered | ||
461 | 457 | work results from an entity transaction, each party to that | ||
462 | 458 | transaction who receives a copy of the work also receives whatever | ||
463 | 459 | licenses to the work the party's predecessor in interest had or could | ||
464 | 460 | give under the previous paragraph, plus a right to possession of the | ||
465 | 461 | Corresponding Source of the work from the predecessor in interest, if | ||
466 | 462 | the predecessor has it or can get it with reasonable efforts. | ||
467 | 463 | |||
468 | 464 | You may not impose any further restrictions on the exercise of the | ||
469 | 465 | rights granted or affirmed under this License. For example, you may | ||
470 | 466 | not impose a license fee, royalty, or other charge for exercise of | ||
471 | 467 | rights granted under this License, and you may not initiate litigation | ||
472 | 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that | ||
473 | 469 | any patent claim is infringed by making, using, selling, offering for | ||
474 | 470 | sale, or importing the Program or any portion of it. | ||
475 | 471 | |||
476 | 472 | 11. Patents. | ||
477 | 473 | |||
478 | 474 | A "contributor" is a copyright holder who authorizes use under this | ||
479 | 475 | License of the Program or a work on which the Program is based. The | ||
480 | 476 | work thus licensed is called the contributor's "contributor version". | ||
481 | 477 | |||
482 | 478 | A contributor's "essential patent claims" are all patent claims | ||
483 | 479 | owned or controlled by the contributor, whether already acquired or | ||
484 | 480 | hereafter acquired, that would be infringed by some manner, permitted | ||
485 | 481 | by this License, of making, using, or selling its contributor version, | ||
486 | 482 | but do not include claims that would be infringed only as a | ||
487 | 483 | consequence of further modification of the contributor version. For | ||
488 | 484 | purposes of this definition, "control" includes the right to grant | ||
489 | 485 | patent sublicenses in a manner consistent with the requirements of | ||
490 | 486 | this License. | ||
491 | 487 | |||
492 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free | ||
493 | 489 | patent license under the contributor's essential patent claims, to | ||
494 | 490 | make, use, sell, offer for sale, import and otherwise run, modify and | ||
495 | 491 | propagate the contents of its contributor version. | ||
496 | 492 | |||
497 | 493 | In the following three paragraphs, a "patent license" is any express | ||
498 | 494 | agreement or commitment, however denominated, not to enforce a patent | ||
499 | 495 | (such as an express permission to practice a patent or covenant not to | ||
500 | 496 | sue for patent infringement). To "grant" such a patent license to a | ||
501 | 497 | party means to make such an agreement or commitment not to enforce a | ||
502 | 498 | patent against the party. | ||
503 | 499 | |||
504 | 500 | If you convey a covered work, knowingly relying on a patent license, | ||
505 | 501 | and the Corresponding Source of the work is not available for anyone | ||
506 | 502 | to copy, free of charge and under the terms of this License, through a | ||
507 | 503 | publicly available network server or other readily accessible means, | ||
508 | 504 | then you must either (1) cause the Corresponding Source to be so | ||
509 | 505 | available, or (2) arrange to deprive yourself of the benefit of the | ||
510 | 506 | patent license for this particular work, or (3) arrange, in a manner | ||
511 | 507 | consistent with the requirements of this License, to extend the patent | ||
512 | 508 | license to downstream recipients. "Knowingly relying" means you have | ||
513 | 509 | actual knowledge that, but for the patent license, your conveying the | ||
514 | 510 | covered work in a country, or your recipient's use of the covered work | ||
515 | 511 | in a country, would infringe one or more identifiable patents in that | ||
516 | 512 | country that you have reason to believe are valid. | ||
517 | 513 | |||
518 | 514 | If, pursuant to or in connection with a single transaction or | ||
519 | 515 | arrangement, you convey, or propagate by procuring conveyance of, a | ||
520 | 516 | covered work, and grant a patent license to some of the parties | ||
521 | 517 | receiving the covered work authorizing them to use, propagate, modify | ||
522 | 518 | or convey a specific copy of the covered work, then the patent license | ||
523 | 519 | you grant is automatically extended to all recipients of the covered | ||
524 | 520 | work and works based on it. | ||
525 | 521 | |||
526 | 522 | A patent license is "discriminatory" if it does not include within | ||
527 | 523 | the scope of its coverage, prohibits the exercise of, or is | ||
528 | 524 | conditioned on the non-exercise of one or more of the rights that are | ||
529 | 525 | specifically granted under this License. You may not convey a covered | ||
530 | 526 | work if you are a party to an arrangement with a third party that is | ||
531 | 527 | in the business of distributing software, under which you make payment | ||
532 | 528 | to the third party based on the extent of your activity of conveying | ||
533 | 529 | the work, and under which the third party grants, to any of the | ||
534 | 530 | parties who would receive the covered work from you, a discriminatory | ||
535 | 531 | patent license (a) in connection with copies of the covered work | ||
536 | 532 | conveyed by you (or copies made from those copies), or (b) primarily | ||
537 | 533 | for and in connection with specific products or compilations that | ||
538 | 534 | contain the covered work, unless you entered into that arrangement, | ||
539 | 535 | or that patent license was granted, prior to 28 March 2007. | ||
540 | 536 | |||
541 | 537 | Nothing in this License shall be construed as excluding or limiting | ||
542 | 538 | any implied license or other defenses to infringement that may | ||
543 | 539 | otherwise be available to you under applicable patent law. | ||
544 | 540 | |||
545 | 541 | 12. No Surrender of Others' Freedom. | ||
546 | 542 | |||
547 | 543 | If conditions are imposed on you (whether by court order, agreement or | ||
548 | 544 | otherwise) that contradict the conditions of this License, they do not | ||
549 | 545 | excuse you from the conditions of this License. If you cannot convey a | ||
550 | 546 | covered work so as to satisfy simultaneously your obligations under this | ||
551 | 547 | License and any other pertinent obligations, then as a consequence you may | ||
552 | 548 | not convey it at all. For example, if you agree to terms that obligate you | ||
553 | 549 | to collect a royalty for further conveying from those to whom you convey | ||
554 | 550 | the Program, the only way you could satisfy both those terms and this | ||
555 | 551 | License would be to refrain entirely from conveying the Program. | ||
556 | 552 | |||
557 | 553 | 13. Use with the GNU Affero General Public License. | ||
558 | 554 | |||
559 | 555 | Notwithstanding any other provision of this License, you have | ||
560 | 556 | permission to link or combine any covered work with a work licensed | ||
561 | 557 | under version 3 of the GNU Affero General Public License into a single | ||
562 | 558 | combined work, and to convey the resulting work. The terms of this | ||
563 | 559 | License will continue to apply to the part which is the covered work, | ||
564 | 560 | but the special requirements of the GNU Affero General Public License, | ||
565 | 561 | section 13, concerning interaction through a network will apply to the | ||
566 | 562 | combination as such. | ||
567 | 563 | |||
568 | 564 | 14. Revised Versions of this License. | ||
569 | 565 | |||
570 | 566 | The Free Software Foundation may publish revised and/or new versions of | ||
571 | 567 | the GNU General Public License from time to time. Such new versions will | ||
572 | 568 | be similar in spirit to the present version, but may differ in detail to | ||
573 | 569 | address new problems or concerns. | ||
574 | 570 | |||
575 | 571 | Each version is given a distinguishing version number. If the | ||
576 | 572 | Program specifies that a certain numbered version of the GNU General | ||
577 | 573 | Public License "or any later version" applies to it, you have the | ||
578 | 574 | option of following the terms and conditions either of that numbered | ||
579 | 575 | version or of any later version published by the Free Software | ||
580 | 576 | Foundation. If the Program does not specify a version number of the | ||
581 | 577 | GNU General Public License, you may choose any version ever published | ||
582 | 578 | by the Free Software Foundation. | ||
583 | 579 | |||
584 | 580 | If the Program specifies that a proxy can decide which future | ||
585 | 581 | versions of the GNU General Public License can be used, that proxy's | ||
586 | 582 | public statement of acceptance of a version permanently authorizes you | ||
587 | 583 | to choose that version for the Program. | ||
588 | 584 | |||
589 | 585 | Later license versions may give you additional or different | ||
590 | 586 | permissions. However, no additional obligations are imposed on any | ||
591 | 587 | author or copyright holder as a result of your choosing to follow a | ||
592 | 588 | later version. | ||
593 | 589 | |||
594 | 590 | 15. Disclaimer of Warranty. | ||
595 | 591 | |||
596 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | ||
597 | 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | ||
598 | 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | ||
599 | 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | ||
600 | 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
601 | 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | ||
602 | 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | ||
603 | 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
604 | 600 | |||
605 | 601 | 16. Limitation of Liability. | ||
606 | 602 | |||
607 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
608 | 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | ||
609 | 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | ||
610 | 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | ||
611 | 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | ||
612 | 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | ||
613 | 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | ||
614 | 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||
615 | 611 | SUCH DAMAGES. | ||
616 | 612 | |||
617 | 613 | 17. Interpretation of Sections 15 and 16. | ||
618 | 614 | |||
619 | 615 | If the disclaimer of warranty and limitation of liability provided | ||
620 | 616 | above cannot be given local legal effect according to their terms, | ||
621 | 617 | reviewing courts shall apply local law that most closely approximates | ||
622 | 618 | an absolute waiver of all civil liability in connection with the | ||
623 | 619 | Program, unless a warranty or assumption of liability accompanies a | ||
624 | 620 | copy of the Program in return for a fee. | ||
625 | 621 | |||
626 | 622 | END OF TERMS AND CONDITIONS | ||
627 | 623 | |||
628 | 624 | How to Apply These Terms to Your New Programs | ||
629 | 625 | |||
630 | 626 | If you develop a new program, and you want it to be of the greatest | ||
631 | 627 | possible use to the public, the best way to achieve this is to make it | ||
632 | 628 | free software which everyone can redistribute and change under these terms. | ||
633 | 629 | |||
634 | 630 | To do so, attach the following notices to the program. It is safest | ||
635 | 631 | to attach them to the start of each source file to most effectively | ||
636 | 632 | state the exclusion of warranty; and each file should have at least | ||
637 | 633 | the "copyright" line and a pointer to where the full notice is found. | ||
638 | 634 | |||
639 | 635 | <one line to give the program's name and a brief idea of what it does.> | ||
640 | 636 | Copyright (C) <year> <name of author> | ||
641 | 637 | |||
642 | 638 | This program is free software: you can redistribute it and/or modify | ||
643 | 639 | it under the terms of the GNU General Public License as published by | ||
644 | 640 | the Free Software Foundation, either version 3 of the License, or | ||
645 | 641 | (at your option) any later version. | ||
646 | 642 | |||
647 | 643 | This program is distributed in the hope that it will be useful, | ||
648 | 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
649 | 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
650 | 646 | GNU General Public License for more details. | ||
651 | 647 | |||
652 | 648 | You should have received a copy of the GNU General Public License | ||
653 | 649 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
654 | 650 | |||
655 | 651 | Also add information on how to contact you by electronic and paper mail. | ||
656 | 652 | |||
657 | 653 | If the program does terminal interaction, make it output a short | ||
658 | 654 | notice like this when it starts in an interactive mode: | ||
659 | 655 | |||
660 | 656 | <program> Copyright (C) <year> <name of author> | ||
661 | 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
662 | 658 | This is free software, and you are welcome to redistribute it | ||
663 | 659 | under certain conditions; type `show c' for details. | ||
664 | 660 | |||
665 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
666 | 662 | parts of the General Public License. Of course, your program's commands | ||
667 | 663 | might be different; for a GUI interface, you would use an "about box". | ||
668 | 664 | |||
669 | 665 | You should also get your employer (if you work as a programmer) or school, | ||
670 | 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. | ||
671 | 667 | For more information on this, and how to apply and follow the GNU GPL, see | ||
672 | 668 | <http://www.gnu.org/licenses/>. | ||
673 | 669 | |||
674 | 670 | The GNU General Public License does not permit incorporating your program | ||
675 | 671 | into proprietary programs. If your program is a subroutine library, you | ||
676 | 672 | may consider it more useful to permit linking proprietary applications with | ||
677 | 673 | the library. If this is what you want to do, use the GNU Lesser General | ||
678 | 674 | Public License instead of this License. But first, please read | ||
679 | 675 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | ||
680 | 676 | |||
681 | 0 | 677 | ||
682 | === renamed file 'COPYING' => 'COPYING.moved' | |||
683 | === added file 'CoverageTestRunner.py' | |||
684 | --- CoverageTestRunner.py 1970-01-01 00:00:00 +0000 | |||
685 | +++ CoverageTestRunner.py 2011-02-28 19:09:32 +0000 | |||
686 | @@ -0,0 +1,203 @@ | |||
687 | 1 | # Copyright (C) 2007 Lars Wirzenius <liw@iki.fi> | ||
688 | 2 | # | ||
689 | 3 | # This program is free software; you can redistribute it and/or modify | ||
690 | 4 | # it under the terms of the GNU General Public License as published by | ||
691 | 5 | # the Free Software Foundation; either version 2 of the License, or | ||
692 | 6 | # (at your option) any later version. | ||
693 | 7 | # | ||
694 | 8 | # This program is distributed in the hope that it will be useful, | ||
695 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
696 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
697 | 11 | # GNU General Public License for more details. | ||
698 | 12 | # | ||
699 | 13 | # You should have received a copy of the GNU General Public License along | ||
700 | 14 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
701 | 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
702 | 16 | |||
703 | 17 | |||
704 | 18 | import coverage | ||
705 | 19 | import unittest | ||
706 | 20 | import optparse | ||
707 | 21 | import os | ||
708 | 22 | import imp | ||
709 | 23 | import sys | ||
710 | 24 | import time | ||
711 | 25 | |||
712 | 26 | |||
713 | 27 | class CoverageTestResult(unittest.TestResult): | ||
714 | 28 | |||
715 | 29 | def __init__(self, output, total): | ||
716 | 30 | unittest.TestResult.__init__(self) | ||
717 | 31 | self.output = output | ||
718 | 32 | self.total = total | ||
719 | 33 | self.lastmsg = "" | ||
720 | 34 | self.coverage_missed = [] | ||
721 | 35 | self.timings = [] | ||
722 | 36 | |||
723 | 37 | def addCoverageMissed(self, filename, statements, missed_statements, | ||
724 | 38 | missed_description): | ||
725 | 39 | self.coverage_missed.append((filename, statements, missed_statements, | ||
726 | 40 | missed_description)) | ||
727 | 41 | |||
728 | 42 | def wasSuccessful(self, ignore_coverage=False): | ||
729 | 43 | return (unittest.TestResult.wasSuccessful(self) and | ||
730 | 44 | (ignore_coverage or not self.coverage_missed)) | ||
731 | 45 | |||
732 | 46 | def clearmsg(self): | ||
733 | 47 | self.output.write("\b \b" * len(self.lastmsg)) | ||
734 | 48 | self.lastmsg = "" | ||
735 | 49 | |||
736 | 50 | def write(self, test): | ||
737 | 51 | self.clearmsg() | ||
738 | 52 | self.lastmsg = "Running test %d/%d: %s" % (self.testsRun, | ||
739 | 53 | self.total, | ||
740 | 54 | str(test)[:50]) | ||
741 | 55 | self.output.write(self.lastmsg) | ||
742 | 56 | self.output.flush() | ||
743 | 57 | |||
744 | 58 | def startTest(self, test): | ||
745 | 59 | unittest.TestResult.startTest(self, test) | ||
746 | 60 | self.write(test) | ||
747 | 61 | self.start_time = time.time() | ||
748 | 62 | |||
749 | 63 | def stopTest(self, test): | ||
750 | 64 | end_time = time.time() | ||
751 | 65 | unittest.TestResult.stopTest(self, test) | ||
752 | 66 | self.timings.append((end_time - self.start_time, test)) | ||
753 | 67 | |||
754 | 68 | |||
755 | 69 | class CoverageTestRunner: | ||
756 | 70 | |||
757 | 71 | """A test runner class that insists modules' tests cover them fully.""" | ||
758 | 72 | |||
759 | 73 | def __init__(self): | ||
760 | 74 | self._module_pairs = [] | ||
761 | 75 | |||
762 | 76 | def add_pair(self, module_pathname, test_module_pathname): | ||
763 | 77 | """Add a module and its test module to list of tests.""" | ||
764 | 78 | self._module_pairs.append((module_pathname, test_module_pathname)) | ||
765 | 79 | |||
766 | 80 | def find_pairs(self, dirname): | ||
767 | 81 | """Find all module/test module pairs in directory tree. | ||
768 | 82 | |||
769 | 83 | This method relies on a naming convention: it scans a directory | ||
770 | 84 | tree and assumes that for any file foo.py, if there exists a | ||
771 | 85 | file foo_tests.py or fooTests.py, they form a pair. | ||
772 | 86 | |||
773 | 87 | """ | ||
774 | 88 | |||
775 | 89 | suffixes = ["_tests.py", "Tests.py"] | ||
776 | 90 | |||
777 | 91 | |||
778 | 92 | for dirname, dirnames, filenames in os.walk(dirname): | ||
779 | 93 | tests = [] | ||
780 | 94 | for filename in filenames: | ||
781 | 95 | for suffix in suffixes: | ||
782 | 96 | if filename.endswith(suffix): | ||
783 | 97 | module = filename[:-len(suffix)] + ".py" | ||
784 | 98 | if module in filenames: | ||
785 | 99 | module = os.path.join(dirname, module) | ||
786 | 100 | filename = os.path.join(dirname, filename) | ||
787 | 101 | self.add_pair(module, filename) | ||
788 | 102 | |||
789 | 103 | def _load_module_from_pathname(self, pathname): | ||
790 | 104 | for tuple in imp.get_suffixes(): | ||
791 | 105 | suffix, mode, type = tuple | ||
792 | 106 | if pathname.endswith(suffix): | ||
793 | 107 | name = os.path.basename(pathname[:-len(suffix)]) | ||
794 | 108 | f = file(pathname, mode) | ||
795 | 109 | return imp.load_module(name, f, pathname, tuple) | ||
796 | 110 | raise Exception("Unknown module: %s" % pathname) | ||
797 | 111 | |||
798 | 112 | def _load_pairs(self): | ||
799 | 113 | module_pairs = [] | ||
800 | 114 | loader = unittest.defaultTestLoader | ||
801 | 115 | for pathname, test_pathname in self._module_pairs: | ||
802 | 116 | module = self._load_module_from_pathname(pathname) | ||
803 | 117 | test_module = self._load_module_from_pathname(test_pathname) | ||
804 | 118 | suite = loader.loadTestsFromModule(test_module) | ||
805 | 119 | module_pairs.append((module, test_module, suite)) | ||
806 | 120 | return module_pairs | ||
807 | 121 | |||
808 | 122 | def printErrorList(self, flavor, errors): | ||
809 | 123 | for test, error in errors: | ||
810 | 124 | print "%s: %s" % (flavor, str(test)) | ||
811 | 125 | print str(error) | ||
812 | 126 | |||
813 | 127 | def run(self): | ||
814 | 128 | start_time = time.time() | ||
815 | 129 | |||
816 | 130 | module_pairs = self._load_pairs() | ||
817 | 131 | total_tests = sum(suite.countTestCases() | ||
818 | 132 | for x, y, suite in module_pairs) | ||
819 | 133 | result = CoverageTestResult(sys.stdout, total_tests) | ||
820 | 134 | |||
821 | 135 | for module, test_module, suite in module_pairs: | ||
822 | 136 | coverage.erase() | ||
823 | 137 | coverage.exclude("#\s*pragma: no cover") | ||
824 | 138 | coverage.start() | ||
825 | 139 | sys.path.insert(0, os.path.dirname(module.__file__)) | ||
826 | 140 | reload(module) | ||
827 | 141 | del sys.path[0] | ||
828 | 142 | suite.run(result) | ||
829 | 143 | coverage.stop() | ||
830 | 144 | filename, stmts, missed, missed_desc = coverage.analysis(module) | ||
831 | 145 | if missed: | ||
832 | 146 | result.addCoverageMissed(filename, stmts, missed, missed_desc) | ||
833 | 147 | |||
834 | 148 | end_time = time.time() | ||
835 | 149 | |||
836 | 150 | sys.stdout.write("\n\n") | ||
837 | 151 | |||
838 | 152 | if result.wasSuccessful(): | ||
839 | 153 | print "OK" | ||
840 | 154 | else: | ||
841 | 155 | print "FAILED" | ||
842 | 156 | |||
843 | 157 | if result.errors: | ||
844 | 158 | self.printErrorList("ERROR", result.errors) | ||
845 | 159 | if result.failures: | ||
846 | 160 | self.printErrorList("FAILURE", result.failures) | ||
847 | 161 | if result.coverage_missed: | ||
848 | 162 | |||
849 | 163 | print "Statements missed by per-module tests:" | ||
850 | 164 | width = max(len(x[0]) for x in result.coverage_missed) | ||
851 | 165 | fmt = " %-*s %s" | ||
852 | 166 | print fmt % (width, "Module", "Missed statements") | ||
853 | 167 | for filename, _, _, desc in sorted(result.coverage_missed): | ||
854 | 168 | print fmt % (width, filename, desc) | ||
855 | 169 | |||
856 | 170 | |||
857 | 171 | print "%d failures, %d errors" % (len(result.failures), | ||
858 | 172 | len(result.errors)) | ||
859 | 173 | |||
860 | 174 | if end_time - start_time > 10: | ||
861 | 175 | |||
862 | 176 | print "Slowest tests:" | ||
863 | 177 | for secs, test in sorted(result.timings)[-10:]: | ||
864 | 178 | print " %5.1f s %s" % (secs, str(test)[:70]) | ||
865 | 179 | |||
866 | 180 | print "Time: %.1f s" % (end_time - start_time) | ||
867 | 181 | |||
868 | 182 | return result | ||
869 | 183 | |||
870 | 184 | |||
871 | 185 | def run(dirname="."): | ||
872 | 186 | """Use CoverageTestRunner on the desired directory.""" | ||
873 | 187 | |||
874 | 188 | parser = optparse.OptionParser() | ||
875 | 189 | parser.add_option("--ignore-coverage", action="store_true", | ||
876 | 190 | help="Don't fail tests even if coverage is " | ||
877 | 191 | "incomplete.") | ||
878 | 192 | |||
879 | 193 | opts, args = parser.parse_args() | ||
880 | 194 | |||
881 | 195 | runner = CoverageTestRunner() | ||
882 | 196 | runner.find_pairs(dirname) | ||
883 | 197 | result = runner.run() | ||
884 | 198 | if not result.wasSuccessful(ignore_coverage=opts.ignore_coverage): | ||
885 | 199 | sys.exit(1) | ||
886 | 200 | |||
887 | 201 | |||
888 | 202 | if __name__ == "__main__": | ||
889 | 203 | run() | ||
890 | 0 | 204 | ||
891 | === renamed file 'CoverageTestRunner.py' => 'CoverageTestRunner.py.moved' | |||
892 | === added file 'Makefile' | |||
893 | --- Makefile 1970-01-01 00:00:00 +0000 | |||
894 | +++ Makefile 2011-02-28 19:09:32 +0000 | |||
895 | @@ -0,0 +1,52 @@ | |||
896 | 1 | # Makefile for Computer Janitor | ||
897 | 2 | # | ||
898 | 3 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
899 | 4 | # | ||
900 | 5 | # This program is free software: you can redistribute it and/or modify | ||
901 | 6 | # it under the terms of the GNU General Public License as published by | ||
902 | 7 | # the Free Software Foundation, version 3 of the License. | ||
903 | 8 | # | ||
904 | 9 | # This program is distributed in the hope that it will be useful, | ||
905 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
906 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
907 | 12 | # GNU General Public License for more details. | ||
908 | 13 | # | ||
909 | 14 | # You should have received a copy of the GNU General Public License | ||
910 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
911 | 16 | |||
912 | 17 | all: data/computer-janitor-gtk.desktop | ||
913 | 18 | |||
914 | 19 | DESKTOP=data/computer-janitor-gtk.desktop | ||
915 | 20 | $(DESKTOP): $(DESKTOP).in | ||
916 | 21 | intltool-merge -d po $(DESKTOP).in $(DESKTOP) | ||
917 | 22 | |||
918 | 23 | check: check-unittests check-has-unit-tests check-licenses | ||
919 | 24 | |||
920 | 25 | check-unittests: | ||
921 | 26 | env COMPUTER_JANITOR_UNITTEST=yes LC_ALL=C python -m CoverageTestRunner | ||
922 | 27 | rm -f .coverage | ||
923 | 28 | |||
924 | 29 | check-has-unit-tests: | ||
925 | 30 | find computerjanitorapp -name '*.py' ! -name '*_tests.py' | \ | ||
926 | 31 | grep -Exv '^computerjanitorapp/(__init__|ui_gtk).py' | \ | ||
927 | 32 | sed 's/\.py$$//' | \ | ||
928 | 33 | while read file; do \ | ||
929 | 34 | [ -e $${file}_tests.py ] || \ | ||
930 | 35 | (echo "Missing unit test: $$file.py"; exit 1); done | ||
931 | 36 | |||
932 | 37 | check-licenses: | ||
933 | 38 | ./license-check | ||
934 | 39 | |||
935 | 40 | clean: | ||
936 | 41 | rm -f computerjanitorapp/*.py[co] .coverage | ||
937 | 42 | rm -f po/computerjanitor.pot | ||
938 | 43 | rm -rf build $(DESKTOP) | ||
939 | 44 | |||
940 | 45 | update-po: | ||
941 | 46 | echo '[encoding: UTF-8]' > po/POTFILES.in; \ | ||
942 | 47 | find computerjanitorapp -name \*.py >> po/POTFILES.in; \ | ||
943 | 48 | for f in data/*.ui; do \ | ||
944 | 49 | echo '[type: gettext/glade]'$$f >> po/POTFILES.in; \ | ||
945 | 50 | done; \ | ||
946 | 51 | ls data/*.in plugins/*.py >> po/POTFILES.in; \ | ||
947 | 52 | python setup.py build_i18n --merge-po --po-dir po | ||
948 | 0 | 53 | ||
949 | === renamed file 'Makefile' => 'Makefile.moved' | |||
950 | === added file 'NEWS' | |||
951 | --- NEWS 1970-01-01 00:00:00 +0000 | |||
952 | +++ NEWS 2011-02-28 19:09:32 +0000 | |||
953 | @@ -0,0 +1,262 @@ | |||
954 | 1 | NEWS for Computer Janitor | ||
955 | 2 | ========================= | ||
956 | 3 | |||
957 | 4 | This file summarizes mainly user-visible changes. For detailed | ||
958 | 5 | changes, please see the bzr commit log messages. | ||
959 | 6 | |||
960 | 7 | Version 2.1.1, released 20XX-XX-XX | ||
961 | 8 | |||
962 | 9 | * 24x24 icon location is fixed. (LP: #720743) | ||
963 | 10 | |||
964 | 11 | Version 2.1.0, released 2011-02-16 | ||
965 | 12 | |||
966 | 13 | Martin Pitt | ||
967 | 14 | * Port from pygtk to pygi, giving identical functionality under GTK3, | ||
968 | 15 | however main-panel popup menus are non-functional under GTK2. | ||
969 | 16 | Barry Warsaw | ||
970 | 17 | * Add Edit menu items for selecting and deselecting cruft. | ||
971 | 18 | * Bump version number. | ||
972 | 19 | * Update copyright years. | ||
973 | 20 | * Python style, whitespace, and import cleanups. | ||
974 | 21 | * Print error messages via logger instead of stderr. | ||
975 | 22 | |||
976 | 23 | Version 2.0.5, released 2011-02-15 | ||
977 | 24 | |||
978 | 25 | * python-dbus cannot type-convert a set, so use a tuple for the package | ||
979 | 26 | set when --all is given to the computer-janitor cli. (LP: #601585) | ||
980 | 27 | * Fix exception when the user de-selects all cruft in the ui, then clicks | ||
981 | 28 | on the 'Do' button. Instead, a dialog pops up that says there's nothing | ||
982 | 29 | to do. (LP: #591433) | ||
983 | 30 | * Clean up some unused imports. | ||
984 | 31 | |||
985 | 32 | Version 2.0.4, released 2010-09-20 | ||
986 | 33 | |||
987 | 34 | * Update translation strings (LP: #621723) (LP: #612493) | ||
988 | 35 | * computer-janitor-gtk --help and --version switches added | ||
989 | 36 | * Fixed SystemError crash in open() (LP: #545306) | ||
990 | 37 | * Do not depend on python-fstab any more. | ||
991 | 38 | * Fixed icon (LP: #434431) - Pavol Klačanský | ||
992 | 39 | |||
993 | 40 | Version 2.0, released 2010-03-15 | ||
994 | 41 | |||
995 | 42 | * Refactored the system modifying parts of Computer Janitor into a | ||
996 | 43 | separate dbus daemon. This allows you to run the cli or gtk versions | ||
997 | 44 | without being root. You will be prompted for the administrative | ||
998 | 45 | password when necessary. | ||
999 | 46 | |||
1000 | 47 | * The user interface has been cleaned up to remove previously unused gui | ||
1001 | 48 | elements. | ||
1002 | 49 | |||
1003 | 50 | Version 1.13.3, released 2009-09-09 | ||
1004 | 51 | |||
1005 | 52 | * Fixed URL in About dialog. | ||
1006 | 53 | |||
1007 | 54 | * The "Do cleanups" button is now set to sensitive when there is | ||
1008 | 55 | something to clean. | ||
1009 | 56 | |||
1010 | 57 | * The user is now told if nothing was found to clean up, so they | ||
1011 | 58 | don't wonder why the window is empty. | ||
1012 | 59 | |||
1013 | 60 | * The 'unsupported package' plugin is re-enabled. | ||
1014 | 61 | |||
1015 | 62 | Version 1.13.2, released 2009-08-21 | ||
1016 | 63 | |||
1017 | 64 | * Versions 1.13.0 and 1.13.1 were not released publicly. This | ||
1018 | 65 | section documents all changes since 1.12.1. | ||
1019 | 66 | |||
1020 | 67 | * The GTK user interface has been completely rewritten from scratch. | ||
1021 | 68 | Thanks to Martin Albisetti for the general design. All bugs are belong | ||
1022 | 69 | to Lars Wirzenius anyway. | ||
1023 | 70 | |||
1024 | 71 | * Adapted to new python-apt API. This means the code only works on | ||
1025 | 72 | Ubuntu karmic, not earlier releases. | ||
1026 | 73 | |||
1027 | 74 | * The 'unsupported package' plugin is now not installed by default. | ||
1028 | 75 | This should make it less likely people remove third-party packages | ||
1029 | 76 | by default. | ||
1030 | 77 | |||
1031 | 78 | * The fstab plugin is not installed by default. It is no longer needed | ||
1032 | 79 | in karmic, since the Linux kernel now uses relatime by default. | ||
1033 | 80 | |||
1034 | 81 | BUG FIXES: | ||
1035 | 82 | |||
1036 | 83 | * I18n changes to account for the fact that Computer Janitor's code | ||
1037 | 84 | is in two places (itself, and Update Manager), and thus two po | ||
1038 | 85 | files. | ||
1039 | 86 | |||
1040 | 87 | * I18n change to include plugin code as well. Thanks to Gabor Kelemen. | ||
1041 | 88 | |||
1042 | 89 | * Other i18n changes, in both the GTK and command line user interfaces. | ||
1043 | 90 | |||
1044 | 91 | * All instances of the word 'cruft' have been removed from the user | ||
1045 | 92 | interface. It is not a proper English word. | ||
1046 | 93 | |||
1047 | 94 | * Typo fix in manual page. Thanks to Charlie_Smotherman. | ||
1048 | 95 | |||
1049 | 96 | Version 1.12.1, released 2009-03-04 | ||
1050 | 97 | |||
1051 | 98 | * Change the description text at the top of the main window to be | ||
1052 | 99 | clearer. | ||
1053 | 100 | |||
1054 | 101 | * Sort cruft in the GTK user interface in groups. This should | ||
1055 | 102 | some day get user-visible headings, so it's clearer to the user. | ||
1056 | 103 | |||
1057 | 104 | BUG FIXES: | ||
1058 | 105 | |||
1059 | 106 | * In the GTK user interface, the button "Cleanup" now uses "u" as the | ||
1060 | 107 | accelerator key, rather than "c", which confliced with the | ||
1061 | 108 | accelerator key for the "Close" button. Fixes LP: #311557, reported | ||
1062 | 109 | by hackel. | ||
1063 | 110 | |||
1064 | 111 | * Changed the label for the yes/no column in the GTK UI to be | ||
1065 | 112 | "Remove/fix?" rather than just "Remove?", since not all things | ||
1066 | 113 | are removals. Fixes LP: #300354, reported by Hernando Torque. | ||
1067 | 114 | |||
1068 | 115 | Version 1.12, released 2009-02-19 | ||
1069 | 116 | |||
1070 | 117 | * New plugin: remove files left on the filesystem by the dpkg | ||
1071 | 118 | conffile handling (*.dpkg-old and *.dpkg-new). | ||
1072 | 119 | |||
1073 | 120 | * Code base has been split so that the core parts (plugin management, | ||
1074 | 121 | some of the plugins) now reside in the update-manager source tree. | ||
1075 | 122 | This was done so that update-manager can use the computer-janitor | ||
1076 | 123 | plugins, since there was no point in both programs having code to do | ||
1077 | 124 | the same thing. | ||
1078 | 125 | |||
1079 | 126 | * When handling exceptions within the computer-janitor code, the | ||
1080 | 127 | actual exception is now logged (at DEBUG level), to aid in | ||
1081 | 128 | debugging the cause. | ||
1082 | 129 | |||
1083 | 130 | * Plugins can now declare that they should only be used under specific | ||
1084 | 131 | conditions, rather than always. This is useful for plugins that are | ||
1085 | 132 | used by update-manager. | ||
1086 | 133 | |||
1087 | 134 | Version 1.11, released 2009-02-03 | ||
1088 | 135 | |||
1089 | 136 | * Renamed to Computer Janitor. The old name, Cruft Remover, was using | ||
1090 | 137 | computer jargon (cruft) and gave the wrong impression (the program | ||
1091 | 138 | does not just remove stuff). | ||
1092 | 139 | |||
1093 | 140 | * New plugin to compact the dpkg status file, from Michael Vogt. | ||
1094 | 141 | |||
1095 | 142 | Version 1.10.5, released 2009-01-16 | ||
1096 | 143 | |||
1097 | 144 | * Upon startup, we now verify that the package lists look sane by | ||
1098 | 145 | checking for the dash and gzip packages. If they're not available, | ||
1099 | 146 | we assume something is badly wrong and we won't continue. This | ||
1100 | 147 | makes is very unlikely that people will accidentally remove all | ||
1101 | 148 | their packages because apt didn't have any package lists available. | ||
1102 | 149 | |||
1103 | 150 | * A further safeguard: the running kernel and related packages | ||
1104 | 151 | won't ever be considered cruft anymore. | ||
1105 | 152 | |||
1106 | 153 | * It is now no longer enough to click on the "Cleanup" button to | ||
1107 | 154 | initiate changes (pacxkage removals etc). Instead, a dialog window | ||
1108 | 155 | will pop up and the user has to click on "OK" to continue. | ||
1109 | 156 | |||
1110 | 157 | * A .deb package's short description is now shown in the cruft | ||
1111 | 158 | description. This will help users have an idea what it's all | ||
1112 | 159 | about. (It's insufficient, but was all that there was time for | ||
1113 | 160 | for the Ubuntu intrepid release schedule.) | ||
1114 | 161 | |||
1115 | 162 | * Columns in the cruft list now have titles, to make it easier | ||
1116 | 163 | to understand what ticks mean (remove cruft? don't remove | ||
1117 | 164 | cruft?). | ||
1118 | 165 | |||
1119 | 166 | * The program now reads whitelists in /etc/cruft-remover.d. Cruft | ||
1120 | 167 | named in files in that directory will _not_ be removed. | ||
1121 | 168 | |||
1122 | 169 | * The plugin to remove packages apt considers autoremovable is now | ||
1123 | 170 | enabled. It has been written ages ago, but not been enabled by | ||
1124 | 171 | default until now. | ||
1125 | 172 | |||
1126 | 173 | * The application now uses the icon it has. | ||
1127 | 174 | |||
1128 | 175 | * Added Polish translation from Piotr Makowski. | ||
1129 | 176 | |||
1130 | 177 | * Added Finnish translation from Lars Wirzenius and Timo Jyrinki. | ||
1131 | 178 | |||
1132 | 179 | Version 1.10.4, released 2008-10-27 | ||
1133 | 180 | |||
1134 | 181 | * Quick bug fixes for the Ubuntu 8.10 release. A proper release | ||
1135 | 182 | of Cruft Remover will be made later. | ||
1136 | 183 | |||
1137 | 184 | Version 1.10.3, released 2008-10-14 | ||
1138 | 185 | |||
1139 | 186 | * Bug fixes to how messages are logged, primarily to how character | ||
1140 | 187 | sets are encoded. Found by James Westby. | ||
1141 | 188 | |||
1142 | 189 | Version 1.10.2, released 2008-10-14 | ||
1143 | 190 | |||
1144 | 191 | IMPORTANT CHANGES: | ||
1145 | 192 | |||
1146 | 193 | * If setting up logging to syslog fails, don't crash. Thanks, | ||
1147 | 194 | Ricardo Wurmus. (LP:#274970) | ||
1148 | 195 | |||
1149 | 196 | * The program now supports translations via gettext. A Finnish | ||
1150 | 197 | translation was added. (LP:#279580) | ||
1151 | 198 | |||
1152 | 199 | * Handles errors by giving nice(r) error messages also in the | ||
1153 | 200 | command line version. The GTK+ version already did that. | ||
1154 | 201 | Thanks, Marco Rodrigues. (LP:#281657) | ||
1155 | 202 | |||
1156 | 203 | MINOR CHANGES: | ||
1157 | 204 | |||
1158 | 205 | * Wording in manual page fixed. Thanks, James Westby. | ||
1159 | 206 | |||
1160 | 207 | * Non-functional help button hidden. Thanks, Loïc Minier. (LP:#279577) | ||
1161 | 208 | |||
1162 | 209 | * Cruft description in the GTK+ user interface is cleared after cruft has | ||
1163 | 210 | been cleaned up. | ||
1164 | 211 | |||
1165 | 212 | Version 1.10.1, released 2008-10-06 | ||
1166 | 213 | |||
1167 | 214 | * Bugfix: Cruft in /etc/fstab now goes away from the GTK user interface | ||
1168 | 215 | after a cleanup. Found by James Westby, thanks. | ||
1169 | 216 | |||
1170 | 217 | * cruft-remover-gtk now has a manual page. | ||
1171 | 218 | |||
1172 | 219 | * Bugfix: The GTK user interface now no longer imports the gtk and | ||
1173 | 220 | gobject Python modules globally, but only when the code actually | ||
1174 | 221 | runs, to prevent them from being loaded when running unit tests, | ||
1175 | 222 | etc. (The GTK UI code is not unit tested.) | ||
1176 | 223 | |||
1177 | 224 | Version 1.10, released 2008-09-30 | ||
1178 | 225 | |||
1179 | 226 | * Important fixes to how GTK+ and threads are used: now all GTK+ | ||
1180 | 227 | stuff happens only in the main thread. This turns out to be | ||
1181 | 228 | easier to get right than using gtk.gdk.threads_enter and _leave | ||
1182 | 229 | correctly in all situations, and also allows things like | ||
1183 | 230 | gtk.Dialog.run to be used. | ||
1184 | 231 | |||
1185 | 232 | * Missing test module for the deb_plugin module written. | ||
1186 | 233 | |||
1187 | 234 | * SystemError exceptions (which are raised by python-apt when | ||
1188 | 235 | there is a dpkg error) are now handled, and an error displayed | ||
1189 | 236 | to the user. This fixes LP: #275034. | ||
1190 | 237 | |||
1191 | 238 | * The GTK user interface now displays the version number at startup. | ||
1192 | 239 | The command line interface shows it with the new --version option. | ||
1193 | 240 | |||
1194 | 241 | Version 1.9, released 2008-09-26 | ||
1195 | 242 | |||
1196 | 243 | * Bug fix: cruft-remover-gtk now correctly refreshes the list of | ||
1197 | 244 | cruft after a bug has been fixed. (LP:274715) | ||
1198 | 245 | |||
1199 | 246 | * Bug fix: cruft-remover-gtk disables the "Cleanup" button if there | ||
1200 | 247 | is nothing to clean up. (LP:274717) | ||
1201 | 248 | |||
1202 | 249 | Version 1.8, released 2008-09-23 | ||
1203 | 250 | |||
1204 | 251 | * The GTK user interface now lets you select a row without toggling | ||
1205 | 252 | the status of the cruft. This is useful, because the description | ||
1206 | 253 | of each cruft is shown for the selected row only. | ||
1207 | 254 | |||
1208 | 255 | * Both the GTK and command line user interfaces now attempt to | ||
1209 | 256 | be more helpful in describing what each piece of cruft is. | ||
1210 | 257 | |||
1211 | 258 | Version 1.7, released 2008-09-12 | ||
1212 | 259 | |||
1213 | 260 | * First real public release, despite the version number. (If you have | ||
1214 | 261 | seen any earlier versions, they were not real. Not real, I tell | ||
1215 | 262 | you! Not real! They didn't exist! Really!) | ||
1216 | 0 | 263 | ||
1217 | === renamed file 'NEWS' => 'NEWS.moved' | |||
1218 | === added file 'README' | |||
1219 | --- README 1970-01-01 00:00:00 +0000 | |||
1220 | +++ README 2011-02-28 19:09:32 +0000 | |||
1221 | @@ -0,0 +1,31 @@ | |||
1222 | 1 | README for Computer Janitor | ||
1223 | 2 | =========================== | ||
1224 | 3 | |||
1225 | 4 | |||
1226 | 5 | Computer Janitor is a tool to clean up a system so that it is more like | ||
1227 | 6 | a freshly installed one. It was written for Ubuntu, but should be | ||
1228 | 7 | possible to port to other Unix-like operating systems. | ||
1229 | 8 | |||
1230 | 9 | |||
1231 | 10 | Copyright license | ||
1232 | 11 | ----------------- | ||
1233 | 12 | |||
1234 | 13 | Computer Janitor - clean up a computer system | ||
1235 | 14 | Copyright (C) 2008-2011 Canonical, Ltd. | ||
1236 | 15 | |||
1237 | 16 | The icon (in data/cruftremover-256x256.png and data/cruftremover-24x25.png): | ||
1238 | 17 | Copyright (C) Marco Rodrigues | ||
1239 | 18 | |||
1240 | 19 | The following license applies to all files (including the icons): | ||
1241 | 20 | |||
1242 | 21 | This program is free software: you can redistribute it and/or modify | ||
1243 | 22 | it under the terms of the GNU General Public License as published by | ||
1244 | 23 | the Free Software Foundation, version 3 of the License. | ||
1245 | 24 | |||
1246 | 25 | This program is distributed in the hope that it will be useful, | ||
1247 | 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1248 | 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1249 | 28 | GNU General Public License for more details. | ||
1250 | 29 | |||
1251 | 30 | You should have received a copy of the GNU General Public License | ||
1252 | 31 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1253 | 0 | 32 | ||
1254 | === renamed file 'README' => 'README.moved' | |||
1255 | === added file 'TODO' | |||
1256 | --- TODO 1970-01-01 00:00:00 +0000 | |||
1257 | +++ TODO 2011-02-28 19:09:32 +0000 | |||
1258 | @@ -0,0 +1,30 @@ | |||
1259 | 1 | Computer Janitor ideas | ||
1260 | 2 | |||
1261 | 3 | - policykit | ||
1262 | 4 | - aptdaemon backend | ||
1263 | 5 | - nx is disabled? | ||
1264 | 6 | - cronjob to run daily to report cruft | ||
1265 | 7 | - vrms plugin | ||
1266 | 8 | - plugin to suggest removing -generic kernel if more specific one | ||
1267 | 9 | is installed and running (-server, e.g.) | ||
1268 | 10 | - configuration mechanism for plugins | ||
1269 | 11 | - plugin to check for sources.list inconsistencies: $released-updates | ||
1270 | 12 | enabled for foo, if $released is enabled for foo (where foo is | ||
1271 | 13 | main, universe, etc) | ||
1272 | 14 | - UI improvement: group items so that previously ignored stuff is in a | ||
1273 | 15 | separate section of the list, and new stuff is at the top. | ||
1274 | 16 | - UI improvement: more information about a .deb: size, full | ||
1275 | 17 | description, when was it installed, which release did it come | ||
1276 | 18 | from | ||
1277 | 19 | - UI improvement: show sections based on type of cruft. e.g., .deb, fstab | ||
1278 | 20 | - add policykit support | ||
1279 | 21 | - cj: setup.py shouldn't hardcode version string, but should not | ||
1280 | 22 | import computerjanitorapp either, since that requires access | ||
1281 | 23 | to the computerjanitor package. | ||
1282 | 24 | - import computerjanitor.version? | ||
1283 | 25 | - write plugin: unpurged packages | ||
1284 | 26 | - kde UI | ||
1285 | 27 | - write plugin (early karmic): apt-get autoclean | ||
1286 | 28 | - relatime unnecessary in karmic? at least obey noatime, strictatime | ||
1287 | 29 | http://mjg59.livejournal.com/109286.html | ||
1288 | 30 | |||
1289 | 0 | 31 | ||
1290 | === renamed file 'TODO' => 'TODO.moved' | |||
1291 | === added file 'computer-janitor' | |||
1292 | --- computer-janitor 1970-01-01 00:00:00 +0000 | |||
1293 | +++ computer-janitor 2011-02-28 19:09:32 +0000 | |||
1294 | @@ -0,0 +1,41 @@ | |||
1295 | 1 | #!/usr/bin/python | ||
1296 | 2 | # | ||
1297 | 3 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
1298 | 4 | # | ||
1299 | 5 | # This program is free software: you can redistribute it and/or modify | ||
1300 | 6 | # it under the terms of the GNU General Public License as published by | ||
1301 | 7 | # the Free Software Foundation, version 3 of the License. | ||
1302 | 8 | # | ||
1303 | 9 | # This program is distributed in the hope that it will be useful, | ||
1304 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1305 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1306 | 12 | # GNU General Public License for more details. | ||
1307 | 13 | # | ||
1308 | 14 | # You should have received a copy of the GNU General Public License | ||
1309 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1310 | 16 | |||
1311 | 17 | """Start the command-line computer janitor.""" | ||
1312 | 18 | |||
1313 | 19 | from __future__ import absolute_import, unicode_literals | ||
1314 | 20 | |||
1315 | 21 | __metaclass__ = type | ||
1316 | 22 | __all__ = [ | ||
1317 | 23 | ] | ||
1318 | 24 | |||
1319 | 25 | |||
1320 | 26 | import sys | ||
1321 | 27 | |||
1322 | 28 | from computerjanitorapp import setup_gettext | ||
1323 | 29 | from computerjanitorapp.cli.main import main | ||
1324 | 30 | from dbus.exceptions import DBusException | ||
1325 | 31 | _ = setup_gettext() | ||
1326 | 32 | |||
1327 | 33 | |||
1328 | 34 | try: | ||
1329 | 35 | main() | ||
1330 | 36 | except KeyboardInterrupt: | ||
1331 | 37 | pass | ||
1332 | 38 | except DBusException as error: | ||
1333 | 39 | print >> sys.stderr, _( | ||
1334 | 40 | 'Cannot contact Computer Janitor dbus service; try again.') | ||
1335 | 41 | sys.exit(1) | ||
1336 | 0 | 42 | ||
1337 | === added file 'computer-janitor-gtk' | |||
1338 | --- computer-janitor-gtk 1970-01-01 00:00:00 +0000 | |||
1339 | +++ computer-janitor-gtk 2011-02-28 19:09:32 +0000 | |||
1340 | @@ -0,0 +1,68 @@ | |||
1341 | 1 | #!/usr/bin/python | ||
1342 | 2 | # | ||
1343 | 3 | # computer-janitor-gtk - clean up a Unix-like operating system (GTK version) | ||
1344 | 4 | # | ||
1345 | 5 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
1346 | 6 | # | ||
1347 | 7 | # This program is free software: you can redistribute it and/or modify | ||
1348 | 8 | # it under the terms of the GNU General Public License as published by | ||
1349 | 9 | # the Free Software Foundation, version 3 of the License. | ||
1350 | 10 | # | ||
1351 | 11 | # This program is distributed in the hope that it will be useful, | ||
1352 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1353 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1354 | 14 | # GNU General Public License for more details. | ||
1355 | 15 | # | ||
1356 | 16 | # You should have received a copy of the GNU General Public License | ||
1357 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1358 | 18 | |||
1359 | 19 | """Start the gtk computer janitor.""" | ||
1360 | 20 | |||
1361 | 21 | from __future__ import absolute_import, unicode_literals | ||
1362 | 22 | |||
1363 | 23 | __metaclass__ = type | ||
1364 | 24 | __all__ = [ | ||
1365 | 25 | ] | ||
1366 | 26 | |||
1367 | 27 | |||
1368 | 28 | import os | ||
1369 | 29 | import sys | ||
1370 | 30 | import logging | ||
1371 | 31 | import argparse | ||
1372 | 32 | import traceback | ||
1373 | 33 | import computerjanitor | ||
1374 | 34 | |||
1375 | 35 | from computerjanitorapp import __version__, setup_gettext | ||
1376 | 36 | from computerjanitorapp.gtk.main import main | ||
1377 | 37 | from dbus.exceptions import DBusException | ||
1378 | 38 | |||
1379 | 39 | _ = setup_gettext() | ||
1380 | 40 | |||
1381 | 41 | |||
1382 | 42 | # Parse some simple command line arguments. | ||
1383 | 43 | parser = argparse.ArgumentParser( | ||
1384 | 44 | description=_("""\ | ||
1385 | 45 | Find and remove cruft from your system. | ||
1386 | 46 | |||
1387 | 47 | Cruft is anything that shouldn't be on your system, but is. | ||
1388 | 48 | Stretching the definition, cruft is also things that should be on | ||
1389 | 49 | your system but aren't.""")) | ||
1390 | 50 | parser.add_argument( | ||
1391 | 51 | '--version', action='version', | ||
1392 | 52 | version=_('Computer Janitor {version}').format( | ||
1393 | 53 | version=__version__)) | ||
1394 | 54 | parser.parse_args() | ||
1395 | 55 | # If --version or --help is given, .parse_args() will not return. | ||
1396 | 56 | |||
1397 | 57 | try: | ||
1398 | 58 | logging.basicConfig() | ||
1399 | 59 | log = logging.getLogger('computerjanitor') | ||
1400 | 60 | main() | ||
1401 | 61 | except KeyboardInterrupt: | ||
1402 | 62 | pass | ||
1403 | 63 | except DBusException as error: | ||
1404 | 64 | log.exception('Cannot contact Computer Janitor dbus service; try again.') | ||
1405 | 65 | sys.exit(1) | ||
1406 | 66 | except: | ||
1407 | 67 | log.exception('computer-janitor-gtk uncaught exception') | ||
1408 | 68 | sys.exit(1) | ||
1409 | 0 | 69 | ||
1410 | === added file 'computer-janitor-gtk.8' | |||
1411 | --- computer-janitor-gtk.8 1970-01-01 00:00:00 +0000 | |||
1412 | +++ computer-janitor-gtk.8 2011-02-28 19:09:32 +0000 | |||
1413 | @@ -0,0 +1,36 @@ | |||
1414 | 1 | .\" Copyright (C) 2008-2011 Canonical, Ltd. | ||
1415 | 2 | .\" | ||
1416 | 3 | .\" This program is free software: you can redistribute it and/or modify | ||
1417 | 4 | .\" it under the terms of the GNU General Public License as published by | ||
1418 | 5 | .\" the Free Software Foundation, version 3 of the License. | ||
1419 | 6 | .\" | ||
1420 | 7 | .\" This program is distributed in the hope that it will be useful, | ||
1421 | 8 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1422 | 9 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1423 | 10 | .\" GNU General Public License for more details. | ||
1424 | 11 | .\" | ||
1425 | 12 | .\" You should have received a copy of the GNU General Public License | ||
1426 | 13 | .\" along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1427 | 14 | .TH COMPUTER-JANITOR-GTK 8 2011-02-16 Ubuntu "Ubuntu system administration" | ||
1428 | 15 | .SH NAME | ||
1429 | 16 | computer-janitor-gtk \- remove cruft from system (GUI version) | ||
1430 | 17 | .SH SYNOPSIS | ||
1431 | 18 | .B computer-janitor-gtk | ||
1432 | 19 | .SH DESCRIPTION | ||
1433 | 20 | .B computer-janitor-gtk | ||
1434 | 21 | is a version of | ||
1435 | 22 | .BR computer-janitor (8) | ||
1436 | 23 | with a graphical user interface. | ||
1437 | 24 | See the latter's manual page for more information. | ||
1438 | 25 | .SH ENVIRONMENT | ||
1439 | 26 | In addition to the environment variables understood by | ||
1440 | 27 | .BR computer-janitor (8), | ||
1441 | 28 | the following one is understood by | ||
1442 | 29 | .B computer-janitor-gtk | ||
1443 | 30 | as well. | ||
1444 | 31 | .TP | ||
1445 | 32 | .B COMPUTER_JANITOR_GLADE | ||
1446 | 33 | The location of the Glade data file to specify the user interface. | ||
1447 | 34 | You should not need to set this, unless you really know what you are doing. | ||
1448 | 35 | .SH "SEE ALSO" | ||
1449 | 36 | .BR computer-janitor (8). | ||
1450 | 0 | 37 | ||
1451 | === renamed file 'computer-janitor-gtk.8' => 'computer-janitor-gtk.8.moved' | |||
1452 | === renamed file 'computer-janitor-gtk' => 'computer-janitor-gtk.moved' | |||
1453 | === added file 'computer-janitor.8' | |||
1454 | --- computer-janitor.8 1970-01-01 00:00:00 +0000 | |||
1455 | +++ computer-janitor.8 2011-02-28 19:09:32 +0000 | |||
1456 | @@ -0,0 +1,222 @@ | |||
1457 | 1 | .\" Copyright (C) 2008-2011 Canonical, Ltd. | ||
1458 | 2 | .\" | ||
1459 | 3 | .\" This program is free software: you can redistribute it and/or modify | ||
1460 | 4 | .\" it under the terms of the GNU General Public License as published by | ||
1461 | 5 | .\" the Free Software Foundation, version 3 of the License. | ||
1462 | 6 | .\" | ||
1463 | 7 | .\" This program is distributed in the hope that it will be useful, | ||
1464 | 8 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1465 | 9 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1466 | 10 | .\" GNU General Public License for more details. | ||
1467 | 11 | .\" | ||
1468 | 12 | .\" You should have received a copy of the GNU General Public License | ||
1469 | 13 | .\" along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1470 | 14 | .TH COMPUTER-JANITOR 8 2011-02-16 Ubuntu "Ubuntu system administration" | ||
1471 | 15 | .SH NAME | ||
1472 | 16 | computer-janitor \- clean up a system installation | ||
1473 | 17 | .SH SYNOPSIS | ||
1474 | 18 | .B "computer-janitor" | ||
1475 | 19 | .RB [ --version|-h ] | ||
1476 | 20 | .br | ||
1477 | 21 | .B "computer-janitor find" | ||
1478 | 22 | .RB [ -i|-r|-s|-v|-h ] | ||
1479 | 23 | .RI | ||
1480 | 24 | .br | ||
1481 | 25 | .B "computer-janitor clean" | ||
1482 | 26 | .RB [ -a|-v|-h ] | ||
1483 | 27 | .RI [ CRUFT ]... | ||
1484 | 28 | .br | ||
1485 | 29 | .B "computer-janitor ignore" | ||
1486 | 30 | .RB [ -h ] | ||
1487 | 31 | .RI CRUFT | ||
1488 | 32 | .br | ||
1489 | 33 | .B "computer-janitor unignore" | ||
1490 | 34 | .RB [ -h ] | ||
1491 | 35 | .RI CRUFT | ||
1492 | 36 | .br | ||
1493 | 37 | .B computer-janitor-gtk | ||
1494 | 38 | .SH DESCRIPTION | ||
1495 | 39 | .B computer-janitor | ||
1496 | 40 | and | ||
1497 | 41 | .B computer-janitor-gtk | ||
1498 | 42 | find and remove | ||
1499 | 43 | .I cruft | ||
1500 | 44 | from your system. | ||
1501 | 45 | The former is a command line program, | ||
1502 | 46 | the latter has a graphical user interface. | ||
1503 | 47 | .PP | ||
1504 | 48 | Cruft is anything that shouldn't be on the system, but is. | ||
1505 | 49 | Stretching the definition, it is also things that should be on the system, | ||
1506 | 50 | but aren't. | ||
1507 | 51 | Examples: | ||
1508 | 52 | .IP \(bu | ||
1509 | 53 | Packages that were originally installed because something else depended on | ||
1510 | 54 | them, but the depending package has since been removed. | ||
1511 | 55 | Typically this includes large numbers of libraries. | ||
1512 | 56 | .IP \(bu | ||
1513 | 57 | Packages that are no longer supported by the current release of the | ||
1514 | 58 | operating system. | ||
1515 | 59 | For example, this can be applications whose development have stopped | ||
1516 | 60 | and that no longer have support, including for security issues. | ||
1517 | 61 | Keeping such applications installed can be dangerous. | ||
1518 | 62 | .IP \(bu | ||
1519 | 63 | Configuration tweaks that are missing from the system, | ||
1520 | 64 | but which would be there if the system was installed from scratch. | ||
1521 | 65 | For example, mount options for filesystems such as | ||
1522 | 66 | the | ||
1523 | 67 | .B relatime | ||
1524 | 68 | option. | ||
1525 | 69 | .PP | ||
1526 | 70 | .B computer-janitor | ||
1527 | 71 | has four modes of operation, invoked by the first non-option | ||
1528 | 72 | word in the argument list. | ||
1529 | 73 | .IP \(bu | ||
1530 | 74 | .B find | ||
1531 | 75 | searches for cruft and prints out a list of them. | ||
1532 | 76 | Each piece of cruft is also tagged with its state: | ||
1533 | 77 | .I ignored | ||
1534 | 78 | or | ||
1535 | 79 | .IR removable . | ||
1536 | 80 | .IP \(bu | ||
1537 | 81 | .B clean | ||
1538 | 82 | actually removes the cruft. | ||
1539 | 83 | It will remove those pieces of cruft you name on the command line. | ||
1540 | 84 | If you want to remove everything identified by | ||
1541 | 85 | .B find | ||
1542 | 86 | that is marked | ||
1543 | 87 | .IR removable , | ||
1544 | 88 | use the | ||
1545 | 89 | .B --all | ||
1546 | 90 | option. | ||
1547 | 91 | .IP \(bu | ||
1548 | 92 | .B ignore | ||
1549 | 93 | and | ||
1550 | 94 | .B unignore | ||
1551 | 95 | mark cruft as | ||
1552 | 96 | .I ignored | ||
1553 | 97 | or | ||
1554 | 98 | .IR removable , | ||
1555 | 99 | respectively. | ||
1556 | 100 | .SH OPTIONS | ||
1557 | 101 | Each subcommand listed above has its own set of options. If | ||
1558 | 102 | .B computer-janitor | ||
1559 | 103 | is invoked with no subcommand, the following options are available: | ||
1560 | 104 | .TP | ||
1561 | 105 | .B --version | ||
1562 | 106 | Print the version number and exit. | ||
1563 | 107 | .TP | ||
1564 | 108 | .BR --help | -h | ||
1565 | 109 | Print some global help and exit. | ||
1566 | 110 | .PP | ||
1567 | 111 | The | ||
1568 | 112 | .B find | ||
1569 | 113 | subcommand supports the following options: | ||
1570 | 114 | .TP | ||
1571 | 115 | .BR --ignored | -i | ||
1572 | 116 | Find and display only the system's ignored cruft. | ||
1573 | 117 | .TP | ||
1574 | 118 | .BR --removable | -r | ||
1575 | 119 | Find and display only the system's removable cruft. | ||
1576 | 120 | .TP | ||
1577 | 121 | .BR --short | -s | ||
1578 | 122 | Display only the cruft names; do not use with | ||
1579 | 123 | .BR --verbose . | ||
1580 | 124 | .TP | ||
1581 | 125 | .BR --verbose | -v | ||
1582 | 126 | Display a detailed explanation for each piece of cruft found. | ||
1583 | 127 | .TP | ||
1584 | 128 | .BR --help | -h | ||
1585 | 129 | Print detailed help for the | ||
1586 | 130 | .B find | ||
1587 | 131 | subcommand and exit. | ||
1588 | 132 | .PP | ||
1589 | 133 | The | ||
1590 | 134 | .B clean | ||
1591 | 135 | subcommand requires either a cruft name or the | ||
1592 | 136 | .B --all | ||
1593 | 137 | option to specify which cruft to remove. It supports the following options: | ||
1594 | 138 | .TP | ||
1595 | 139 | .B --all | -a | ||
1596 | 140 | Remove all system cruft that are not ignored. | ||
1597 | 141 | .TP | ||
1598 | 142 | .BR --verbose | -v | ||
1599 | 143 | Provide more details about the cruft being cleaned up. | ||
1600 | 144 | .TP | ||
1601 | 145 | .BR --help | -h | ||
1602 | 146 | Print detailed help for the | ||
1603 | 147 | .B clean | ||
1604 | 148 | subcommand and exit. | ||
1605 | 149 | .PP | ||
1606 | 150 | The | ||
1607 | 151 | .B ignore | ||
1608 | 152 | and | ||
1609 | 153 | .B unignore | ||
1610 | 154 | commands both take the name of a cruft to mark ignored or removable, | ||
1611 | 155 | respectively. They both also accept these options: | ||
1612 | 156 | .TP | ||
1613 | 157 | .BR --help | -h | ||
1614 | 158 | Print detailed help for the | ||
1615 | 159 | .B ignore | ||
1616 | 160 | or | ||
1617 | 161 | .B unignore | ||
1618 | 162 | subcommands and exit. | ||
1619 | 163 | .SH "EXIT STATUS" | ||
1620 | 164 | .B computer-janitor | ||
1621 | 165 | will return an exit code of 0 for successful operation (no errors). | ||
1622 | 166 | It will return a non-zero exit code if there are any errors. | ||
1623 | 167 | It is not an error to find cruft, or to not find cruft. | ||
1624 | 168 | .SH FILES | ||
1625 | 169 | .TP | ||
1626 | 170 | .B /var/lib/computer-janitor/state.dat | ||
1627 | 171 | This file stores the | ||
1628 | 172 | .I ignored | ||
1629 | 173 | or | ||
1630 | 174 | .I removable | ||
1631 | 175 | state of system cruft. Any cruft not listed in this file is by default | ||
1632 | 176 | .IR removable . | ||
1633 | 177 | .TP | ||
1634 | 178 | .B /etc/computer-janitor.d | ||
1635 | 179 | This directory contains whitelist files, which specify | ||
1636 | 180 | things that are never considered cruft. | ||
1637 | 181 | A whitelist file has a name that ends with | ||
1638 | 182 | .BR .whitelist , | ||
1639 | 183 | and contains one (potential) cruft name per line. | ||
1640 | 184 | (Empty lines and lines beginning with # are ignored.) | ||
1641 | 185 | .SH EXAMPLE | ||
1642 | 186 | To find all cruft on the system: | ||
1643 | 187 | .sp 1 | ||
1644 | 188 | .RS | ||
1645 | 189 | computer-janitor find | ||
1646 | 190 | .RE | ||
1647 | 191 | .PP | ||
1648 | 192 | To remove a specific piece of cruft: | ||
1649 | 193 | .sp 1 | ||
1650 | 194 | .RS | ||
1651 | 195 | computer-janitor clean hello | ||
1652 | 196 | .RE | ||
1653 | 197 | .PP | ||
1654 | 198 | To mark a piece of cruft as | ||
1655 | 199 | .IR ignored , | ||
1656 | 200 | so that it isn't removed by | ||
1657 | 201 | .B clean | ||
1658 | 202 | .BR --all : | ||
1659 | 203 | .sp 1 | ||
1660 | 204 | .RS | ||
1661 | 205 | computer-janitor ignore hello | ||
1662 | 206 | .RE | ||
1663 | 207 | .PP | ||
1664 | 208 | To mark a piece of cruft as | ||
1665 | 209 | .I removable | ||
1666 | 210 | again: | ||
1667 | 211 | .sp 1 | ||
1668 | 212 | .RS | ||
1669 | 213 | computer-janitor unignore hello | ||
1670 | 214 | .RE | ||
1671 | 215 | .PP | ||
1672 | 216 | To remove all cruft that isn't ignored: | ||
1673 | 217 | .sp 1 | ||
1674 | 218 | .RS | ||
1675 | 219 | computer-janitor clean --all | ||
1676 | 220 | .RE | ||
1677 | 221 | .SH "SEE ALSO" | ||
1678 | 222 | .BR computer-janitor-gtk (8). | ||
1679 | 0 | 223 | ||
1680 | === renamed file 'computer-janitor.8' => 'computer-janitor.8.moved' | |||
1681 | === renamed file 'computer-janitor' => 'computer-janitor.moved' | |||
1682 | === added directory 'computerjanitorapp' | |||
1683 | === renamed directory 'computerjanitorapp' => 'computerjanitorapp.moved' | |||
1684 | === added file 'computerjanitorapp/__init__.py' | |||
1685 | --- computerjanitorapp/__init__.py 1970-01-01 00:00:00 +0000 | |||
1686 | +++ computerjanitorapp/__init__.py 2011-02-28 19:09:32 +0000 | |||
1687 | @@ -0,0 +1,44 @@ | |||
1688 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
1689 | 2 | # | ||
1690 | 3 | # This program is free software: you can redistribute it and/or modify | ||
1691 | 4 | # it under the terms of the GNU General Public License as published by | ||
1692 | 5 | # the Free Software Foundation, version 3 of the License. | ||
1693 | 6 | # | ||
1694 | 7 | # This program is distributed in the hope that it will be useful, | ||
1695 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1696 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1697 | 10 | # GNU General Public License for more details. | ||
1698 | 11 | # | ||
1699 | 12 | # You should have received a copy of the GNU General Public License | ||
1700 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1701 | 14 | |||
1702 | 15 | """computerjanitorapp module.""" | ||
1703 | 16 | |||
1704 | 17 | from __future__ import absolute_import, unicode_literals | ||
1705 | 18 | |||
1706 | 19 | __metaclass__ = type | ||
1707 | 20 | __all__ = [ | ||
1708 | 21 | '__version__', | ||
1709 | 22 | 'setup_gettext', | ||
1710 | 23 | ] | ||
1711 | 24 | |||
1712 | 25 | |||
1713 | 26 | __version__ = '2.1.0' | ||
1714 | 27 | |||
1715 | 28 | |||
1716 | 29 | # Set up gettext. | ||
1717 | 30 | def setup_gettext(): | ||
1718 | 31 | """Set up gettext for a module. | ||
1719 | 32 | |||
1720 | 33 | Return a method to be used for looking up translations. Usage: | ||
1721 | 34 | |||
1722 | 35 | >>> import computerjanitorapp | ||
1723 | 36 | >>> _ = computerjanitorapp.setup_gettext() | ||
1724 | 37 | """ | ||
1725 | 38 | import gettext | ||
1726 | 39 | import os | ||
1727 | 40 | |||
1728 | 41 | domain = 'computerjanitor' | ||
1729 | 42 | localedir = os.environ.get('LOCPATH', None) | ||
1730 | 43 | t = gettext.translation(domain, localedir=localedir, fallback=True) | ||
1731 | 44 | return t.ugettext | ||
1732 | 0 | 45 | ||
1733 | === added directory 'computerjanitorapp/cli' | |||
1734 | === added file 'computerjanitorapp/cli/__init__.py' | |||
1735 | === added file 'computerjanitorapp/cli/main.py' | |||
1736 | --- computerjanitorapp/cli/main.py 1970-01-01 00:00:00 +0000 | |||
1737 | +++ computerjanitorapp/cli/main.py 2011-02-28 19:09:32 +0000 | |||
1738 | @@ -0,0 +1,312 @@ | |||
1739 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
1740 | 2 | # | ||
1741 | 3 | # This program is free software: you can redistribute it and/or modify | ||
1742 | 4 | # it under the terms of the GNU General Public License as published by | ||
1743 | 5 | # the Free Software Foundation, version 3 of the License. | ||
1744 | 6 | # | ||
1745 | 7 | # This program is distributed in the hope that it will be useful, | ||
1746 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1747 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1748 | 10 | # GNU General Public License for more details. | ||
1749 | 11 | # | ||
1750 | 12 | # You should have received a copy of the GNU General Public License | ||
1751 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1752 | 14 | |||
1753 | 15 | """Command line user interface.""" | ||
1754 | 16 | |||
1755 | 17 | from __future__ import absolute_import, unicode_literals | ||
1756 | 18 | |||
1757 | 19 | __metaclass__ = type | ||
1758 | 20 | __all__ = [ | ||
1759 | 21 | 'main', | ||
1760 | 22 | ] | ||
1761 | 23 | |||
1762 | 24 | |||
1763 | 25 | import sys | ||
1764 | 26 | import dbus | ||
1765 | 27 | import gobject | ||
1766 | 28 | import argparse | ||
1767 | 29 | import textwrap | ||
1768 | 30 | |||
1769 | 31 | from dbus.mainloop.glib import DBusGMainLoop | ||
1770 | 32 | from operator import mod | ||
1771 | 33 | |||
1772 | 34 | from computerjanitorapp import __version__, setup_gettext | ||
1773 | 35 | from computerjanitorapp.terminalsize import get_terminal_size | ||
1774 | 36 | from computerjanitorapp.utilities import format_size | ||
1775 | 37 | from computerjanitord.service import DBUS_INTERFACE_NAME | ||
1776 | 38 | _ = setup_gettext() | ||
1777 | 39 | |||
1778 | 40 | |||
1779 | 41 | class Options: | ||
1780 | 42 | """Command line option parser.""" | ||
1781 | 43 | def __init__(self, runner): | ||
1782 | 44 | """Parse the command line options. | ||
1783 | 45 | |||
1784 | 46 | :param runner: The class implementing the sub-commands. | ||
1785 | 47 | :type runner: `Runner` | ||
1786 | 48 | """ | ||
1787 | 49 | self.runner = runner | ||
1788 | 50 | # Parse the arguments. | ||
1789 | 51 | self.parser = argparse.ArgumentParser( | ||
1790 | 52 | description=_("""\ | ||
1791 | 53 | Find and remove cruft from your system. | ||
1792 | 54 | |||
1793 | 55 | Cruft is anything that shouldn't be on your system, but is. | ||
1794 | 56 | Stretching the definition, cruft is also things that should be on | ||
1795 | 57 | your system but aren't.""")) | ||
1796 | 58 | self.parser.add_argument( | ||
1797 | 59 | '--version', action='version', | ||
1798 | 60 | # XXX barry 2010-08-23: LP: #622720 | ||
1799 | 61 | version=mod(_('Computer Janitor %(version)s'), | ||
1800 | 62 | dict(version=__version__))) | ||
1801 | 63 | subparser = self.parser.add_subparsers(title='Commands') | ||
1802 | 64 | # The 'find' subcommand. | ||
1803 | 65 | command = subparser.add_parser( | ||
1804 | 66 | 'find', help=_('Find and display all cruft found on your system.')) | ||
1805 | 67 | command.add_argument( | ||
1806 | 68 | '-v', '--verbose', action='store_true', | ||
1807 | 69 | help=_("""\ | ||
1808 | 70 | Display a detailed explanation for each piece of cruft found.""")) | ||
1809 | 71 | command.add_argument( | ||
1810 | 72 | '-i', '--ignored', action='store_true', | ||
1811 | 73 | help=_('Find and display only the ignored cruft.')) | ||
1812 | 74 | command.add_argument( | ||
1813 | 75 | '-r', '--removable', action='store_true', | ||
1814 | 76 | help=_('Find and display only the removable cruft.')) | ||
1815 | 77 | command.add_argument( | ||
1816 | 78 | '-s', '--short', action='store_true', | ||
1817 | 79 | help=_('Display only the package names. Do not use with -v.')) | ||
1818 | 80 | command.set_defaults(func=self.runner.find) | ||
1819 | 81 | # The 'ignore' subcommand. | ||
1820 | 82 | command = subparser.add_parser( | ||
1821 | 83 | 'ignore', help=_("""\ | ||
1822 | 84 | Ignore a piece of cruft so that it is not cleaned up.""")) | ||
1823 | 85 | command.add_argument( | ||
1824 | 86 | 'cruft', nargs=1, | ||
1825 | 87 | help=_('The name of the cruft to ignore.')) | ||
1826 | 88 | command.set_defaults(func=self.runner.ignore) | ||
1827 | 89 | # The 'unignore' subcommand. | ||
1828 | 90 | command = subparser.add_parser( | ||
1829 | 91 | 'unignore', help=_("""\ | ||
1830 | 92 | Unignore a piece of cruft so that it will be cleaned up.""")) | ||
1831 | 93 | command.add_argument( | ||
1832 | 94 | 'cruft', nargs=1, | ||
1833 | 95 | help=_('The name of the cruft to unignore.')) | ||
1834 | 96 | command.set_defaults(func=self.runner.unignore) | ||
1835 | 97 | # The 'clean' subcommand. | ||
1836 | 98 | command = subparser.add_parser( | ||
1837 | 99 | 'clean', | ||
1838 | 100 | help=_('Remove the selected cruft from the system.')) | ||
1839 | 101 | command.add_argument( | ||
1840 | 102 | '-a', '--all', action='store_true', | ||
1841 | 103 | help=_('Clean up all unignored cruft.')) | ||
1842 | 104 | command.add_argument( | ||
1843 | 105 | '-v', '--verbose', action='store_true', | ||
1844 | 106 | help=_("Provide more details on what's being cleaned.")) | ||
1845 | 107 | command.add_argument( | ||
1846 | 108 | 'cruft', nargs='?', | ||
1847 | 109 | help=_("""\ | ||
1848 | 110 | The name of the cruft to clean up. Do not use if specifying | ||
1849 | 111 | --all.""")) | ||
1850 | 112 | command.set_defaults(func=self.runner.clean) | ||
1851 | 113 | # Parse the arguments and execute the subcommand. | ||
1852 | 114 | self.arguments = self.parser.parse_args() | ||
1853 | 115 | |||
1854 | 116 | |||
1855 | 117 | class Runner: | ||
1856 | 118 | """Implementations of subcommands.""" | ||
1857 | 119 | |||
1858 | 120 | def __init__(self): | ||
1859 | 121 | # Connect to the dbus service. | ||
1860 | 122 | system_bus = dbus.SystemBus() | ||
1861 | 123 | proxy = system_bus.get_object(DBUS_INTERFACE_NAME, '/') | ||
1862 | 124 | self.janitord = dbus.Interface( | ||
1863 | 125 | proxy, dbus_interface=DBUS_INTERFACE_NAME) | ||
1864 | 126 | # Connect to the signal the server will emit when cleaning up. | ||
1865 | 127 | self.janitord.connect_to_signal('cleanup_status', self._clean_working) | ||
1866 | 128 | # This will get backpatched by __main__. We need it to produce error | ||
1867 | 129 | # messages from the argparser. | ||
1868 | 130 | self.options = None | ||
1869 | 131 | # The main loop for asynchronous calls and signal reception. | ||
1870 | 132 | self.loop = gobject.MainLoop() | ||
1871 | 133 | |||
1872 | 134 | def _error(self, message): | ||
1873 | 135 | """Generate a parser error and exit. | ||
1874 | 136 | |||
1875 | 137 | :param message: The error message. | ||
1876 | 138 | :type message: string | ||
1877 | 139 | """ | ||
1878 | 140 | self.options.parser.error(message) | ||
1879 | 141 | # No return. | ||
1880 | 142 | |||
1881 | 143 | def find(self, arguments): | ||
1882 | 144 | """Find and display all cruft. | ||
1883 | 145 | |||
1884 | 146 | :param arguments: Command line options. | ||
1885 | 147 | """ | ||
1886 | 148 | # Cruft will be prefixed by 'removable' if it is not being ignored. | ||
1887 | 149 | ignored = set(self.janitord.ignored()) | ||
1888 | 150 | cruft_names = set(self.janitord.find()) | ||
1889 | 151 | # Filter names based on option flags. | ||
1890 | 152 | if arguments.ignored: | ||
1891 | 153 | cruft = sorted(cruft_names & ignored) | ||
1892 | 154 | elif arguments.removable: | ||
1893 | 155 | cruft = sorted(cruft_names - ignored) | ||
1894 | 156 | else: | ||
1895 | 157 | cruft = sorted(cruft_names) | ||
1896 | 158 | # The prefix will either be 'ignored' or 'removable' however this | ||
1897 | 159 | # string will be translated, so calculate the prefix size in the | ||
1898 | 160 | # native language, then add two columns of separator, followed by the | ||
1899 | 161 | # cruft name. | ||
1900 | 162 | prefixi = _('ignored') | ||
1901 | 163 | prefixr = _('removable') | ||
1902 | 164 | prefix_width = max(len(prefixi), len(prefixr)) | ||
1903 | 165 | # Long, short, shorter display. | ||
1904 | 166 | if arguments.verbose and arguments.short: | ||
1905 | 167 | self._error('Use either -s or -v but not both.') | ||
1906 | 168 | if arguments.short: | ||
1907 | 169 | # This is the shorter output. | ||
1908 | 170 | for name in cruft: | ||
1909 | 171 | print name | ||
1910 | 172 | elif not arguments.verbose: | ||
1911 | 173 | # This is the short output. | ||
1912 | 174 | for name in cruft: | ||
1913 | 175 | prefix = (prefixi if name in ignored else prefixr) | ||
1914 | 176 | # 10 spaces for the prefix | ||
1915 | 177 | print '{0:{1}} {2}'.format(prefix, prefix_width, name) | ||
1916 | 178 | else: | ||
1917 | 179 | # This is the verbose output. Start by getting the terminal's | ||
1918 | 180 | # size, though all we care about is the width. | ||
1919 | 181 | rows, columns = get_terminal_size() | ||
1920 | 182 | width = ((80 if columns in (None, 0) else columns) | ||
1921 | 183 | - prefix_width # space for prefix | ||
1922 | 184 | - 2 # separator | ||
1923 | 185 | - 1 # avoid last column, some terminals wrap | ||
1924 | 186 | ) | ||
1925 | 187 | margin = ' ' * (prefix_width + 2) | ||
1926 | 188 | for name in cruft: | ||
1927 | 189 | prefix = (prefixi if name in ignored else prefixr) | ||
1928 | 190 | # 10 spaces for the prefix | ||
1929 | 191 | print '{0:{1}} {2}'.format(prefix, prefix_width, name) | ||
1930 | 192 | # Print some details about the cruft. | ||
1931 | 193 | cruft_type, disk_usage = self.janitord.get_details(name) | ||
1932 | 194 | print '{0}{1} of type {2}'.format( | ||
1933 | 195 | margin, format_size(disk_usage), cruft_type) | ||
1934 | 196 | # Get the description, wrap it to the available columns, and | ||
1935 | 197 | # display it line-by-line with the proper amount of leading | ||
1936 | 198 | # spaces (prefix_width + 2). | ||
1937 | 199 | description = self.janitord.get_description(name) | ||
1938 | 200 | if len(description) == 0: | ||
1939 | 201 | |||
1940 | 202 | continue | ||
1941 | 203 | paragraphs = description.split('\n\n') | ||
1942 | 204 | for paragraph in paragraphs: | ||
1943 | 205 | for line in textwrap.wrap(paragraph, width): | ||
1944 | 206 | # 2010-02-09 barry: The original code forced the | ||
1945 | 207 | # output to utf-8, claiming that was necessary to | ||
1946 | 208 | # "write out stuff even when it's going to somewhere | ||
1947 | 209 | # like a pipe [...] ignor[ing] the user's desired | ||
1948 | 210 | # charset, which is bad, bad, bad...". This makes me | ||
1949 | 211 | # pretty uncomfortable, so I'd like to see a bug | ||
1950 | 212 | # report before I copy that from the previous | ||
1951 | 213 | # implementation. | ||
1952 | 214 | print '{0}{1}'.format(margin, line) | ||
1953 | 215 | # Paragraph separator. | ||
1954 | 216 | |||
1955 | 217 | |||
1956 | 218 | def ignore(self, arguments): | ||
1957 | 219 | """Ignore some cruft. | ||
1958 | 220 | |||
1959 | 221 | :param arguments: Command line options. | ||
1960 | 222 | """ | ||
1961 | 223 | assert len(arguments.cruft) == 1, 'Unexpected arguments' | ||
1962 | 224 | self.janitord.ignore(arguments.cruft[0]) | ||
1963 | 225 | self.janitord.save() | ||
1964 | 226 | |||
1965 | 227 | def unignore(self, arguments): | ||
1966 | 228 | """Unignore some cruft. | ||
1967 | 229 | |||
1968 | 230 | :param arguments: Command line options. | ||
1969 | 231 | """ | ||
1970 | 232 | assert len(arguments.cruft) == 1, 'Unexpected arguments' | ||
1971 | 233 | self.janitord.unignore(arguments.cruft[0]) | ||
1972 | 234 | self.janitord.save() | ||
1973 | 235 | |||
1974 | 236 | def _clean_reply(self): | ||
1975 | 237 | """The 'clean' operation has completed successfully.""" | ||
1976 | 238 | self.loop.quit() | ||
1977 | 239 | print 'done.' | ||
1978 | 240 | |||
1979 | 241 | def _clean_error(self, exception): | ||
1980 | 242 | """The 'clean' operation has failed.""" | ||
1981 | 243 | self.loop.quit() | ||
1982 | 244 | print 'dbus service error:', exception | ||
1983 | 245 | |||
1984 | 246 | def _clean_working(self, cruft): | ||
1985 | 247 | """The 'clean' operation is in progress. | ||
1986 | 248 | |||
1987 | 249 | :param cruft: The cruft that is being cleaned up. | ||
1988 | 250 | :type cruft: string | ||
1989 | 251 | """ | ||
1990 | 252 | verbose = self.options.arguments.verbose | ||
1991 | 253 | if cruft == '': | ||
1992 | 254 | # We're done. | ||
1993 | 255 | if not verbose: | ||
1994 | 256 | sys.stdout.write(' ') | ||
1995 | 257 | sys.stdout.flush() | ||
1996 | 258 | else: | ||
1997 | 259 | if verbose: | ||
1998 | 260 | print 'Working on', cruft | ||
1999 | 261 | else: | ||
2000 | 262 | sys.stdout.write('.') | ||
2001 | 263 | sys.stdout.flush() | ||
2002 | 264 | |||
2003 | 265 | def clean(self, arguments): | ||
2004 | 266 | """Clean up the cruft. | ||
2005 | 267 | |||
2006 | 268 | :param arguments: Command line options. | ||
2007 | 269 | """ | ||
2008 | 270 | if arguments.all: | ||
2009 | 271 | # You can't specify both --all and a cruft name. | ||
2010 | 272 | if arguments.cruft is not None: | ||
2011 | 273 | self._error('Specify a cruft name or --all, but not both') | ||
2012 | 274 | # No return. | ||
2013 | 275 | all_cruft = set(self.janitord.find()) | ||
2014 | 276 | ignored = set(self.janitord.ignored()) | ||
2015 | 277 | cleanable_cruft = tuple(all_cruft - ignored) | ||
2016 | 278 | else: | ||
2017 | 279 | if arguments.cruft is None: | ||
2018 | 280 | self._error('You must specify a cruft name, or use --all') | ||
2019 | 281 | # No return. | ||
2020 | 282 | cleanable_cruft = (arguments.cruft,) | ||
2021 | 283 | # Make the asynchronous call because this can take a long time. We'll | ||
2022 | 284 | # get status updates periodically. Note however that even though this | ||
2023 | 285 | # is asynchronous, dbus still expects a response within a certain | ||
2024 | 286 | # amount of time. We have no idea how long it will take to clean up | ||
2025 | 287 | # the cruft though, so just crank the timeout up to some insanely huge | ||
2026 | 288 | # number (of seconds). | ||
2027 | 289 | self.janitord.clean(cleanable_cruft, | ||
2028 | 290 | reply_handler=self._clean_reply, | ||
2029 | 291 | error_handler=self._clean_error, | ||
2030 | 292 | # If it takes longer than an hour, we're screwed. | ||
2031 | 293 | timeout=3600) | ||
2032 | 294 | # Start the main loop. This will exit when the remote operation is | ||
2033 | 295 | # complete. | ||
2034 | 296 | if not arguments.verbose: | ||
2035 | 297 | sys.stdout.write('processing') | ||
2036 | 298 | sys.stdout.flush() | ||
2037 | 299 | self.loop.run() | ||
2038 | 300 | |||
2039 | 301 | |||
2040 | 302 | def main(): | ||
2041 | 303 | # We'll need a main loop to receive status signals from the dbus service. | ||
2042 | 304 | # Don't start the main loop yet though, since we only need it for 'clean' | ||
2043 | 305 | # commands. | ||
2044 | 306 | DBusGMainLoop(set_as_default=True) | ||
2045 | 307 | runner = Runner() | ||
2046 | 308 | options = Options(runner) | ||
2047 | 309 | # Backpatch runner because of circular references. | ||
2048 | 310 | runner.options = options | ||
2049 | 311 | # Execute the subcommand. | ||
2050 | 312 | options.arguments.func(options.arguments) | ||
2051 | 0 | 313 | ||
2052 | === added directory 'computerjanitorapp/gtk' | |||
2053 | === added file 'computerjanitorapp/gtk/__init__.py' | |||
2054 | === added file 'computerjanitorapp/gtk/dialogs.py' | |||
2055 | --- computerjanitorapp/gtk/dialogs.py 1970-01-01 00:00:00 +0000 | |||
2056 | +++ computerjanitorapp/gtk/dialogs.py 2011-02-28 19:09:32 +0000 | |||
2057 | @@ -0,0 +1,125 @@ | |||
2058 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
2059 | 2 | # | ||
2060 | 3 | # This program is free software: you can redistribute it and/or modify | ||
2061 | 4 | # it under the terms of the GNU General Public License as published by | ||
2062 | 5 | # the Free Software Foundation, version 3 of the License. | ||
2063 | 6 | # | ||
2064 | 7 | # This program is distributed in the hope that it will be useful, | ||
2065 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2066 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2067 | 10 | # GNU General Public License for more details. | ||
2068 | 11 | # | ||
2069 | 12 | # You should have received a copy of the GNU General Public License | ||
2070 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2071 | 14 | |||
2072 | 15 | """Confirm some actions.""" | ||
2073 | 16 | |||
2074 | 17 | from __future__ import absolute_import, unicode_literals | ||
2075 | 18 | |||
2076 | 19 | __metaclass__ = type | ||
2077 | 20 | __all__ = [ | ||
2078 | 21 | 'AreYouSure', | ||
2079 | 22 | 'CleanupProblem', | ||
2080 | 23 | ] | ||
2081 | 24 | |||
2082 | 25 | |||
2083 | 26 | from computerjanitorapp import setup_gettext | ||
2084 | 27 | from gi.repository import Gtk | ||
2085 | 28 | from operator import mod as interpolate | ||
2086 | 29 | |||
2087 | 30 | |||
2088 | 31 | _ = setup_gettext() | ||
2089 | 32 | NL = '\n' | ||
2090 | 33 | |||
2091 | 34 | |||
2092 | 35 | class DialogBase: | ||
2093 | 36 | """Base class for dialogs.""" | ||
2094 | 37 | |||
2095 | 38 | def __init__(self, ui): | ||
2096 | 39 | self._ui = ui | ||
2097 | 40 | |||
2098 | 41 | |||
2099 | 42 | class AreYouSure(DialogBase): | ||
2100 | 43 | """Confirmation of destructive actions.""" | ||
2101 | 44 | |||
2102 | 45 | def verify(self): | ||
2103 | 46 | """Confirm package removal.""" | ||
2104 | 47 | # Start by getting all the active, non-ignored cruft. These are the | ||
2105 | 48 | # candidates for removal. | ||
2106 | 49 | cleanable_cruft = self._ui.get_cleanable_cruft() | ||
2107 | 50 | package_cruft_count = sum(1 for cruft_name, is_pkg in cleanable_cruft | ||
2108 | 51 | if is_pkg) | ||
2109 | 52 | other_cruft_count = len(cleanable_cruft) - package_cruft_count | ||
2110 | 53 | messages = [] | ||
2111 | 54 | ok_button = None | ||
2112 | 55 | # XXX vv barry 2010-08-23: LP: #622720 | ||
2113 | 56 | if package_cruft_count > 0: | ||
2114 | 57 | messages = [ | ||
2115 | 58 | _('<b>Software packages to remove: %(packages)s</b>.'), | ||
2116 | 59 | _('\nRemoving packages that are still in use can ' | ||
2117 | 60 | 'cause errors.'), | ||
2118 | 61 | ] | ||
2119 | 62 | ok_button = _('Remove packages') | ||
2120 | 63 | if other_cruft_count > 0: | ||
2121 | 64 | messages.insert(1, _('Non-package items to remove: %(others)s.')) | ||
2122 | 65 | ok_button = _('Clean up') | ||
2123 | 66 | secondary_message = interpolate(NL.join(messages), | ||
2124 | 67 | dict(packages=package_cruft_count, | ||
2125 | 68 | others=other_cruft_count)) | ||
2126 | 69 | # XXX ^^ barry 2010-08-23: LP: #622720 | ||
2127 | 70 | if ok_button is None: | ||
2128 | 71 | # The user de-selected all cruft from the ui, so there's actually | ||
2129 | 72 | # nothing to clean up. | ||
2130 | 73 | dialog = Gtk.MessageDialog( | ||
2131 | 74 | parent=self._ui.widgets['window'], | ||
2132 | 75 | type=Gtk.MessageType.WARNING, | ||
2133 | 76 | buttons=Gtk.ButtonsType.NONE, | ||
2134 | 77 | message_format=_('There is nothing to clean up'), | ||
2135 | 78 | ) | ||
2136 | 79 | dialog.set_title(_('Clean up')) | ||
2137 | 80 | dialog.add_button(_('Ok'), Gtk.ResponseType.YES) | ||
2138 | 81 | dialog.show_all() | ||
2139 | 82 | dialog.run() | ||
2140 | 83 | dialog.hide() | ||
2141 | 84 | return False | ||
2142 | 85 | # It would be nice if we could produce better messages than these, | ||
2143 | 86 | # but that would require a richer interface to the dbus service, | ||
2144 | 87 | # and probably to the cruft plugin architecture underneath that. | ||
2145 | 88 | message = _('Are you sure you want to clean your system?') | ||
2146 | 89 | dialog = Gtk.MessageDialog( | ||
2147 | 90 | parent=self._ui.widgets['window'], | ||
2148 | 91 | type=Gtk.MessageType.WARNING, | ||
2149 | 92 | buttons=Gtk.ButtonsType.NONE, | ||
2150 | 93 | message_format=message) | ||
2151 | 94 | dialog.set_title(_('Clean up')) | ||
2152 | 95 | dialog.format_secondary_markup(secondary_message) | ||
2153 | 96 | dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CLOSE) | ||
2154 | 97 | dialog.add_button(ok_button, Gtk.ResponseType.YES) | ||
2155 | 98 | # Show the dialog and get the user's response. | ||
2156 | 99 | dialog.show_all() | ||
2157 | 100 | response = dialog.run() | ||
2158 | 101 | dialog.hide() | ||
2159 | 102 | return response == Gtk.ResponseType.YES | ||
2160 | 103 | |||
2161 | 104 | |||
2162 | 105 | class CleanupProblem(DialogBase): | ||
2163 | 106 | """Some problem occurred during cleanup. | ||
2164 | 107 | |||
2165 | 108 | This is almost definitely caused by another package manager running at the | ||
2166 | 109 | same time. | ||
2167 | 110 | """ | ||
2168 | 111 | |||
2169 | 112 | def run(self): | ||
2170 | 113 | """Show the dialog and wait for confirmation.""" | ||
2171 | 114 | message = _('System clean up could not complete. ' | ||
2172 | 115 | 'Be sure no other package manager such as Synaptic or ' | ||
2173 | 116 | 'Update Manager is running.') | ||
2174 | 117 | dialog = Gtk.MessageDialog( | ||
2175 | 118 | parent=self._ui.widgets['window'], | ||
2176 | 119 | type=Gtk.MessageType.ERROR, | ||
2177 | 120 | buttons=Gtk.ButtonsType.OK, | ||
2178 | 121 | message_format=message) | ||
2179 | 122 | dialog.set_title(_('System clean up failure')) | ||
2180 | 123 | dialog.show_all() | ||
2181 | 124 | dialog.run() | ||
2182 | 125 | dialog.hide() | ||
2183 | 0 | 126 | ||
2184 | === added file 'computerjanitorapp/gtk/main.py' | |||
2185 | --- computerjanitorapp/gtk/main.py 1970-01-01 00:00:00 +0000 | |||
2186 | +++ computerjanitorapp/gtk/main.py 2011-02-28 19:09:32 +0000 | |||
2187 | @@ -0,0 +1,32 @@ | |||
2188 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
2189 | 2 | # | ||
2190 | 3 | # This program is free software: you can redistribute it and/or modify | ||
2191 | 4 | # it under the terms of the GNU General Public License as published by | ||
2192 | 5 | # the Free Software Foundation, version 3 of the License. | ||
2193 | 6 | # | ||
2194 | 7 | # This program is distributed in the hope that it will be useful, | ||
2195 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2196 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2197 | 10 | # GNU General Public License for more details. | ||
2198 | 11 | # | ||
2199 | 12 | # You should have received a copy of the GNU General Public License | ||
2200 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2201 | 14 | |||
2202 | 15 | """Command line user interface.""" | ||
2203 | 16 | |||
2204 | 17 | from __future__ import absolute_import, unicode_literals | ||
2205 | 18 | |||
2206 | 19 | __metaclass__ = type | ||
2207 | 20 | __all__ = [ | ||
2208 | 21 | 'main', | ||
2209 | 22 | ] | ||
2210 | 23 | |||
2211 | 24 | |||
2212 | 25 | from computerjanitorapp.gtk.ui import UserInterface | ||
2213 | 26 | from dbus.mainloop.glib import DBusGMainLoop | ||
2214 | 27 | |||
2215 | 28 | |||
2216 | 29 | def main(): | ||
2217 | 30 | DBusGMainLoop(set_as_default=True) | ||
2218 | 31 | ui = UserInterface() | ||
2219 | 32 | ui.run() | ||
2220 | 0 | 33 | ||
2221 | === added file 'computerjanitorapp/gtk/store.py' | |||
2222 | --- computerjanitorapp/gtk/store.py 1970-01-01 00:00:00 +0000 | |||
2223 | +++ computerjanitorapp/gtk/store.py 2011-02-28 19:09:32 +0000 | |||
2224 | @@ -0,0 +1,162 @@ | |||
2225 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
2226 | 2 | # | ||
2227 | 3 | # This program is free software: you can redistribute it and/or modify | ||
2228 | 4 | # it under the terms of the GNU General Public License as published by | ||
2229 | 5 | # the Free Software Foundation, version 3 of the License. | ||
2230 | 6 | # | ||
2231 | 7 | # This program is distributed in the hope that it will be useful, | ||
2232 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2233 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2234 | 10 | # GNU General Public License for more details. | ||
2235 | 11 | # | ||
2236 | 12 | # You should have received a copy of the GNU General Public License | ||
2237 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2238 | 14 | |||
2239 | 15 | """Gtk ListStore model for backing the TreeViews of cruft.""" | ||
2240 | 16 | |||
2241 | 17 | from __future__ import absolute_import, unicode_literals | ||
2242 | 18 | |||
2243 | 19 | __metaclass__ = type | ||
2244 | 20 | __all__ = [ | ||
2245 | 21 | 'Store', | ||
2246 | 22 | 'optimize', | ||
2247 | 23 | 'unused', | ||
2248 | 24 | ] | ||
2249 | 25 | |||
2250 | 26 | |||
2251 | 27 | import gobject | ||
2252 | 28 | |||
2253 | 29 | from gi.repository import Gtk | ||
2254 | 30 | |||
2255 | 31 | |||
2256 | 32 | # XXX 2010-03-04 barry: Use a munepy enum. | ||
2257 | 33 | class ListStoreColumns: | ||
2258 | 34 | # The cruft name as known by the dbus service. | ||
2259 | 35 | name = 0 | ||
2260 | 36 | # The short name of the cruft. | ||
2261 | 37 | short_name = 1 | ||
2262 | 38 | # The text displayed in the cell. | ||
2263 | 39 | text = 2 | ||
2264 | 40 | # Should the cruft be shown? | ||
2265 | 41 | show = 3 | ||
2266 | 42 | # Is the cruft active locally (i.e. toggle button is set)? | ||
2267 | 43 | active = 4 | ||
2268 | 44 | # Is the cruft being ignored in the dbus service? | ||
2269 | 45 | server_ignored = 5 | ||
2270 | 46 | # Is the cruft's description expanded? | ||
2271 | 47 | expanded = 6 | ||
2272 | 48 | # Is this cruft package cruft or some other kind of cruft? | ||
2273 | 49 | is_package_cruft = 7 | ||
2274 | 50 | |||
2275 | 51 | |||
2276 | 52 | class Store: | ||
2277 | 53 | """The higher level wrapper around the Gtk.ListStore.""" | ||
2278 | 54 | |||
2279 | 55 | def __init__(self, janitord): | ||
2280 | 56 | """Create the Store. | ||
2281 | 57 | |||
2282 | 58 | :param janitord: The `dbus.Interface` for talking to the Computer | ||
2283 | 59 | Janitor dbus service. | ||
2284 | 60 | """ | ||
2285 | 61 | self.janitord = janitord | ||
2286 | 62 | # This ListStore is the backing data structure for the TreeViews in | ||
2287 | 63 | # the main window. It holds information about the individual pieces | ||
2288 | 64 | # of cruft. See ListStoreColumns for details. | ||
2289 | 65 | # | ||
2290 | 66 | # XXX 2010-03-04 barry: pygtk does not like 'unicode'. | ||
2291 | 67 | self.store = Gtk.ListStore(str, str, str, bool, bool, bool, bool, bool) | ||
2292 | 68 | |||
2293 | 69 | def find_cruft(self): | ||
2294 | 70 | """Find cruft and populate the backing store. | ||
2295 | 71 | |||
2296 | 72 | This actually just asks the backend dbus service to find all the cruft | ||
2297 | 73 | asynchronously. When the dbus service completes the task, it sends a | ||
2298 | 74 | `find_finished` signal with the new list of cruft. Upon receipt of | ||
2299 | 75 | that signal, the ListStore is updated. | ||
2300 | 76 | """ | ||
2301 | 77 | self.janitord.connect_to_signal('find_finished', self.on_find_finished) | ||
2302 | 78 | self.janitord.find_async() | ||
2303 | 79 | |||
2304 | 80 | def on_find_finished(self, all_cruft_names): | ||
2305 | 81 | """dbus signal handler. | ||
2306 | 82 | |||
2307 | 83 | This actually updates the store with the new cruft results. | ||
2308 | 84 | """ | ||
2309 | 85 | ignored_cruft = set(self.janitord.ignored()) | ||
2310 | 86 | all_cruft_names = set(all_cruft_names); | ||
2311 | 87 | pkg_cruft_names = set( | ||
2312 | 88 | cruft_name for cruft_name in all_cruft_names | ||
2313 | 89 | if self.janitord.get_details(cruft_name)[0].lower() | ||
2314 | 90 | == 'packagecruft') | ||
2315 | 91 | self.store.clear() | ||
2316 | 92 | # Cruft always starts out in the active, not-expanded state. Package | ||
2317 | 93 | # cruft goes in the 'unused' column while non-package cruft goes in | ||
2318 | 94 | # the 'optimize' column. | ||
2319 | 95 | for cruft_name in all_cruft_names: | ||
2320 | 96 | cruft_shortname = self.janitord.get_shortname(cruft_name) | ||
2321 | 97 | self.store.append(( | ||
2322 | 98 | cruft_name, cruft_shortname, | ||
2323 | 99 | # What is being displayed in the cell. | ||
2324 | 100 | gobject.markup_escape_text(cruft_shortname), | ||
2325 | 101 | # Show the cruft be shown? | ||
2326 | 102 | cruft_name not in ignored_cruft, | ||
2327 | 103 | # Is the cruft active locally? | ||
2328 | 104 | cruft_name not in ignored_cruft, | ||
2329 | 105 | # Is the cruft ignored in the dbus service? | ||
2330 | 106 | cruft_name in ignored_cruft, | ||
2331 | 107 | # Is the cruft's description expanded? | ||
2332 | 108 | False, | ||
2333 | 109 | # Is this package cruft? | ||
2334 | 110 | cruft_name in pkg_cruft_names, | ||
2335 | 111 | )) | ||
2336 | 112 | |||
2337 | 113 | # Forwards to the underlying store, for convenience. Really, these should | ||
2338 | 114 | # use generic delegates, or clients should just use self.store.store. | ||
2339 | 115 | |||
2340 | 116 | def get_value(self, *args, **kws): | ||
2341 | 117 | return self.store.get_value(*args, **kws) | ||
2342 | 118 | |||
2343 | 119 | def set_value(self, *args, **kws): | ||
2344 | 120 | return self.store.set_value(*args, **kws) | ||
2345 | 121 | |||
2346 | 122 | def filter_new(self, *args, **kws): | ||
2347 | 123 | return self.store.filter_new(*args, **kws) | ||
2348 | 124 | |||
2349 | 125 | def foreach(self, *args, **kws): | ||
2350 | 126 | return self.store.foreach(*args, **kws) | ||
2351 | 127 | |||
2352 | 128 | def reorder(self, *args, **kws): | ||
2353 | 129 | return self.store.reorder(*args, **kws) | ||
2354 | 130 | |||
2355 | 131 | def get_iter_first(self, *args, **kws): | ||
2356 | 132 | return self.store.get_iter_first(*args, **kws) | ||
2357 | 133 | |||
2358 | 134 | def iter_next(self, *args, **kws): | ||
2359 | 135 | return self.store.iter_next(*args, **kws) | ||
2360 | 136 | |||
2361 | 137 | def clear(self, *args, **kws): | ||
2362 | 138 | return self.store.clear(*args, **kws) | ||
2363 | 139 | |||
2364 | 140 | |||
2365 | 141 | # Filter functions for use with TreeView column display. | ||
2366 | 142 | |||
2367 | 143 | def unused(store, iter, data): | ||
2368 | 144 | """True if the cruft is not being ignored and is package cruft. | ||
2369 | 145 | |||
2370 | 146 | :param store: The ListStore instance. | ||
2371 | 147 | :param iter: The TreeIter instance. | ||
2372 | 148 | """ | ||
2373 | 149 | show = store.get_value(iter, ListStoreColumns.show) | ||
2374 | 150 | is_package_cruft = store.get_value(iter, ListStoreColumns.is_package_cruft) | ||
2375 | 151 | return show and is_package_cruft | ||
2376 | 152 | |||
2377 | 153 | |||
2378 | 154 | def optimize(store, iter, data): | ||
2379 | 155 | """True if the cruft is not package cruft. | ||
2380 | 156 | |||
2381 | 157 | :param store: The ListStore instance. | ||
2382 | 158 | :param iter: The TreeIter instance. | ||
2383 | 159 | """ | ||
2384 | 160 | show = store.get_value(iter, ListStoreColumns.show) | ||
2385 | 161 | is_package_cruft = store.get_value(iter, ListStoreColumns.is_package_cruft) | ||
2386 | 162 | return show and not is_package_cruft | ||
2387 | 0 | 163 | ||
2388 | === added file 'computerjanitorapp/gtk/ui.py' | |||
2389 | --- computerjanitorapp/gtk/ui.py 1970-01-01 00:00:00 +0000 | |||
2390 | +++ computerjanitorapp/gtk/ui.py 2011-02-28 19:09:32 +0000 | |||
2391 | @@ -0,0 +1,594 @@ | |||
2392 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
2393 | 2 | # | ||
2394 | 3 | # This program is free software: you can redistribute it and/or modify | ||
2395 | 4 | # it under the terms of the GNU General Public License as published by | ||
2396 | 5 | # the Free Software Foundation, version 3 of the License. | ||
2397 | 6 | # | ||
2398 | 7 | # This program is distributed in the hope that it will be useful, | ||
2399 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2400 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2401 | 10 | # GNU General Public License for more details. | ||
2402 | 11 | # | ||
2403 | 12 | # You should have received a copy of the GNU General Public License | ||
2404 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2405 | 14 | |||
2406 | 15 | """Gtk user interface for computer janitor.""" | ||
2407 | 16 | |||
2408 | 17 | from __future__ import absolute_import, unicode_literals | ||
2409 | 18 | |||
2410 | 19 | __metaclass__ = type | ||
2411 | 20 | __all__ = [ | ||
2412 | 21 | 'UserInterface', | ||
2413 | 22 | ] | ||
2414 | 23 | |||
2415 | 24 | |||
2416 | 25 | import os | ||
2417 | 26 | import dbus | ||
2418 | 27 | import glib | ||
2419 | 28 | import gobject | ||
2420 | 29 | import logging | ||
2421 | 30 | |||
2422 | 31 | from operator import mod | ||
2423 | 32 | |||
2424 | 33 | from gi.repository import Gtk, Pango | ||
2425 | 34 | |||
2426 | 35 | from computerjanitorapp import __version__, setup_gettext | ||
2427 | 36 | from computerjanitorapp.gtk.dialogs import AreYouSure, CleanupProblem | ||
2428 | 37 | from computerjanitorapp.gtk.store import ( | ||
2429 | 38 | ListStoreColumns, Store, optimize, unused) | ||
2430 | 39 | from computerjanitorapp.utilities import format_size | ||
2431 | 40 | from computerjanitord.service import DBUS_INTERFACE_NAME | ||
2432 | 41 | |||
2433 | 42 | |||
2434 | 43 | Gtk.require_version('2.0') | ||
2435 | 44 | log = logging.getLogger('computerjanitor') | ||
2436 | 45 | _ = setup_gettext() | ||
2437 | 46 | |||
2438 | 47 | |||
2439 | 48 | GLADE = '/usr/share/computer-janitor/ComputerJanitor.ui' | ||
2440 | 49 | ROOT_WIDTH = 900 | ||
2441 | 50 | ROOT_HEIGHT = 500 | ||
2442 | 51 | NL = '\n' | ||
2443 | 52 | |||
2444 | 53 | # Keys are lower-cased cruft types, i.e. class name of cruft instances. | ||
2445 | 54 | ACTIONS = dict( | ||
2446 | 55 | packagecruft=_('Package will be <b>removed</b>.'), | ||
2447 | 56 | filecruft=_('Package will be <b>installed</b>.'), | ||
2448 | 57 | missingpackagecruft=_('File will be <b>removed</b>.'), | ||
2449 | 58 | ) | ||
2450 | 59 | |||
2451 | 60 | SENSITIVE_WIDGETS = ( | ||
2452 | 61 | 'do_button', | ||
2453 | 62 | 'optimize_treeview', | ||
2454 | 63 | 'quit_menuitem', | ||
2455 | 64 | 'show_previously_ignored', | ||
2456 | 65 | 'sort_by_name', | ||
2457 | 66 | 'sort_by_size', | ||
2458 | 67 | 'unused_treeview', | ||
2459 | 68 | ) | ||
2460 | 69 | |||
2461 | 70 | |||
2462 | 71 | class UserInterface: | ||
2463 | 72 | """Implementation of the Gtk user interface.""" | ||
2464 | 73 | |||
2465 | 74 | def __init__(self): | ||
2466 | 75 | # Connect to the dbus service. | ||
2467 | 76 | system_bus = dbus.SystemBus() | ||
2468 | 77 | proxy = system_bus.get_object(DBUS_INTERFACE_NAME, '/') | ||
2469 | 78 | self.janitord = dbus.Interface( | ||
2470 | 79 | proxy, dbus_interface=DBUS_INTERFACE_NAME) | ||
2471 | 80 | # Create the model on which the TreeViews will be based. | ||
2472 | 81 | self.store = Store(self.janitord) | ||
2473 | 82 | self.popup_menus = {} | ||
2474 | 83 | self.cruft_name_columns = set() | ||
2475 | 84 | # Sort by name by default. | ||
2476 | 85 | self._sort_key = self._by_name | ||
2477 | 86 | # Work is happening asynchronously on the dbus service. | ||
2478 | 87 | self.working = False | ||
2479 | 88 | # Connect to the signal the server will emit when cleaning up. | ||
2480 | 89 | self.janitord.connect_to_signal('cleanup_status', self._clean_working) | ||
2481 | 90 | |||
2482 | 91 | def run(self): | ||
2483 | 92 | """Set up the widgets and run the main loop.""" | ||
2484 | 93 | builder = Gtk.Builder() | ||
2485 | 94 | builder.set_translation_domain('computerjanitor') | ||
2486 | 95 | # Load the glade ui file, which can be overridden from the environment | ||
2487 | 96 | # for testing purposes. | ||
2488 | 97 | glade_file = os.environ.get('COMPUTER_JANITOR_GLADE', GLADE) | ||
2489 | 98 | builder.add_from_file(glade_file) | ||
2490 | 99 | # Bind widgets to callbacks. Initialize the Do... button to | ||
2491 | 100 | # insensitive, but possibly toggle it back to sensitive if we find | ||
2492 | 101 | # cruft. | ||
2493 | 102 | self.find_and_bind_widgets(builder) | ||
2494 | 103 | self.widgets['do_button'].set_sensitive(False) | ||
2495 | 104 | self.janitord.connect_to_signal('find_finished', self._find_finished) | ||
2496 | 105 | # Do the initial search for cruft and set up the TreeView model. | ||
2497 | 106 | self.store.find_cruft() | ||
2498 | 107 | self.sort_cruft() | ||
2499 | 108 | # Now hook the TreeViews up to there view of the model. | ||
2500 | 109 | self.create_column('unused_treeview', unused) | ||
2501 | 110 | self.create_column('optimize_treeview', optimize) | ||
2502 | 111 | # Set the dimensions of the root window. | ||
2503 | 112 | root = self.widgets['window'] | ||
2504 | 113 | root.set_default_size(ROOT_WIDTH, ROOT_HEIGHT) | ||
2505 | 114 | # Map the root window and go! | ||
2506 | 115 | root.show() | ||
2507 | 116 | Gtk.main() | ||
2508 | 117 | |||
2509 | 118 | def find_and_bind_widgets(self, builder): | ||
2510 | 119 | """Bind widgets and callbacks.""" | ||
2511 | 120 | # Start by extracting all the bindable widgets from the ui builder, | ||
2512 | 121 | # keeping track of them as mapped to their name. | ||
2513 | 122 | self.widgets = {} | ||
2514 | 123 | for ui_object in builder.get_objects(): | ||
2515 | 124 | if issubclass(type(ui_object), Gtk.Buildable): | ||
2516 | 125 | widget_name = Gtk.Buildable.get_name(ui_object) | ||
2517 | 126 | self.widgets[widget_name] = ui_object | ||
2518 | 127 | # Search through the attributes of this instance looking for | ||
2519 | 128 | # callbacks for this widget. We use the naming convention | ||
2520 | 129 | # 'on_<widget>_<signal>' for such methods. Both the widget | ||
2521 | 130 | # name and signal (or event) can contain underscores. Connect | ||
2522 | 131 | # the widget to the callback. | ||
2523 | 132 | prefix = 'on_{0}_'.format(widget_name) | ||
2524 | 133 | for method_name in dir(self): | ||
2525 | 134 | if method_name.startswith(prefix): | ||
2526 | 135 | signal_name = method_name[len(prefix):] | ||
2527 | 136 | ui_object.connect( | ||
2528 | 137 | signal_name, getattr(self, method_name)) | ||
2529 | 138 | |||
2530 | 139 | def create_column(self, widget_name, filter_func): | ||
2531 | 140 | """Set up a column in the named TreeView.""" | ||
2532 | 141 | treeview = self.widgets[widget_name] | ||
2533 | 142 | # XXX 2010-03-04 barry: This is a bit of an abuse because it's | ||
2534 | 143 | # supposed to specify whether users are to read across the rows. As a | ||
2535 | 144 | # side effect it renders the columns with alternating row colors, but | ||
2536 | 145 | # that's not it's primary function. | ||
2537 | 146 | treeview.set_rules_hint(True) | ||
2538 | 147 | # Each TreeView contains two columns. The leftmost one is a toggle | ||
2539 | 148 | # that when select tells c-j to act on that cruft. Deselecting the | ||
2540 | 149 | # toggle ignores the package for next time. | ||
2541 | 150 | toggle_cr = Gtk.CellRendererToggle() | ||
2542 | 151 | toggle_cr.connect('toggled', self._toggled, treeview) | ||
2543 | 152 | toggle_cr.set_property('yalign', 0) | ||
2544 | 153 | toggle_col = Gtk.TreeViewColumn() | ||
2545 | 154 | toggle_col.pack_start(toggle_cr, True) | ||
2546 | 155 | toggle_col.add_attribute(toggle_cr, 'active', ListStoreColumns.active) | ||
2547 | 156 | treeview.append_column(toggle_col) | ||
2548 | 157 | # The rightmost column contains the details of the cruft. It will | ||
2549 | 158 | # always contain the cruft name and can be expanded to display cruft | ||
2550 | 159 | # details. Tell the column to get its toggle's active state from the | ||
2551 | 160 | # model. | ||
2552 | 161 | name_cr = Gtk.CellRendererText() | ||
2553 | 162 | name_cr.set_property('yalign', 0) | ||
2554 | 163 | name_cr.set_property('wrap-mode', Pango.WrapMode.WORD) | ||
2555 | 164 | name_col = Gtk.TreeViewColumn() | ||
2556 | 165 | name_col.pack_start(name_cr, True) | ||
2557 | 166 | name_col.add_attribute(name_cr, 'markup', ListStoreColumns.text) | ||
2558 | 167 | treeview.append_column(name_col) | ||
2559 | 168 | self.cruft_name_columns.add(name_col) | ||
2560 | 169 | # The individual crufts may or may not be visible in this TreeView. | ||
2561 | 170 | # It's the filter function that controls this, so set that now. | ||
2562 | 171 | filter_store = self.store.filter_new(None) | ||
2563 | 172 | filter_store.set_visible_func(filter_func, None) | ||
2564 | 173 | treeview.set_model(filter_store) | ||
2565 | 174 | # Each TreeView has a popup menu for select or deselecting all visible | ||
2566 | 175 | # cruft. | ||
2567 | 176 | self.create_popup_menu_for_treeview(treeview) | ||
2568 | 177 | |||
2569 | 178 | def create_popup_menu_for_treeview(self, treeview): | ||
2570 | 179 | """The tree views have a popup menu to select/deselect everything. | ||
2571 | 180 | |||
2572 | 181 | :param treeview: The `TreeView` to attach the menu to. | ||
2573 | 182 | """ | ||
2574 | 183 | select_all = Gtk.MenuItem(label='Select all') | ||
2575 | 184 | select_all.connect('activate', self.popup_menu_select_all, treeview) | ||
2576 | 185 | unselect_all = Gtk.MenuItem(label='Unselect all') | ||
2577 | 186 | unselect_all.connect('activate', | ||
2578 | 187 | self.popup_menu_unselect_all, treeview) | ||
2579 | 188 | menu = Gtk.Menu() | ||
2580 | 189 | menu.append(select_all) | ||
2581 | 190 | menu.append(unselect_all) | ||
2582 | 191 | menu.show_all() | ||
2583 | 192 | self.popup_menus[treeview] = menu | ||
2584 | 193 | |||
2585 | 194 | def _by_name(self, cruft_name): | ||
2586 | 195 | """Sort by cruft name.""" | ||
2587 | 196 | return cruft_name | ||
2588 | 197 | |||
2589 | 198 | def _by_size(self, cruft_name): | ||
2590 | 199 | """Sort by cruft size, from largest to smallest.""" | ||
2591 | 200 | # Return negative size to sort from largest to smallest. | ||
2592 | 201 | return -self.janitord.get_details(cruft_name)[1] | ||
2593 | 202 | |||
2594 | 203 | def sort_cruft(self): | ||
2595 | 204 | """Sort the cruft displays, either by name or size.""" | ||
2596 | 205 | # The way reordering (not technically 'sorting') works in gtk is that | ||
2597 | 206 | # you give a list of integer indexes to the the ListStore. These | ||
2598 | 207 | # indexes are in sorted order, and refer to the pre-sort indexes of | ||
2599 | 208 | # the items in the store. IOW, the ListStore knows that if the first | ||
2600 | 209 | # integer in the list is 7, it will move the 7th item to the top. | ||
2601 | 210 | # | ||
2602 | 211 | # Start by getting the indexes and names of the currenly sorted cruft. | ||
2603 | 212 | # We'll fill this list with 2-tuples of the format: | ||
2604 | 213 | # (sort-key, current-index). | ||
2605 | 214 | cruft_data = [] | ||
2606 | 215 | def get(model, path, iter, crufts): | ||
2607 | 216 | cruft_name = model.get_value(iter, ListStoreColumns.name) | ||
2608 | 217 | crufts.append((self._sort_key(cruft_name), len(crufts))) | ||
2609 | 218 | # Continue iterating. | ||
2610 | 219 | return False | ||
2611 | 220 | self.store.foreach(get, cruft_data) | ||
2612 | 221 | cruft_data.sort() | ||
2613 | 222 | cruft_indexes = [index for key, index in cruft_data] | ||
2614 | 223 | # No need to do anything if there is no cruft. | ||
2615 | 224 | if len(cruft_indexes) > 0: | ||
2616 | 225 | self.store.reorder(cruft_indexes) | ||
2617 | 226 | |||
2618 | 227 | def get_cleanable_cruft(self): | ||
2619 | 228 | """Return the list of cleanable cruft candidates. | ||
2620 | 229 | |||
2621 | 230 | :return: List of cleanable cruft. | ||
2622 | 231 | :rtype: list of 2-tuples of (cruft_name, is_package_cruft) | ||
2623 | 232 | """ | ||
2624 | 233 | cleanable_cruft = [] | ||
2625 | 234 | def collect(model, path, iter, crufts): | ||
2626 | 235 | # Only clean up active cruft, i.e. those that are specifically | ||
2627 | 236 | # checked as ready for cleaning. | ||
2628 | 237 | cruft_active = model.get_value(iter, ListStoreColumns.active) | ||
2629 | 238 | if cruft_active: | ||
2630 | 239 | cruft_name = model.get_value(iter, ListStoreColumns.name) | ||
2631 | 240 | cruft_is_package_cruft = model.get_value( | ||
2632 | 241 | iter, ListStoreColumns.is_package_cruft) | ||
2633 | 242 | crufts.append((cruft_name, cruft_is_package_cruft)) | ||
2634 | 243 | # Continue iterating. | ||
2635 | 244 | return False | ||
2636 | 245 | self.store.foreach(collect, cleanable_cruft) | ||
2637 | 246 | return cleanable_cruft | ||
2638 | 247 | |||
2639 | 248 | def toggle_long_description(self, treeview): | ||
2640 | 249 | """Toggle the currently selected cruft's long description. | ||
2641 | 250 | |||
2642 | 251 | :param treeview: The TreeView | ||
2643 | 252 | """ | ||
2644 | 253 | selection = treeview.get_selection() | ||
2645 | 254 | filter_model, selected = selection.get_selected() | ||
2646 | 255 | if not selected: | ||
2647 | 256 | return | ||
2648 | 257 | model = filter_model.get_model() | ||
2649 | 258 | iter = filter_model.convert_iter_to_child_iter(selected) | ||
2650 | 259 | cruft_name = model.get_value(iter, ListStoreColumns.name) | ||
2651 | 260 | expanded = model.get_value(iter, ListStoreColumns.expanded) | ||
2652 | 261 | shortname = model.get_value(iter, ListStoreColumns.short_name) | ||
2653 | 262 | if expanded: | ||
2654 | 263 | # Collapse it. | ||
2655 | 264 | value = gobject.markup_escape_text(shortname) | ||
2656 | 265 | else: | ||
2657 | 266 | cruft_type, size = self.janitord.get_details(cruft_name) | ||
2658 | 267 | lines = [gobject.markup_escape_text(shortname)] | ||
2659 | 268 | action = ACTIONS.get(cruft_type.lower()) | ||
2660 | 269 | if action is not None: | ||
2661 | 270 | lines.append(action) | ||
2662 | 271 | # XXX barry 2010-08-23: LP: #622720 | ||
2663 | 272 | lines.append(mod(_('Size: %(bytes)s'), | ||
2664 | 273 | dict(bytes=format_size(size)))) | ||
2665 | 274 | lines.append('') | ||
2666 | 275 | description = self.janitord.get_description(cruft_name) | ||
2667 | 276 | lines.append(gobject.markup_escape_text(description)) | ||
2668 | 277 | value = NL.join(lines) | ||
2669 | 278 | model.set_value(iter, ListStoreColumns.text, value) | ||
2670 | 279 | model.set_value(iter, ListStoreColumns.expanded, not expanded) | ||
2671 | 280 | |||
2672 | 281 | def desensitize(self): | ||
2673 | 282 | """Make certain ui elements insensitive during work.""" | ||
2674 | 283 | for widget in SENSITIVE_WIDGETS: | ||
2675 | 284 | self.widgets[widget].set_sensitive(False) | ||
2676 | 285 | |||
2677 | 286 | def sensitize(self): | ||
2678 | 287 | """Make certain ui elements sensitive after work.""" | ||
2679 | 288 | for widget in SENSITIVE_WIDGETS: | ||
2680 | 289 | self.widgets[widget].set_sensitive(True) | ||
2681 | 290 | |||
2682 | 291 | def _find_finished(self, all_cruft_names): | ||
2683 | 292 | """dbus signal handler.""" | ||
2684 | 293 | self.widgets['do_button'].set_sensitive(len(all_cruft_names) > 0) | ||
2685 | 294 | |||
2686 | 295 | # Popup menu support. | ||
2687 | 296 | |||
2688 | 297 | def _treeview_foreach_set_set_state(self, treeview, enabled): | ||
2689 | 298 | """Set the state of the cruft 'active' flag for all cruft. | ||
2690 | 299 | |||
2691 | 300 | :param treeview: The `TreeView` to set cruft state on. | ||
2692 | 301 | :param enabled: The new state flag for all cruft. True means enabled. | ||
2693 | 302 | :type enabled: bool | ||
2694 | 303 | """ | ||
2695 | 304 | def set_state(model, path, iter, user_data): | ||
2696 | 305 | # Set the state on an individual piece of cruft. Start by | ||
2697 | 306 | # changing the state of the cruft on the dbus service. | ||
2698 | 307 | child_iter = model.convert_iter_to_child_iter(iter) | ||
2699 | 308 | cruft_name = self.store.get_value( | ||
2700 | 309 | child_iter, ListStoreColumns.name) | ||
2701 | 310 | if enabled: | ||
2702 | 311 | self.janitord.unignore(cruft_name) | ||
2703 | 312 | else: | ||
2704 | 313 | self.janitord.ignore(cruft_name) | ||
2705 | 314 | # Now set the active state in the model. | ||
2706 | 315 | self.store.set_value(child_iter, ListStoreColumns.active, enabled) | ||
2707 | 316 | treeview.get_model().foreach(set_state, None) | ||
2708 | 317 | # Save the updated state on the dbus service. | ||
2709 | 318 | self.janitord.save() | ||
2710 | 319 | |||
2711 | 320 | def popup_menu_select_all(self, menuitem, treeview): | ||
2712 | 321 | self._treeview_foreach_set_set_state(treeview, True) | ||
2713 | 322 | |||
2714 | 323 | def popup_menu_unselect_all(self, menuitem, treeview): | ||
2715 | 324 | self._treeview_foreach_set_set_state(treeview, False) | ||
2716 | 325 | |||
2717 | 326 | # Progress bar | ||
2718 | 327 | |||
2719 | 328 | def pulse(self): | ||
2720 | 329 | """Progress bar callback, showing that something is happening.""" | ||
2721 | 330 | progress = self.widgets['progressbar_status'] | ||
2722 | 331 | if self.working: | ||
2723 | 332 | progress.show() | ||
2724 | 333 | progress.pulse() | ||
2725 | 334 | return True | ||
2726 | 335 | else: | ||
2727 | 336 | # All done. Hide the progress bar, make the ui elements sensitive | ||
2728 | 337 | # again, update the store, and kill the timer. | ||
2729 | 338 | progress.hide() | ||
2730 | 339 | self.store.clear() | ||
2731 | 340 | self.store.find_cruft() | ||
2732 | 341 | self.sensitize() | ||
2733 | 342 | return False | ||
2734 | 343 | |||
2735 | 344 | def _clean_working(self, cruft): | ||
2736 | 345 | """dbus signal handler; the 'clean' operation is in progress. | ||
2737 | 346 | |||
2738 | 347 | :param done: The cruft that is being cleaned up. | ||
2739 | 348 | :type done: string | ||
2740 | 349 | """ | ||
2741 | 350 | # Just mark the status here. The progress bar pulsar will handle | ||
2742 | 351 | # doing the actual work. | ||
2743 | 352 | self.working = (cruft != '') | ||
2744 | 353 | if self.working: | ||
2745 | 354 | self.widgets['progressbar_status'].set_text( | ||
2746 | 355 | # XXX barry 2010-08-23: LP: #622720 | ||
2747 | 356 | mod(_('Processing %(cruft)s'), dict(cruft=cruft))) | ||
2748 | 357 | |||
2749 | 358 | # Callbacks | ||
2750 | 359 | |||
2751 | 360 | def _toggled(self, widget, path, treeview): | ||
2752 | 361 | """Handle the toggle button in a TreeView cell. | ||
2753 | 362 | |||
2754 | 363 | :param widget: The CellRendererToggle | ||
2755 | 364 | :param path: The cell's path. | ||
2756 | 365 | :param treeview: The TreeView | ||
2757 | 366 | """ | ||
2758 | 367 | # Find out which cruft's toggle was clicked. | ||
2759 | 368 | model = treeview.get_model() | ||
2760 | 369 | filter_iter = model.get_iter(path) | ||
2761 | 370 | child_iter = model.convert_iter_to_child_iter(filter_iter) | ||
2762 | 371 | cruft_name = self.store.get_value(child_iter, ListStoreColumns.name) | ||
2763 | 372 | state = self.store.get_value(child_iter, ListStoreColumns.active) | ||
2764 | 373 | # Toggle the current state. | ||
2765 | 374 | new_state = not state | ||
2766 | 375 | if new_state: | ||
2767 | 376 | self.janitord.unignore(cruft_name) | ||
2768 | 377 | else: | ||
2769 | 378 | self.janitord.ignore(cruft_name) | ||
2770 | 379 | self.store.set_value(child_iter, ListStoreColumns.active, new_state) | ||
2771 | 380 | self.store.set_value( | ||
2772 | 381 | child_iter, ListStoreColumns.server_ignored, not new_state) | ||
2773 | 382 | # Save the new ignored state on the dbus service. | ||
2774 | 383 | self.janitord.save() | ||
2775 | 384 | |||
2776 | 385 | # Signal and event handlers. | ||
2777 | 386 | |||
2778 | 387 | def on_quit_menuitem_activate(self, *args): | ||
2779 | 388 | """Signal and event handlers for quitting. | ||
2780 | 389 | |||
2781 | 390 | Since we just want things to go away, we don't really care about the | ||
2782 | 391 | arguments. Just tell the main loop to exit. | ||
2783 | 392 | """ | ||
2784 | 393 | # Don't quit while we're working. | ||
2785 | 394 | if self.working: | ||
2786 | 395 | return True | ||
2787 | 396 | Gtk.main_quit() | ||
2788 | 397 | |||
2789 | 398 | on_window_delete_event = on_quit_menuitem_activate | ||
2790 | 399 | |||
2791 | 400 | def treeview_button_press_event(self, treeview, event): | ||
2792 | 401 | """Handle mouse button press events on the TreeView ourselves. | ||
2793 | 402 | |||
2794 | 403 | We handle mouse button presses ourselves so that we can either | ||
2795 | 404 | toggle the long description (button 1, typically left) or | ||
2796 | 405 | pop up a menu (button 3, typically right). | ||
2797 | 406 | """ | ||
2798 | 407 | # Original comment: This is slightly tricky and probably a source of | ||
2799 | 408 | # bugs. Oh well. | ||
2800 | 409 | if event.button.button == 1: | ||
2801 | 410 | # Left button event. Select the row being clicked on. If the | ||
2802 | 411 | # click is on the cruft name, show or hide its long description. | ||
2803 | 412 | # If the click the click is elsewhere do not handle it. This | ||
2804 | 413 | # allows the toggle button event to be handled separately. | ||
2805 | 414 | x = int(event.x) | ||
2806 | 415 | y = int(event.y) | ||
2807 | 416 | time = event.time | ||
2808 | 417 | pathinfo = treeview.get_path_at_pos(x, y) | ||
2809 | 418 | if pathinfo is None: | ||
2810 | 419 | # The click was not in a cell, but we've handled it anyway. | ||
2811 | 420 | return True | ||
2812 | 421 | path, column, cell_x, cell_y = pathinfo | ||
2813 | 422 | if column in self.cruft_name_columns: | ||
2814 | 423 | treeview.set_cursor(path, column, False) | ||
2815 | 424 | self.toggle_long_description(treeview) | ||
2816 | 425 | return True | ||
2817 | 426 | else: | ||
2818 | 427 | # We are not handling this event so that the toggle button | ||
2819 | 428 | # handling can occur. | ||
2820 | 429 | return False | ||
2821 | 430 | elif event.button.button == 3: | ||
2822 | 431 | # Right button event. Pop up the select/deselect all menu. | ||
2823 | 432 | treeview.grab_focus() | ||
2824 | 433 | x = int(event.x) | ||
2825 | 434 | y = int(event.y) | ||
2826 | 435 | time = event.time | ||
2827 | 436 | pathinfo = treeview.get_path_at_pos(x, y) | ||
2828 | 437 | if pathinfo is not None: | ||
2829 | 438 | path, column, cell_x, cell_y = pathinfo | ||
2830 | 439 | treeview.set_cursor(path, column, False) | ||
2831 | 440 | menu = self.popup_menus[treeview] | ||
2832 | 441 | try: | ||
2833 | 442 | menu.popup_for_device(None, None, None, None, None, | ||
2834 | 443 | event.button.button, time) | ||
2835 | 444 | except AttributeError: | ||
2836 | 445 | # popup_for_device() is introspection safe, but only exists in | ||
2837 | 446 | # GTK3. popup() isn't introspectable, so in GTK 2 we need to | ||
2838 | 447 | # disable the popup menu functionality | ||
2839 | 448 | log.warning('popup menu not supported when using GTK2') | ||
2840 | 449 | return True | ||
2841 | 450 | else: | ||
2842 | 451 | # No other events are handled by us. | ||
2843 | 452 | return False | ||
2844 | 453 | |||
2845 | 454 | # The actual event handler is totally generic. Alias it to names | ||
2846 | 455 | # recognized by the automatic event binding scheme. | ||
2847 | 456 | on_unused_treeview_button_press_event = treeview_button_press_event | ||
2848 | 457 | on_optimize_treeview_button_press_event = treeview_button_press_event | ||
2849 | 458 | |||
2850 | 459 | def treeview_size_allocate(self, treeview, *args): | ||
2851 | 460 | """Allocate space for the tree view and set wrap width. | ||
2852 | 461 | |||
2853 | 462 | :param treeview: The TreeView | ||
2854 | 463 | :param args: Additional ignored positional arguments | ||
2855 | 464 | """ | ||
2856 | 465 | # Get the rightmost of the two columns in the TreeView, i.e. the one | ||
2857 | 466 | # containing the text. | ||
2858 | 467 | column = treeview.get_column(1) | ||
2859 | 468 | name_cr = column.get_cells()[0] | ||
2860 | 469 | # Wrap to the entire width of the column. | ||
2861 | 470 | width = column.get_width() | ||
2862 | 471 | name_cr.set_property('wrap-width', width) | ||
2863 | 472 | |||
2864 | 473 | on_unused_treeview_size_allocate = treeview_size_allocate | ||
2865 | 474 | on_optimize_treeview_size_allocate = treeview_size_allocate | ||
2866 | 475 | |||
2867 | 476 | def on_sort_by_name_toggled(self, menuitem): | ||
2868 | 477 | """Reorder the crufts to be sorted by name or size.""" | ||
2869 | 478 | if menuitem.get_active(): | ||
2870 | 479 | self._sort_key = self._by_name | ||
2871 | 480 | else: | ||
2872 | 481 | self._sort_key = self._by_size | ||
2873 | 482 | self.sort_cruft() | ||
2874 | 483 | |||
2875 | 484 | def on_about_menuitem_activate(self, *args): | ||
2876 | 485 | dialog = self.widgets['about_dialog'] | ||
2877 | 486 | dialog.set_name(_('Computer Janitor')) | ||
2878 | 487 | dialog.set_version(__version__) | ||
2879 | 488 | dialog.show() | ||
2880 | 489 | dialog.run() | ||
2881 | 490 | dialog.hide() | ||
2882 | 491 | |||
2883 | 492 | def on_show_previously_ignored_toggled(self, menuitem): | ||
2884 | 493 | """Show all cruft, even those being ignored. | ||
2885 | 494 | |||
2886 | 495 | Normally, we only show cruft that wasn't explicitly ignored. By | ||
2887 | 496 | toggling this menu item, the janitor can also display cruft that is | ||
2888 | 497 | marked as ignored on the dbus service. | ||
2889 | 498 | """ | ||
2890 | 499 | show_ignored_cruft = menuitem.get_active() | ||
2891 | 500 | iter = self.store.get_iter_first() | ||
2892 | 501 | while iter: | ||
2893 | 502 | server_ignored = self.store.get_value( | ||
2894 | 503 | iter, ListStoreColumns.server_ignored) | ||
2895 | 504 | show = (show_ignored_cruft or not server_ignored) | ||
2896 | 505 | self.store.set_value(iter, ListStoreColumns.show, show) | ||
2897 | 506 | iter = self.store.iter_next(iter) | ||
2898 | 507 | |||
2899 | 508 | def _edit_menuitem_set_select_state(self, enabled, *treeviews): | ||
2900 | 509 | """Set the specified state on the selected treeviews. | ||
2901 | 510 | |||
2902 | 511 | :param enabled: The new state flag for all cruft. True means enabled. | ||
2903 | 512 | :type enabled: bool | ||
2904 | 513 | :param treeviews: Sequence of `TreeView` object to set cruft state on. | ||
2905 | 514 | """ | ||
2906 | 515 | for treeview in treeviews: | ||
2907 | 516 | self._treeview_foreach_set_set_state(treeview, enabled) | ||
2908 | 517 | |||
2909 | 518 | def on_select_all_cruft_activate(self, menuitem): | ||
2910 | 519 | """Select all cruft, both package and other.""" | ||
2911 | 520 | self._edit_menuitem_set_select_state( | ||
2912 | 521 | True, | ||
2913 | 522 | self.widgets['unused_treeview'], | ||
2914 | 523 | self.widgets['optimize_treeview']) | ||
2915 | 524 | |||
2916 | 525 | def on_select_all_packages_activate(self, menuitem): | ||
2917 | 526 | """Select all cruft, both package and other.""" | ||
2918 | 527 | self._edit_menuitem_set_select_state( | ||
2919 | 528 | True, self.widgets['unused_treeview']) | ||
2920 | 529 | |||
2921 | 530 | def on_select_all_other_activate(self, menuitem): | ||
2922 | 531 | """Select all cruft, both package and other.""" | ||
2923 | 532 | self._edit_menuitem_set_select_state( | ||
2924 | 533 | True, self.widgets['optimize_treeview']) | ||
2925 | 534 | |||
2926 | 535 | def on_deselect_all_cruft_activate(self, menuitem): | ||
2927 | 536 | """Select all cruft, both package and other.""" | ||
2928 | 537 | self._edit_menuitem_set_select_state( | ||
2929 | 538 | False, | ||
2930 | 539 | self.widgets['unused_treeview'], | ||
2931 | 540 | self.widgets['optimize_treeview']) | ||
2932 | 541 | |||
2933 | 542 | def on_deselect_all_packages_activate(self, menuitem): | ||
2934 | 543 | """Select all cruft, both package and other.""" | ||
2935 | 544 | self._edit_menuitem_set_select_state( | ||
2936 | 545 | False, self.widgets['unused_treeview']) | ||
2937 | 546 | |||
2938 | 547 | def on_deselect_all_other_activate(self, menuitem): | ||
2939 | 548 | """Select all cruft, both package and other.""" | ||
2940 | 549 | self._edit_menuitem_set_select_state( | ||
2941 | 550 | False, self.widgets['optimize_treeview']) | ||
2942 | 551 | |||
2943 | 552 | def on_do_button_clicked(self, *args): | ||
2944 | 553 | """JFDI, well almost.""" | ||
2945 | 554 | self.count = 0 | ||
2946 | 555 | response = AreYouSure(self).verify() | ||
2947 | 556 | if not response: | ||
2948 | 557 | return | ||
2949 | 558 | # This can take a long time. Make an asynchronous call to the dbus | ||
2950 | 559 | # service and arrange for it to occasionally provide us with status. | ||
2951 | 560 | # This isn't great ui, but OTOH, the package cruft cleaners themselves | ||
2952 | 561 | # don't provide much granularity, so there's little we can do anyway | ||
2953 | 562 | # without a major rewrite of the plugin architecture. | ||
2954 | 563 | self.working = True | ||
2955 | 564 | glib.timeout_add(150, self.pulse) | ||
2956 | 565 | # Make various ui elements insensitive. | ||
2957 | 566 | self.desensitize() | ||
2958 | 567 | cleanable = [cruft for cruft, ispkg in self.get_cleanable_cruft()] | ||
2959 | 568 | def error(exception): | ||
2960 | 569 | # XXX 2010-05-19 barry: This will (almost?) always be caused by | ||
2961 | 570 | # some other package manager already running, so if we get that | ||
2962 | 571 | # exception, display a (hopefully) useful dialog. I'm not sure | ||
2963 | 572 | # it's very helpful to display the low-level apt exception in a | ||
2964 | 573 | # dialog. `exception` will always be a DBusException; we won't | ||
2965 | 574 | # get the more useful PackageCleanupError. | ||
2966 | 575 | # | ||
2967 | 576 | # We use log.error() instead of log.exception() because we're not | ||
2968 | 577 | # in an exception handler. | ||
2969 | 578 | log.error('%s', exception) | ||
2970 | 579 | CleanupProblem(self).run() | ||
2971 | 580 | self.working = False | ||
2972 | 581 | def reply(): | ||
2973 | 582 | pass | ||
2974 | 583 | # Make the asynchronous call because this can take a long time. We'll | ||
2975 | 584 | # get status updates periodically. Note however that even though this | ||
2976 | 585 | # is asynchronous, dbus still expects a response within a certain | ||
2977 | 586 | # amount of time. We have no idea how long it will take to clean up | ||
2978 | 587 | # the cruft though, so just crank the timeout up to some insanely huge | ||
2979 | 588 | # number (of seconds). | ||
2980 | 589 | self.widgets['progressbar_status'].set_text('Authenticating...') | ||
2981 | 590 | self.janitord.clean(cleanable, | ||
2982 | 591 | reply_handler=reply, | ||
2983 | 592 | error_handler=error, | ||
2984 | 593 | # If it takes longer than an hour, we're screwed. | ||
2985 | 594 | timeout=3600) | ||
2986 | 0 | 595 | ||
2987 | === added file 'computerjanitorapp/terminalsize.py' | |||
2988 | --- computerjanitorapp/terminalsize.py 1970-01-01 00:00:00 +0000 | |||
2989 | +++ computerjanitorapp/terminalsize.py 2011-02-28 19:09:32 +0000 | |||
2990 | @@ -0,0 +1,63 @@ | |||
2991 | 1 | # terminalsize.py - find size of terminal | ||
2992 | 2 | # | ||
2993 | 3 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
2994 | 4 | # | ||
2995 | 5 | # This program is free software: you can redistribute it and/or modify | ||
2996 | 6 | # it under the terms of the GNU General Public License as published by | ||
2997 | 7 | # the Free Software Foundation, version 3 of the License. | ||
2998 | 8 | # | ||
2999 | 9 | # This program is distributed in the hope that it will be useful, | ||
3000 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3001 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3002 | 12 | # GNU General Public License for more details. | ||
3003 | 13 | # | ||
3004 | 14 | # You should have received a copy of the GNU General Public License | ||
3005 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3006 | 16 | |||
3007 | 17 | # Inspired by code by Chuck Blake, at | ||
3008 | 18 | # http://pdos.csail.mit.edu/~cblake/cls/cls.py, but rewritten in an | ||
3009 | 19 | # attempt to clarify things. This code is slightly tricky, so I thought | ||
3010 | 20 | # the extra clarity would be worth it. | ||
3011 | 21 | |||
3012 | 22 | import fcntl | ||
3013 | 23 | import struct | ||
3014 | 24 | import termios | ||
3015 | 25 | |||
3016 | 26 | |||
3017 | 27 | def get_terminal_size(fd=1): | ||
3018 | 28 | """Return size of terminal attached to the standard output. | ||
3019 | 29 | |||
3020 | 30 | Use ioctl(2) to query a terminal for its size, given a file descriptor | ||
3021 | 31 | attached to the terminal. | ||
3022 | 32 | |||
3023 | 33 | :param fd: Use the given file descriptor. | ||
3024 | 34 | :type fd: int | ||
3025 | 35 | :return: The columns and rows representing the size of the terminal. If | ||
3026 | 36 | this cannot be determined, None is returned for both values. | ||
3027 | 37 | :rtype: 2-tuple | ||
3028 | 38 | """ | ||
3029 | 39 | try: | ||
3030 | 40 | # Do the ioctl call. termios.TIOCGWINSZ is the code to query terminal | ||
3031 | 41 | # size (see tty_ioctl(4), at least on Linux). We need to give it a | ||
3032 | 42 | # string of suitable size to use as the input buffer for ioctl. | ||
3033 | 43 | # ioctl() modifies the buffer and returns the modified buffer as its | ||
3034 | 44 | # return value. | ||
3035 | 45 | # | ||
3036 | 46 | # The manual page specifies a struct winsize to be used, which | ||
3037 | 47 | # consists of four unsigned shorts. We use struct.calcsize() to | ||
3038 | 48 | # compute the size of that. | ||
3039 | 49 | # | ||
3040 | 50 | # Note that Blake's original code assumes only the first two shorts in | ||
3041 | 51 | # the struct are used, and that two shorts fit into four bytes, which | ||
3042 | 52 | # is probably true for all the relevant platforms, but is cramped | ||
3043 | 53 | # enough that it makes me feel icky. Thus, I assume less. This will | ||
3044 | 54 | # still break if the contents of the struct change, but since that | ||
3045 | 55 | # would change the system call API, that's unlikely. | ||
3046 | 56 | buflen = struct.calcsize('hhhh') | ||
3047 | 57 | buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * buflen) | ||
3048 | 58 | # ioctl returns a binary buffer that represents the struct | ||
3049 | 59 | # at the C level. We unpack it with struct.unpack. | ||
3050 | 60 | return tuple(struct.unpack('hhhh', buf)[:2]) | ||
3051 | 61 | except Exception: | ||
3052 | 62 | # If anything went wrong, we give up and claim we don't know. | ||
3053 | 63 | return None, None | ||
3054 | 0 | 64 | ||
3055 | === added directory 'computerjanitorapp/tests' | |||
3056 | === added file 'computerjanitorapp/tests/__init__.py' | |||
3057 | === added file 'computerjanitorapp/tests/test_all.py' | |||
3058 | --- computerjanitorapp/tests/test_all.py 1970-01-01 00:00:00 +0000 | |||
3059 | +++ computerjanitorapp/tests/test_all.py 2011-02-28 19:09:32 +0000 | |||
3060 | @@ -0,0 +1,29 @@ | |||
3061 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3062 | 2 | # | ||
3063 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3064 | 4 | # it under the terms of the GNU General Public License as published by | ||
3065 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3066 | 6 | # | ||
3067 | 7 | # This program is distributed in the hope that it will be useful, | ||
3068 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3069 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3070 | 10 | # GNU General Public License for more details. | ||
3071 | 11 | # | ||
3072 | 12 | # You should have received a copy of the GNU General Public License | ||
3073 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3074 | 14 | |||
3075 | 15 | """Test suite for Computer Janitor.""" | ||
3076 | 16 | |||
3077 | 17 | import unittest | ||
3078 | 18 | |||
3079 | 19 | from computerjanitorapp.tests import test_terminalsize | ||
3080 | 20 | from computerjanitorapp.tests import test_utilities | ||
3081 | 21 | from computerjanitord.tests.test_all import test_suite as cjd_suite | ||
3082 | 22 | |||
3083 | 23 | |||
3084 | 24 | def test_suite(): | ||
3085 | 25 | suite = unittest.TestSuite() | ||
3086 | 26 | suite.addTests(test_terminalsize.test_suite()) | ||
3087 | 27 | suite.addTests(test_utilities.test_suite()) | ||
3088 | 28 | suite.addTests(cjd_suite()) | ||
3089 | 29 | return suite | ||
3090 | 0 | 30 | ||
3091 | === added file 'computerjanitorapp/tests/test_terminalsize.py' | |||
3092 | --- computerjanitorapp/tests/test_terminalsize.py 1970-01-01 00:00:00 +0000 | |||
3093 | +++ computerjanitorapp/tests/test_terminalsize.py 2011-02-28 19:09:32 +0000 | |||
3094 | @@ -0,0 +1,54 @@ | |||
3095 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3096 | 2 | # | ||
3097 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3098 | 4 | # it under the terms of the GNU General Public License as published by | ||
3099 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3100 | 6 | # | ||
3101 | 7 | # This program is distributed in the hope that it will be useful, | ||
3102 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3103 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3104 | 10 | # GNU General Public License for more details. | ||
3105 | 11 | # | ||
3106 | 12 | # You should have received a copy of the GNU General Public License | ||
3107 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3108 | 14 | |||
3109 | 15 | """Test calculation of terminal sizes.""" | ||
3110 | 16 | |||
3111 | 17 | from __future__ import absolute_import, unicode_literals | ||
3112 | 18 | |||
3113 | 19 | __metaclass__ = type | ||
3114 | 20 | __all__ = [ | ||
3115 | 21 | 'test_suite', | ||
3116 | 22 | ] | ||
3117 | 23 | |||
3118 | 24 | |||
3119 | 25 | import os | ||
3120 | 26 | import unittest | ||
3121 | 27 | |||
3122 | 28 | from computerjanitorapp import terminalsize | ||
3123 | 29 | |||
3124 | 30 | |||
3125 | 31 | class TestTerminalSize(unittest.TestCase): | ||
3126 | 32 | """Test calculation of terminal sizes.""" | ||
3127 | 33 | |||
3128 | 34 | def test_returns_unknown_when_querying_dev_null(self): | ||
3129 | 35 | fd = os.open("/dev/null", os.O_RDONLY) | ||
3130 | 36 | rows, cols = terminalsize.get_terminal_size(fd) | ||
3131 | 37 | os.close(fd) | ||
3132 | 38 | self.assertEqual(rows, None) | ||
3133 | 39 | self.assertEqual(cols, None) | ||
3134 | 40 | |||
3135 | 41 | def test_returns_two_integers_when_stdout_is_a_terminal(self): | ||
3136 | 42 | # We only run this check if stdout is a terminal. | ||
3137 | 43 | # Unfortunately, there is no sensible way of checking the values. | ||
3138 | 44 | # But that's OK, they're lumberjacks. | ||
3139 | 45 | if os.isatty(1): | ||
3140 | 46 | rows, cols = terminalsize.get_terminal_size(1) | ||
3141 | 47 | self.assertEqual(type(rows), int) | ||
3142 | 48 | self.assertEqual(type(cols), int) | ||
3143 | 49 | |||
3144 | 50 | |||
3145 | 51 | def test_suite(): | ||
3146 | 52 | suite = unittest.TestSuite() | ||
3147 | 53 | suite.addTests(unittest.makeSuite(TestTerminalSize)) | ||
3148 | 54 | return suite | ||
3149 | 0 | 55 | ||
3150 | === added file 'computerjanitorapp/tests/test_utilities.py' | |||
3151 | --- computerjanitorapp/tests/test_utilities.py 1970-01-01 00:00:00 +0000 | |||
3152 | +++ computerjanitorapp/tests/test_utilities.py 2011-02-28 19:09:32 +0000 | |||
3153 | @@ -0,0 +1,70 @@ | |||
3154 | 1 | # Copyright (C) 2010-2011 Canonical, Ltd. | ||
3155 | 2 | # | ||
3156 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3157 | 4 | # it under the terms of the GNU General Public License as published by | ||
3158 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3159 | 6 | # | ||
3160 | 7 | # This program is distributed in the hope that it will be useful, | ||
3161 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3162 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3163 | 10 | # GNU General Public License for more details. | ||
3164 | 11 | # | ||
3165 | 12 | # You should have received a copy of the GNU General Public License | ||
3166 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3167 | 14 | |||
3168 | 15 | """Test common utilities.""" | ||
3169 | 16 | |||
3170 | 17 | from __future__ import absolute_import, unicode_literals | ||
3171 | 18 | |||
3172 | 19 | __metaclass__ = type | ||
3173 | 20 | __all__ = [ | ||
3174 | 21 | 'test_suite', | ||
3175 | 22 | ] | ||
3176 | 23 | |||
3177 | 24 | |||
3178 | 25 | import unittest | ||
3179 | 26 | |||
3180 | 27 | from computerjanitorapp.utilities import format_size | ||
3181 | 28 | |||
3182 | 29 | |||
3183 | 30 | class TestUtilities(unittest.TestCase): | ||
3184 | 31 | """Test common utilities.""" | ||
3185 | 32 | |||
3186 | 33 | def test_format_negative(self): | ||
3187 | 34 | self.assertRaises(AssertionError, format_size, -1) | ||
3188 | 35 | |||
3189 | 36 | def test_format_zero(self): | ||
3190 | 37 | self.assertEqual(format_size(0), '0B') | ||
3191 | 38 | |||
3192 | 39 | def test_format_small(self): | ||
3193 | 40 | self.assertEqual(format_size(500), '500B') | ||
3194 | 41 | |||
3195 | 42 | def test_format_1k(self): | ||
3196 | 43 | self.assertEqual(format_size(1000), '1kB') | ||
3197 | 44 | |||
3198 | 45 | def test_format_smallish(self): | ||
3199 | 46 | self.assertEqual(format_size(500000), '500kB') | ||
3200 | 47 | |||
3201 | 48 | def test_format_1M(self): | ||
3202 | 49 | self.assertEqual(format_size(1000000), '1MB') | ||
3203 | 50 | |||
3204 | 51 | def test_format_mediumish(self): | ||
3205 | 52 | self.assertEqual(format_size(500000000), '500MB') | ||
3206 | 53 | |||
3207 | 54 | def test_format_1G(self): | ||
3208 | 55 | self.assertEqual(format_size(1000000000), '1GB') | ||
3209 | 56 | |||
3210 | 57 | def test_format_bigish(self): | ||
3211 | 58 | self.assertEqual(format_size(500000000000), '500GB') | ||
3212 | 59 | |||
3213 | 60 | def test_format_1T(self): | ||
3214 | 61 | self.assertEqual(format_size(1000000000000), '1TB') | ||
3215 | 62 | |||
3216 | 63 | def test_format_hugish(self): | ||
3217 | 64 | self.assertEqual(format_size(500000000000000), '>1TB') | ||
3218 | 65 | |||
3219 | 66 | |||
3220 | 67 | def test_suite(): | ||
3221 | 68 | suite = unittest.TestSuite() | ||
3222 | 69 | suite.addTests(unittest.makeSuite(TestUtilities)) | ||
3223 | 70 | return suite | ||
3224 | 0 | 71 | ||
3225 | === added file 'computerjanitorapp/utilities.py' | |||
3226 | --- computerjanitorapp/utilities.py 1970-01-01 00:00:00 +0000 | |||
3227 | +++ computerjanitorapp/utilities.py 2011-02-28 19:09:32 +0000 | |||
3228 | @@ -0,0 +1,51 @@ | |||
3229 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3230 | 2 | # | ||
3231 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3232 | 4 | # it under the terms of the GNU General Public License as published by | ||
3233 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3234 | 6 | # | ||
3235 | 7 | # This program is distributed in the hope that it will be useful, | ||
3236 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3237 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3238 | 10 | # GNU General Public License for more details. | ||
3239 | 11 | # | ||
3240 | 12 | # You should have received a copy of the GNU General Public License | ||
3241 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3242 | 14 | |||
3243 | 15 | """Common utilities.""" | ||
3244 | 16 | |||
3245 | 17 | from __future__ import absolute_import, unicode_literals | ||
3246 | 18 | |||
3247 | 19 | __metaclass__ = type | ||
3248 | 20 | __all__ = [ | ||
3249 | 21 | 'format_size', | ||
3250 | 22 | ] | ||
3251 | 23 | |||
3252 | 24 | |||
3253 | 25 | from math import log10 | ||
3254 | 26 | |||
3255 | 27 | |||
3256 | 28 | TABLE = ( | ||
3257 | 29 | 'B', | ||
3258 | 30 | 'kB', | ||
3259 | 31 | 'MB', | ||
3260 | 32 | 'GB', | ||
3261 | 33 | 'TB', | ||
3262 | 34 | ) | ||
3263 | 35 | |||
3264 | 36 | |||
3265 | 37 | def format_size(bytes): | ||
3266 | 38 | """Format size in bytes. | ||
3267 | 39 | |||
3268 | 40 | :param bytes: Integer size in bytes. | ||
3269 | 41 | :type bytes: integer | ||
3270 | 42 | :return: Formatted size | ||
3271 | 43 | :rtype: string | ||
3272 | 44 | """ | ||
3273 | 45 | assert bytes >= 0, 'Cannot have negative sizes' | ||
3274 | 46 | if bytes == 0: | ||
3275 | 47 | return '0B' | ||
3276 | 48 | if bytes > 10**12: | ||
3277 | 49 | return '>1TB' | ||
3278 | 50 | key = divmod(int(log10(bytes)), 3)[0] | ||
3279 | 51 | return '{0}{1}'.format(bytes // 10**(key * 3), TABLE[key]) | ||
3280 | 0 | 52 | ||
3281 | === added directory 'computerjanitord' | |||
3282 | === renamed directory 'computerjanitord' => 'computerjanitord.moved' | |||
3283 | === added file 'computerjanitord/__init__.py' | |||
3284 | === added file 'computerjanitord/application.py' | |||
3285 | --- computerjanitord/application.py 1970-01-01 00:00:00 +0000 | |||
3286 | +++ computerjanitord/application.py 2011-02-28 19:09:32 +0000 | |||
3287 | @@ -0,0 +1,90 @@ | |||
3288 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3289 | 2 | # | ||
3290 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3291 | 4 | # it under the terms of the GNU General Public License as published by | ||
3292 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3293 | 6 | # | ||
3294 | 7 | # This program is distributed in the hope that it will be useful, | ||
3295 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3296 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3297 | 10 | # GNU General Public License for more details. | ||
3298 | 11 | # | ||
3299 | 12 | # You should have received a copy of the GNU General Public License | ||
3300 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3301 | 14 | |||
3302 | 15 | """Application interface for use by plugins. | ||
3303 | 16 | |||
3304 | 17 | This primarily makes certain apt functionality available to the plugin. | ||
3305 | 18 | """ | ||
3306 | 19 | |||
3307 | 20 | from __future__ import absolute_import, unicode_literals | ||
3308 | 21 | |||
3309 | 22 | __metaclass__ = type | ||
3310 | 23 | __all__ = [ | ||
3311 | 24 | 'Application', | ||
3312 | 25 | ] | ||
3313 | 26 | |||
3314 | 27 | |||
3315 | 28 | import apt | ||
3316 | 29 | |||
3317 | 30 | import computerjanitorapp | ||
3318 | 31 | |||
3319 | 32 | from computerjanitord.errors import ( | ||
3320 | 33 | MissingLandmarkError, NonDownloadableError) | ||
3321 | 34 | |||
3322 | 35 | |||
3323 | 36 | _ = computerjanitorapp.setup_gettext() | ||
3324 | 37 | |||
3325 | 38 | SYNTAPTIC_PREFERENCES_FILE = '/var/lib/synaptic/preferences' | ||
3326 | 39 | # There really isn't anything special about these packages. These really just | ||
3327 | 40 | # represent landmarks in the package namespace that we look for to try to | ||
3328 | 41 | # judge the sanity of the apt cache. If these are missing, things are really | ||
3329 | 42 | # messed up and we can't actually figure out how to continue. | ||
3330 | 43 | LANDMARK_PACKAGES = [ | ||
3331 | 44 | 'dash', | ||
3332 | 45 | 'gzip', | ||
3333 | 46 | ] | ||
3334 | 47 | |||
3335 | 48 | |||
3336 | 49 | class Application: | ||
3337 | 50 | """Interface for plugins requesting apt actions.""" | ||
3338 | 51 | |||
3339 | 52 | def __init__(self, apt_cache=None): | ||
3340 | 53 | """Create the application interface. | ||
3341 | 54 | |||
3342 | 55 | :param apt_cache: Alternative apt cache for testing purposes. When | ||
3343 | 56 | `None` use the default apt cache. | ||
3344 | 57 | """ | ||
3345 | 58 | if apt_cache is None: | ||
3346 | 59 | # Use the real apt cache. | ||
3347 | 60 | self.apt_cache = apt.Cache() | ||
3348 | 61 | else: | ||
3349 | 62 | self.apt_cache = apt_cache | ||
3350 | 63 | self.refresh_apt_cache() | ||
3351 | 64 | |||
3352 | 65 | def refresh_apt_cache(self): | ||
3353 | 66 | """Refresh the apt cache. | ||
3354 | 67 | |||
3355 | 68 | This API is used by plugins. | ||
3356 | 69 | """ | ||
3357 | 70 | self.apt_cache.open() | ||
3358 | 71 | # For historical purposes, Synaptic has a different way of pinning | ||
3359 | 72 | # packages than apt, so we have to load its preferences file in order | ||
3360 | 73 | # to know what it's pinning. | ||
3361 | 74 | self.apt_cache._depcache.read_pinfile(SYNTAPTIC_PREFERENCES_FILE) | ||
3362 | 75 | |||
3363 | 76 | def verify_apt_cache(self): | ||
3364 | 77 | """Verify that essential packages are available in the apt cache. | ||
3365 | 78 | |||
3366 | 79 | This API is used by plugins. | ||
3367 | 80 | |||
3368 | 81 | :raises MissingLandmarkError: When an essential package is not | ||
3369 | 82 | available. | ||
3370 | 83 | :raises NonDownloadableError: When an essential package cannot be | ||
3371 | 84 | downloaded. | ||
3372 | 85 | """ | ||
3373 | 86 | for name in LANDMARK_PACKAGES: | ||
3374 | 87 | if name not in self.apt_cache: | ||
3375 | 88 | raise MissingLandmarkError(name) | ||
3376 | 89 | if not any(v.downloadable for v in self.apt_cache[name].versions): | ||
3377 | 90 | raise NonDownloadableError(name) | ||
3378 | 0 | 91 | ||
3379 | === added file 'computerjanitord/authenticator.py' | |||
3380 | --- computerjanitord/authenticator.py 1970-01-01 00:00:00 +0000 | |||
3381 | +++ computerjanitord/authenticator.py 2011-02-28 19:09:32 +0000 | |||
3382 | @@ -0,0 +1,85 @@ | |||
3383 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3384 | 2 | # | ||
3385 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3386 | 4 | # it under the terms of the GNU General Public License as published by | ||
3387 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3388 | 6 | # | ||
3389 | 7 | # This program is distributed in the hope that it will be useful, | ||
3390 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3391 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3392 | 10 | # GNU General Public License for more details. | ||
3393 | 11 | # | ||
3394 | 12 | # You should have received a copy of the GNU General Public License | ||
3395 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3396 | 14 | |||
3397 | 15 | """Authentication for Computer Janitor backend services.""" | ||
3398 | 16 | |||
3399 | 17 | from __future__ import absolute_import, unicode_literals | ||
3400 | 18 | |||
3401 | 19 | __metaclass__ = type | ||
3402 | 20 | __all__ = [ | ||
3403 | 21 | 'Authenticator', | ||
3404 | 22 | ] | ||
3405 | 23 | |||
3406 | 24 | |||
3407 | 25 | import dbus | ||
3408 | 26 | |||
3409 | 27 | |||
3410 | 28 | PK_AUTHORITY_BUS_NAME = 'org.freedesktop.PolicyKit1' | ||
3411 | 29 | PK_AUTHORITY_OBJECT_PATH = '/org/freedesktop/PolicyKit1/Authority' | ||
3412 | 30 | PK_AUTHORITY_INTERFACE = 'org.freedesktop.PolicyKit1.Authority' | ||
3413 | 31 | # From the PolicyKit API. | ||
3414 | 32 | # http://hal.freedesktop.org/docs/polkit/ | ||
3415 | 33 | # eggdbus-interface-org.freedesktop.PolicyKit1.Authority.html | ||
3416 | 34 | AllowUserInteraction = 0x00000001 | ||
3417 | 35 | |||
3418 | 36 | |||
3419 | 37 | class Authenticator: | ||
3420 | 38 | """PolicyKit authenticator.""" | ||
3421 | 39 | |||
3422 | 40 | def authenticate(self, sender, connection, privilege): | ||
3423 | 41 | """Authenticate with PolicyKit. | ||
3424 | 42 | |||
3425 | 43 | :param sender: The initiator of the action. | ||
3426 | 44 | :param connection: The dbus connection that initiated the action. | ||
3427 | 45 | :param privilege: The privilege being requested. | ||
3428 | 46 | :return: Whether the subject is authorized or not. | ||
3429 | 47 | :rtype: bool | ||
3430 | 48 | """ | ||
3431 | 49 | policykit = self._get_policykit_proxy() | ||
3432 | 50 | sender_pid = self._get_sender_pid(connection, sender) | ||
3433 | 51 | # This is the CheckAuthorization() 'subject' structure. | ||
3434 | 52 | subject = ( | ||
3435 | 53 | 'unix-process', { | ||
3436 | 54 | 'pid': sender_pid, | ||
3437 | 55 | 'start-time': dbus.UInt64(0), | ||
3438 | 56 | }) | ||
3439 | 57 | # No details or cancellation_id needed. | ||
3440 | 58 | details = {'': ''} | ||
3441 | 59 | cancellation_id = '' | ||
3442 | 60 | flags = AllowUserInteraction | ||
3443 | 61 | # CheckAuthorization returns an AuthorizationResult structure, modeled | ||
3444 | 62 | # as a 3-tuple. The only thing we care about though is the boolean | ||
3445 | 63 | # describing whether we got authorized or not. | ||
3446 | 64 | is_authorized, is_challenge, details = policykit.CheckAuthorization( | ||
3447 | 65 | subject, privilege, details, flags, cancellation_id) | ||
3448 | 66 | return is_authorized | ||
3449 | 67 | |||
3450 | 68 | def _get_policykit_proxy(self): | ||
3451 | 69 | """Contact the system bus to get a PolicyKit proxy.""" | ||
3452 | 70 | system_bus = dbus.SystemBus() | ||
3453 | 71 | pk_proxy = system_bus.get_object( | ||
3454 | 72 | PK_AUTHORITY_BUS_NAME, PK_AUTHORITY_OBJECT_PATH) | ||
3455 | 73 | return dbus.Interface(pk_proxy, PK_AUTHORITY_INTERFACE) | ||
3456 | 74 | |||
3457 | 75 | def _get_sender_pid(self, connection, sender): | ||
3458 | 76 | """Contact the system bus to get the sender connection PID.""" | ||
3459 | 77 | # Since we're going to authorize a Unix process, we need to get the | ||
3460 | 78 | # sender's process id. This is available on the dbus. The | ||
3461 | 79 | # CheckAuthorization() method also requires us to have a start-time, | ||
3462 | 80 | # but it's not clear what the semantics are for that, so we'll just | ||
3463 | 81 | # put a zero there. | ||
3464 | 82 | db_proxy = connection.get_object( | ||
3465 | 83 | dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH, introspect=False) | ||
3466 | 84 | info = dbus.Interface(db_proxy, dbus.BUS_DAEMON_IFACE) | ||
3467 | 85 | return info.GetConnectionUnixProcessID(sender) | ||
3468 | 0 | 86 | ||
3469 | === added file 'computerjanitord/collector.py' | |||
3470 | --- computerjanitord/collector.py 1970-01-01 00:00:00 +0000 | |||
3471 | +++ computerjanitord/collector.py 2011-02-28 19:09:32 +0000 | |||
3472 | @@ -0,0 +1,168 @@ | |||
3473 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3474 | 2 | # | ||
3475 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3476 | 4 | # it under the terms of the GNU General Public License as published by | ||
3477 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3478 | 6 | # | ||
3479 | 7 | # This program is distributed in the hope that it will be useful, | ||
3480 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3481 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3482 | 10 | # GNU General Public License for more details. | ||
3483 | 11 | # | ||
3484 | 12 | # You should have received a copy of the GNU General Public License | ||
3485 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3486 | 14 | |||
3487 | 15 | """A cruft collector.""" | ||
3488 | 16 | |||
3489 | 17 | from __future__ import absolute_import, unicode_literals | ||
3490 | 18 | |||
3491 | 19 | __metaclass__ = type | ||
3492 | 20 | __all__ = [ | ||
3493 | 21 | 'Collector', | ||
3494 | 22 | ] | ||
3495 | 23 | |||
3496 | 24 | |||
3497 | 25 | import os | ||
3498 | 26 | import time | ||
3499 | 27 | import logging | ||
3500 | 28 | |||
3501 | 29 | from computerjanitor import PluginManager | ||
3502 | 30 | from computerjanitord.errors import ( | ||
3503 | 31 | DuplicateCruftError, NoSuchCruftError, PackageCleanupError) | ||
3504 | 32 | from computerjanitord.whitelist import Whitelist | ||
3505 | 33 | |||
3506 | 34 | |||
3507 | 35 | log = logging.getLogger('computerjanitor') | ||
3508 | 36 | MISSING = object() | ||
3509 | 37 | DEFAULT_PLUGINS_DIRS = "/usr/share/computerjanitor/plugins" | ||
3510 | 38 | |||
3511 | 39 | # For testing purposes. | ||
3512 | 40 | SLEEPY_TIME = float(os.environ.get('COMPUTER_JANITOR_SLEEPY_TIME', '1.0')) | ||
3513 | 41 | |||
3514 | 42 | |||
3515 | 43 | class Collector: | ||
3516 | 44 | """A cruft collector.""" | ||
3517 | 45 | |||
3518 | 46 | def __init__(self, application, plugin_manager_class=None, | ||
3519 | 47 | whitelist_dirs=None, service=None): | ||
3520 | 48 | """Create a cruft collector. | ||
3521 | 49 | |||
3522 | 50 | :param application: The `Application` class. | ||
3523 | 51 | :type application: This object is used by plugins to access the apt | ||
3524 | 52 | database. It must have an attribute named `apt_cache` and a | ||
3525 | 53 | method named `refresh_apt_cache()`. | ||
3526 | 54 | :param plugin_manager_class: The plugin manager class. If None (the | ||
3527 | 55 | default), then `computerjanitor.PluginManager` is used. | ||
3528 | 56 | :type plugin_manager_class: callable accepting a single argument, | ||
3529 | 57 | which is a sequence of plugin directories. | ||
3530 | 58 | :param whitelist_dirs: Sequence of directories to search for | ||
3531 | 59 | '.whitelist' files. Passed directly to | ||
3532 | 60 | `computerjanitord.whitelist.Whitelist`. | ||
3533 | 61 | :param service: The dbus service; when doing plugin post-cleanup, this | ||
3534 | 62 | will be used to emit a progress signal. | ||
3535 | 63 | """ | ||
3536 | 64 | self.application = application | ||
3537 | 65 | self.service = service | ||
3538 | 66 | self.whitelist = Whitelist(whitelist_dirs) | ||
3539 | 67 | # Keep track of cruft and map between the cruft's name and its Cruft | ||
3540 | 68 | # instance. We'll use the latter when cruft cleanup is requested | ||
3541 | 69 | # through the dbus API. | ||
3542 | 70 | self.cruft = None | ||
3543 | 71 | self.cruft_by_name = None | ||
3544 | 72 | # Set up the plugin manager. | ||
3545 | 73 | plugin_path = os.environ.get('COMPUTER_JANITOR_PLUGINS', | ||
3546 | 74 | DEFAULT_PLUGINS_DIRS) | ||
3547 | 75 | plugin_dirs = plugin_path.split(':') | ||
3548 | 76 | if plugin_manager_class is None: | ||
3549 | 77 | plugin_manager_class = PluginManager | ||
3550 | 78 | self.plugin_manager = plugin_manager_class(application, plugin_dirs) | ||
3551 | 79 | self.load() | ||
3552 | 80 | |||
3553 | 81 | def load(self): | ||
3554 | 82 | """Reload all cruft.""" | ||
3555 | 83 | self.cruft = [] | ||
3556 | 84 | self.cruft_by_name = {} | ||
3557 | 85 | # Ask all the plugins to find their cruft, filtering out whitelisted | ||
3558 | 86 | # cruft. | ||
3559 | 87 | for plugin in self.plugin_manager.get_plugins(): | ||
3560 | 88 | for cruft in plugin.get_cruft(): | ||
3561 | 89 | if not self.whitelist.is_whitelisted(cruft): | ||
3562 | 90 | # Different plugins can give us duplicate cruft names, | ||
3563 | 91 | # however the Cruft class better be the same, otherwise we | ||
3564 | 92 | # won't actually know how to map the name back to a cruft | ||
3565 | 93 | # instance for proper cleanup. | ||
3566 | 94 | if cruft.get_name() in self.cruft_by_name: | ||
3567 | 95 | my_cruft = self.cruft_by_name[cruft.get_name()] | ||
3568 | 96 | if cruft.__class__ is my_cruft.__class__: | ||
3569 | 97 | # We only need one instance of this cruft. | ||
3570 | 98 | continue | ||
3571 | 99 | else: | ||
3572 | 100 | raise DuplicateCruftError(cruft.get_name()) | ||
3573 | 101 | #print ' ', cruft.get_name() | ||
3574 | 102 | self.cruft.append(cruft) | ||
3575 | 103 | self.cruft_by_name[cruft.get_name()] = cruft | ||
3576 | 104 | |||
3577 | 105 | def clean(self, names, dry_run=False): | ||
3578 | 106 | """Clean up the named cruft. | ||
3579 | 107 | |||
3580 | 108 | :param names: The names of the cruft to clean up. | ||
3581 | 109 | :type names: list of strings | ||
3582 | 110 | :param dry_run: Flag indicating whether to do permanent changes. | ||
3583 | 111 | :type dry_run: bool | ||
3584 | 112 | """ | ||
3585 | 113 | for name in names: | ||
3586 | 114 | # Ensure that all named cruft is known. | ||
3587 | 115 | cruft = self.cruft_by_name.get(name, MISSING) | ||
3588 | 116 | if cruft is MISSING: | ||
3589 | 117 | log.error('No such cruft: {0}'.format(name)) | ||
3590 | 118 | raise NoSuchCruftError(name) | ||
3591 | 119 | # Ensure that the cruft is not being ignored. | ||
3592 | 120 | if cruft in self.service.state.ignore: | ||
3593 | 121 | log.error('Skipping ignored cruft: {0}'.format(name)) | ||
3594 | 122 | continue | ||
3595 | 123 | log.info('cleaning cruft{1}: {0}'.format( | ||
3596 | 124 | cruft.get_name(), ('[X]' if dry_run else '[Y]'))) | ||
3597 | 125 | if not dry_run: | ||
3598 | 126 | try: | ||
3599 | 127 | cruft.cleanup() | ||
3600 | 128 | except: | ||
3601 | 129 | log.exception('cruft.cleanup(): {0}'.format(name)) | ||
3602 | 130 | raise | ||
3603 | 131 | # Do plugin-specific post-cleanup. | ||
3604 | 132 | for plugin in self.plugin_manager.get_plugins(): | ||
3605 | 133 | log.info('post-cleanup: {0}'.format(plugin)) | ||
3606 | 134 | if self.service is not None: | ||
3607 | 135 | # Notify the client that we're not done yet. | ||
3608 | 136 | # | ||
3609 | 137 | # 2010-02-09 barry: this actually kind of sucks because the | ||
3610 | 138 | # granularity is too coarse. Some plugins will post_cleanup() | ||
3611 | 139 | # very quickly, others will take a long time. Unfortunately, | ||
3612 | 140 | # the computerjanitor.Plugin API doesn't support a more | ||
3613 | 141 | # granular feedback. Plugin.get_plugin(..., callback=foo) | ||
3614 | 142 | # doesn't really cut it because that only gets called during | ||
3615 | 143 | # get_plugins(). | ||
3616 | 144 | self.service.cleanup_status(plugin.__class__.__name__) | ||
3617 | 145 | if dry_run: | ||
3618 | 146 | # For testing purposes. | ||
3619 | 147 | time.sleep(SLEEPY_TIME) | ||
3620 | 148 | else: | ||
3621 | 149 | try: | ||
3622 | 150 | plugin.post_cleanup() | ||
3623 | 151 | except SystemError as error: | ||
3624 | 152 | # apt will raise a SystemError if some other package | ||
3625 | 153 | # manager is already running. Turn this into a dbus | ||
3626 | 154 | # derived exception so the client will be properly | ||
3627 | 155 | # informed. | ||
3628 | 156 | log.exception( | ||
3629 | 157 | 'plugin.post_cleanup(): {0}'.format(plugin)) | ||
3630 | 158 | raise PackageCleanupError(str(error)) | ||
3631 | 159 | except: | ||
3632 | 160 | log.exception( | ||
3633 | 161 | 'plugin.post_cleanup(): {0}'.format(plugin)) | ||
3634 | 162 | raise | ||
3635 | 163 | # Now we're done. | ||
3636 | 164 | if self.service is not None: | ||
3637 | 165 | self.service.cleanup_status('') | ||
3638 | 166 | # Reload list of crufts. | ||
3639 | 167 | self.application.refresh_apt_cache() | ||
3640 | 168 | self.load() | ||
3641 | 0 | 169 | ||
3642 | === added directory 'computerjanitord/data' | |||
3643 | === added file 'computerjanitord/data/com.ubuntu.ComputerJanitor.conf' | |||
3644 | --- computerjanitord/data/com.ubuntu.ComputerJanitor.conf 1970-01-01 00:00:00 +0000 | |||
3645 | +++ computerjanitord/data/com.ubuntu.ComputerJanitor.conf 2011-02-28 19:09:32 +0000 | |||
3646 | @@ -0,0 +1,15 @@ | |||
3647 | 1 | <!DOCTYPE busconfig PUBLIC | ||
3648 | 2 | "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" | ||
3649 | 3 | "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
3650 | 4 | <busconfig> | ||
3651 | 5 | <policy user="root"> | ||
3652 | 6 | <allow own="com.ubuntu.ComputerJanitor"/> | ||
3653 | 7 | </policy> | ||
3654 | 8 | |||
3655 | 9 | <policy context="default"> | ||
3656 | 10 | <allow send_interface="com.ubuntu.ComputerJanitor"/> | ||
3657 | 11 | <allow receive_interface="com.ubuntu.ComputerJanitor" | ||
3658 | 12 | receive_sender="com.ubuntu.ComputerJanitor"/> | ||
3659 | 13 | </policy> | ||
3660 | 14 | |||
3661 | 15 | </busconfig> | ||
3662 | 0 | 16 | ||
3663 | === added file 'computerjanitord/data/com.ubuntu.ComputerJanitor.service' | |||
3664 | --- computerjanitord/data/com.ubuntu.ComputerJanitor.service 1970-01-01 00:00:00 +0000 | |||
3665 | +++ computerjanitord/data/com.ubuntu.ComputerJanitor.service 2011-02-28 19:09:32 +0000 | |||
3666 | @@ -0,0 +1,4 @@ | |||
3667 | 1 | [D-BUS Service] | ||
3668 | 2 | Name=com.ubuntu.ComputerJanitor | ||
3669 | 3 | Exec=/usr/share/computerjanitor/janitord | ||
3670 | 4 | User=root | ||
3671 | 0 | 5 | ||
3672 | === added file 'computerjanitord/data/com.ubuntu.computerjanitor.policy' | |||
3673 | --- computerjanitord/data/com.ubuntu.computerjanitor.policy 1970-01-01 00:00:00 +0000 | |||
3674 | +++ computerjanitord/data/com.ubuntu.computerjanitor.policy 2011-02-28 19:09:32 +0000 | |||
3675 | @@ -0,0 +1,19 @@ | |||
3676 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
3677 | 2 | <!DOCTYPE policyconfig PUBLIC | ||
3678 | 3 | "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" | ||
3679 | 4 | "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd"> | ||
3680 | 5 | <policyconfig> | ||
3681 | 6 | |||
3682 | 7 | <vendor>ComputerJanitor</vendor> | ||
3683 | 8 | <vendor_url>https://launchpad.net/computer-janitor</vendor_url> | ||
3684 | 9 | |||
3685 | 10 | <action id="com.ubuntu.computerjanitor.updatesystem"> | ||
3686 | 11 | <description>Clean up packages that are no longer necessary</description> | ||
3687 | 12 | <message>Removing unused packages requires authentication</message> | ||
3688 | 13 | <defaults> | ||
3689 | 14 | <allow_inactive>no</allow_inactive> | ||
3690 | 15 | <allow_active>auth_admin_keep</allow_active> | ||
3691 | 16 | </defaults> | ||
3692 | 17 | </action> | ||
3693 | 18 | |||
3694 | 19 | </policyconfig> | ||
3695 | 0 | 20 | ||
3696 | === added file 'computerjanitord/errors.py' | |||
3697 | --- computerjanitord/errors.py 1970-01-01 00:00:00 +0000 | |||
3698 | +++ computerjanitord/errors.py 2011-02-28 19:09:32 +0000 | |||
3699 | @@ -0,0 +1,95 @@ | |||
3700 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3701 | 2 | # | ||
3702 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3703 | 4 | # it under the terms of the GNU General Public License as published by | ||
3704 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3705 | 6 | # | ||
3706 | 7 | # This program is distributed in the hope that it will be useful, | ||
3707 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3708 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3709 | 10 | # GNU General Public License for more details. | ||
3710 | 11 | # | ||
3711 | 12 | # You should have received a copy of the GNU General Public License | ||
3712 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3713 | 14 | |||
3714 | 15 | """Exceptions for the Computer Janitor daemon.""" | ||
3715 | 16 | |||
3716 | 17 | |||
3717 | 18 | from __future__ import absolute_import, unicode_literals | ||
3718 | 19 | |||
3719 | 20 | __metaclass__ = type | ||
3720 | 21 | __all__ = [ | ||
3721 | 22 | 'DuplicateCruftError', | ||
3722 | 23 | 'LandmarkPackageError', | ||
3723 | 24 | 'MissingLandmarkError', | ||
3724 | 25 | 'NoSuchCruftError', | ||
3725 | 26 | 'NonDownloadableError', | ||
3726 | 27 | 'PermissionDeniedError', | ||
3727 | 28 | ] | ||
3728 | 29 | |||
3729 | 30 | |||
3730 | 31 | import dbus | ||
3731 | 32 | import computerjanitor | ||
3732 | 33 | |||
3733 | 34 | |||
3734 | 35 | class DBusServiceBaseException(computerjanitor.Exception, dbus.DBusException): | ||
3735 | 36 | """Base class exception for the Computer Janitor DBus service.""" | ||
3736 | 37 | |||
3737 | 38 | |||
3738 | 39 | class PermissionDeniedError(DBusServiceBaseException): | ||
3739 | 40 | """Permission denied by policy.""" | ||
3740 | 41 | |||
3741 | 42 | |||
3742 | 43 | class CruftError(DBusServiceBaseException): | ||
3743 | 44 | """Cruft exceptions passed back to dbus client.""" | ||
3744 | 45 | |||
3745 | 46 | _errmsg = None | ||
3746 | 47 | |||
3747 | 48 | def __init__(self, cruft_name): | ||
3748 | 49 | self.cruft_name = cruft_name | ||
3749 | 50 | |||
3750 | 51 | def __str__(self): | ||
3751 | 52 | return self._errmsg.format(self) | ||
3752 | 53 | |||
3753 | 54 | |||
3754 | 55 | class DuplicateCruftError(CruftError): | ||
3755 | 56 | """Duplicate cruft name with different cleanup.""" | ||
3756 | 57 | |||
3757 | 58 | _errmsg = 'Duplicate cruft with different cleanup: {0.cruft_name}' | ||
3758 | 59 | |||
3759 | 60 | |||
3760 | 61 | class NoSuchCruftError(CruftError): | ||
3761 | 62 | """There is no cruft by the given name.""" | ||
3762 | 63 | |||
3763 | 64 | _errmsg = 'No such cruft: {0.cruft_name}' | ||
3764 | 65 | |||
3765 | 66 | |||
3766 | 67 | class LandmarkPackageError(DBusServiceBaseException): | ||
3767 | 68 | """Base class for problems with the landmark packages.""" | ||
3768 | 69 | |||
3769 | 70 | _errmsg = None | ||
3770 | 71 | |||
3771 | 72 | def __init__(self, package): | ||
3772 | 73 | self.package = package | ||
3773 | 74 | |||
3774 | 75 | def __str__(self): | ||
3775 | 76 | # gettext translation needs to be called at run time. | ||
3776 | 77 | return self._errmsg.format(self) | ||
3777 | 78 | |||
3778 | 79 | |||
3779 | 80 | class MissingLandmarkError(LandmarkPackageError): | ||
3780 | 81 | """A landmark package could not be found.""" | ||
3781 | 82 | |||
3782 | 83 | _errmsg = 'Landmark package {0.package} is missing' | ||
3783 | 84 | |||
3784 | 85 | |||
3785 | 86 | class NonDownloadableError(LandmarkPackageError): | ||
3786 | 87 | """A landmark package is not downloadable.""" | ||
3787 | 88 | |||
3788 | 89 | _errmsg = 'Landmark package {0.package} is not downloadable' | ||
3789 | 90 | |||
3790 | 91 | |||
3791 | 92 | class PackageCleanupError(DBusServiceBaseException): | ||
3792 | 93 | """Could not complete plugin post-cleanup.""" | ||
3793 | 94 | |||
3794 | 95 | _errmsg = 'Post-cleanup exception' | ||
3795 | 0 | 96 | ||
3796 | === added file 'computerjanitord/main.py' | |||
3797 | --- computerjanitord/main.py 1970-01-01 00:00:00 +0000 | |||
3798 | +++ computerjanitord/main.py 2011-02-28 19:09:32 +0000 | |||
3799 | @@ -0,0 +1,120 @@ | |||
3800 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3801 | 2 | # | ||
3802 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3803 | 4 | # it under the terms of the GNU General Public License as published by | ||
3804 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3805 | 6 | # | ||
3806 | 7 | # This program is distributed in the hope that it will be useful, | ||
3807 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3808 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3809 | 10 | # GNU General Public License for more details. | ||
3810 | 11 | # | ||
3811 | 12 | # You should have received a copy of the GNU General Public License | ||
3812 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3813 | 14 | |||
3814 | 15 | """Main entry point for Computer Janitor dbus daemon.""" | ||
3815 | 16 | |||
3816 | 17 | from __future__ import absolute_import, unicode_literals | ||
3817 | 18 | |||
3818 | 19 | __metaclass__ = type | ||
3819 | 20 | __all__ = [ | ||
3820 | 21 | 'main', | ||
3821 | 22 | ] | ||
3822 | 23 | |||
3823 | 24 | |||
3824 | 25 | import os | ||
3825 | 26 | import gobject | ||
3826 | 27 | import logging | ||
3827 | 28 | import argparse | ||
3828 | 29 | import warnings | ||
3829 | 30 | import dbus.mainloop.glib | ||
3830 | 31 | import logging.handlers | ||
3831 | 32 | |||
3832 | 33 | from computerjanitorapp import __version__, setup_gettext | ||
3833 | 34 | from computerjanitord.service import Service | ||
3834 | 35 | |||
3835 | 36 | _ = setup_gettext() | ||
3836 | 37 | |||
3837 | 38 | |||
3838 | 39 | # 2010-02-09 barry: computerjanitor.package_cruft has a DeprecationWarning, | ||
3839 | 40 | # but that really needs to be fixed in that package, which in turn needs to be | ||
3840 | 41 | # ripped out of update-manager. | ||
3841 | 42 | warnings.filterwarnings('ignore', category=DeprecationWarning, | ||
3842 | 43 | module='computerjanitor.package_cruft') | ||
3843 | 44 | |||
3844 | 45 | |||
3845 | 46 | # As per aptdaemon, when run as a dbus service, we must add the necessary | ||
3846 | 47 | # paths to $PATH. | ||
3847 | 48 | REQUIRED_PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' | ||
3848 | 49 | |||
3849 | 50 | |||
3850 | 51 | class Options: | ||
3851 | 52 | """Command line options.""" | ||
3852 | 53 | |||
3853 | 54 | def __init__(self): | ||
3854 | 55 | self.parser = argparse.ArgumentParser( | ||
3855 | 56 | description=_("""\ | ||
3856 | 57 | Computer janitor dbus daemon. You must run this daemon as root. | ||
3857 | 58 | """)) | ||
3858 | 59 | self.parser.add_argument( | ||
3859 | 60 | '--version', action='version', | ||
3860 | 61 | version=_('Computer Janitor dbus daemon {version}'.format( | ||
3861 | 62 | version=__version__))) | ||
3862 | 63 | self.parser.add_argument( | ||
3863 | 64 | '-n', '--dry-run', action='store_true', | ||
3864 | 65 | help=_("""\ | ||
3865 | 66 | Only pretend to do anything permanent. This is useful for testing | ||
3866 | 67 | and debugging.""")) | ||
3867 | 68 | self.parser.add_argument( | ||
3868 | 69 | '-f', '--state-file', metavar='FILE', | ||
3869 | 70 | help=_('Store ignored state in FILE instead of the default.')) | ||
3870 | 71 | self.arguments = self.parser.parse_args() | ||
3871 | 72 | |||
3872 | 73 | |||
3873 | 74 | class ASCIIFormatter(logging.Formatter): | ||
3874 | 75 | """Force the log messages to ASCII.""" | ||
3875 | 76 | def format(self, record): | ||
3876 | 77 | message = logging.Formatter.format(self, record) | ||
3877 | 78 | return message.encode('ascii', 'replace') | ||
3878 | 79 | |||
3879 | 80 | |||
3880 | 81 | def main(): | ||
3881 | 82 | """Main entry point.""" | ||
3882 | 83 | # Set up logging. | ||
3883 | 84 | if os.environ.get('COMPUTER_JANITOR_DEBUG') is not None: | ||
3884 | 85 | level = logging.DEBUG | ||
3885 | 86 | else: | ||
3886 | 87 | level = logging.INFO | ||
3887 | 88 | # When running under dbus, $PATH will not be set. However it must be in | ||
3888 | 89 | # order to find dpkg(1) and friends. Hard code it in the same way that | ||
3889 | 90 | # aptdaemon does. | ||
3890 | 91 | if os.environ.get('PATH') is None: | ||
3891 | 92 | os.putenv('PATH', REQUIRED_PATH) | ||
3892 | 93 | logging.basicConfig(level=level) | ||
3893 | 94 | log = logging.getLogger('computerjanitor') | ||
3894 | 95 | # SysLogHandler does not recognize unicode arguments. | ||
3895 | 96 | syslog = logging.handlers.SysLogHandler(b'/dev/log') | ||
3896 | 97 | # syslog will provide a timestamp. | ||
3897 | 98 | formatter = ASCIIFormatter('computerjanitord:%(levelname)s: %(message)s') | ||
3898 | 99 | syslog.setFormatter(formatter) | ||
3899 | 100 | syslog.setLevel(level) | ||
3900 | 101 | log.addHandler(syslog) | ||
3901 | 102 | options = Options() | ||
3902 | 103 | # Ensure that we're running as root. Do this here instead of ../janitord | ||
3903 | 104 | # so that we can still run 'janitord --version' and 'janitord --help' as | ||
3904 | 105 | # non-root. | ||
3905 | 106 | if os.getuid() != 0: | ||
3906 | 107 | options.parser.error('You must run this as root') | ||
3907 | 108 | # No return. | ||
3908 | 109 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | ||
3909 | 110 | # pyflakes complains about this line, but we need it anyway to keep the | ||
3910 | 111 | # dbus service object referenced during the running of the main loop. | ||
3911 | 112 | server = Service(options) | ||
3912 | 113 | try: | ||
3913 | 114 | gobject.MainLoop().run() | ||
3914 | 115 | except KeyboardInterrupt: | ||
3915 | 116 | pass | ||
3916 | 117 | |||
3917 | 118 | |||
3918 | 119 | if __name__ == '__main__': | ||
3919 | 120 | main() | ||
3920 | 0 | 121 | ||
3921 | === added file 'computerjanitord/service.py' | |||
3922 | --- computerjanitord/service.py 1970-01-01 00:00:00 +0000 | |||
3923 | +++ computerjanitord/service.py 2011-02-28 19:09:32 +0000 | |||
3924 | @@ -0,0 +1,288 @@ | |||
3925 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
3926 | 2 | # | ||
3927 | 3 | # This program is free software: you can redistribute it and/or modify | ||
3928 | 4 | # it under the terms of the GNU General Public License as published by | ||
3929 | 5 | # the Free Software Foundation, version 3 of the License. | ||
3930 | 6 | # | ||
3931 | 7 | # This program is distributed in the hope that it will be useful, | ||
3932 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3933 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3934 | 10 | # GNU General Public License for more details. | ||
3935 | 11 | # | ||
3936 | 12 | # You should have received a copy of the GNU General Public License | ||
3937 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3938 | 14 | |||
3939 | 15 | """dbus service for cleaning up crufty packages that are no longer needed.""" | ||
3940 | 16 | |||
3941 | 17 | |||
3942 | 18 | from __future__ import absolute_import, unicode_literals | ||
3943 | 19 | |||
3944 | 20 | __metaclass__ = type | ||
3945 | 21 | __all__ = [ | ||
3946 | 22 | 'Service', | ||
3947 | 23 | ] | ||
3948 | 24 | |||
3949 | 25 | |||
3950 | 26 | import atexit | ||
3951 | 27 | import logging | ||
3952 | 28 | |||
3953 | 29 | import glib | ||
3954 | 30 | import dbus.service | ||
3955 | 31 | |||
3956 | 32 | from computerjanitord.application import Application | ||
3957 | 33 | from computerjanitord.authenticator import Authenticator | ||
3958 | 34 | from computerjanitord.collector import Collector | ||
3959 | 35 | from computerjanitord.errors import NoSuchCruftError, PermissionDeniedError | ||
3960 | 36 | from computerjanitord.state import State, DEFAULT_STATE_FILE | ||
3961 | 37 | |||
3962 | 38 | |||
3963 | 39 | log = logging.getLogger('computerjanitor') | ||
3964 | 40 | MISSING = object() | ||
3965 | 41 | |||
3966 | 42 | DBUS_INTERFACE_NAME = 'com.ubuntu.ComputerJanitor' | ||
3967 | 43 | PRIVILEGE = 'com.ubuntu.computerjanitor.updatesystem' | ||
3968 | 44 | |||
3969 | 45 | |||
3970 | 46 | class Service(dbus.service.Object): | ||
3971 | 47 | """Backend dbus service that handles removing crufty packages.""" | ||
3972 | 48 | |||
3973 | 49 | def __init__(self, options): | ||
3974 | 50 | """Create the dbus service. | ||
3975 | 51 | |||
3976 | 52 | :param options: The command line options class. | ||
3977 | 53 | :type options: `Options` | ||
3978 | 54 | """ | ||
3979 | 55 | self.dry_run = options.arguments.dry_run | ||
3980 | 56 | self.state_file = (DEFAULT_STATE_FILE | ||
3981 | 57 | if options.arguments.state_file is None | ||
3982 | 58 | else options.arguments.state_file) | ||
3983 | 59 | self.application = Application() | ||
3984 | 60 | self.state = State() | ||
3985 | 61 | self.state.load(self.state_file) | ||
3986 | 62 | self.collector = Collector(self.application, service=self) | ||
3987 | 63 | self.authenticator = Authenticator() | ||
3988 | 64 | bus_name = dbus.service.BusName( | ||
3989 | 65 | DBUS_INTERFACE_NAME, bus=dbus.SystemBus()) | ||
3990 | 66 | dbus.service.Object.__init__(self, bus_name, '/') | ||
3991 | 67 | # We can't use the decorator because that doesn't work with methods; | ||
3992 | 68 | # self doesn't get passed to the handler. | ||
3993 | 69 | atexit.register(self._exit_handler) | ||
3994 | 70 | |||
3995 | 71 | def _exit_handler(self): | ||
3996 | 72 | """Ensure that the state file is saved at exit.""" | ||
3997 | 73 | if not self.dry_run: | ||
3998 | 74 | self.state.save(self.state_file) | ||
3999 | 75 | |||
4000 | 76 | def _authenticate(self, sender, connection): | ||
4001 | 77 | """Authenticate via PolicyKit. | ||
4002 | 78 | |||
4003 | 79 | :param sender: The dbus client sender. | ||
4004 | 80 | :param connection: The dbus client connection. | ||
4005 | 81 | :raises PermissionDeniedError: when the authentication fails. | ||
4006 | 82 | """ | ||
4007 | 83 | if not self.authenticator.authenticate(sender, connection, PRIVILEGE): | ||
4008 | 84 | log.error('Permission denied: {0} for {1} on {2}'.format( | ||
4009 | 85 | PRIVILEGE, sender, connection)) | ||
4010 | 86 | raise PermissionDeniedError(PRIVILEGE) | ||
4011 | 87 | log.debug('Permission granted: {0} for {1} on {2}'.format( | ||
4012 | 88 | PRIVILEGE, sender, connection)) | ||
4013 | 89 | |||
4014 | 90 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4015 | 91 | out_signature='as') | ||
4016 | 92 | def find(self): | ||
4017 | 93 | """Find all the non-whitelisted cruft on the system. | ||
4018 | 94 | |||
4019 | 95 | Because this is a read-only interface it does not need authorization | ||
4020 | 96 | to be called. | ||
4021 | 97 | |||
4022 | 98 | :return: A list of matching cruft names. | ||
4023 | 99 | """ | ||
4024 | 100 | return list(cruft.get_name() for cruft in self.collector.cruft) | ||
4025 | 101 | |||
4026 | 102 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4027 | 103 | out_signature='b') | ||
4028 | 104 | def find_async(self): | ||
4029 | 105 | """Find all the non-whitelisted cruft on the system, asynchronously. | ||
4030 | 106 | |||
4031 | 107 | Because this is a read-only interface it does not need authorization | ||
4032 | 108 | to be called. Use this method when you can't wait for the cruft | ||
4033 | 109 | searching process to complete, since it might take some time. To | ||
4034 | 110 | respond when the cruft has been found, set up a `find_finished` signal | ||
4035 | 111 | handler. | ||
4036 | 112 | |||
4037 | 113 | :return: True | ||
4038 | 114 | """ | ||
4039 | 115 | glib.timeout_add_seconds(1, self._find_async) | ||
4040 | 116 | return True | ||
4041 | 117 | |||
4042 | 118 | def _find_async(self): | ||
4043 | 119 | """Find all cruft asynchronously and call the signal handler.""" | ||
4044 | 120 | cruft = list(cruft.get_name() for cruft in self.collector.cruft) | ||
4045 | 121 | self.find_finished(cruft) | ||
4046 | 122 | # Only call the callback once. | ||
4047 | 123 | return False | ||
4048 | 124 | |||
4049 | 125 | @dbus.service.signal(DBUS_INTERFACE_NAME, signature='as') | ||
4050 | 126 | def find_finished(self, cruft): | ||
4051 | 127 | """dbus signal called when `_find_async()` completes.""" | ||
4052 | 128 | log.debug('find_finished: {0}'.format(cruft)) | ||
4053 | 129 | |||
4054 | 130 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4055 | 131 | out_signature='as', | ||
4056 | 132 | # Must wrap these in str() because Python < 2.6.5 | ||
4057 | 133 | # does not like unicode keyword arguments. | ||
4058 | 134 | sender_keyword=str('sender'), | ||
4059 | 135 | connection_keyword=str('connection')) | ||
4060 | 136 | def load(self, sender=None, connection=None): | ||
4061 | 137 | """Load the state file.""" | ||
4062 | 138 | self._authenticate(sender, connection) | ||
4063 | 139 | self.state.load(self.state_file) | ||
4064 | 140 | return list(self.state.ignore) | ||
4065 | 141 | |||
4066 | 142 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4067 | 143 | # Must wrap these in str() because Python < 2.6.5 | ||
4068 | 144 | # does not like unicode keyword arguments. | ||
4069 | 145 | sender_keyword=str('sender'), | ||
4070 | 146 | connection_keyword=str('connection')) | ||
4071 | 147 | def save(self, sender=None, connection=None): | ||
4072 | 148 | """Save the state file.""" | ||
4073 | 149 | self._authenticate(sender, connection) | ||
4074 | 150 | if not self.dry_run: | ||
4075 | 151 | self.state.save(self.state_file) | ||
4076 | 152 | |||
4077 | 153 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4078 | 154 | in_signature='s', | ||
4079 | 155 | # Must wrap these in str() because Python < 2.6.5 | ||
4080 | 156 | # does not like unicode keyword arguments. | ||
4081 | 157 | sender_keyword=str('sender'), | ||
4082 | 158 | connection_keyword=str('connection')) | ||
4083 | 159 | def ignore(self, name, sender=None, connection=None): | ||
4084 | 160 | """Ignore the named cruft. | ||
4085 | 161 | |||
4086 | 162 | :param name: The name of the cruft to ignore. | ||
4087 | 163 | :type filename: string | ||
4088 | 164 | """ | ||
4089 | 165 | # Make sure this is known cruft first. | ||
4090 | 166 | cruft = self.collector.cruft_by_name.get(name, MISSING) | ||
4091 | 167 | if cruft is MISSING: | ||
4092 | 168 | log.error('ignore(): No such cruft: {0}'.format(name)) | ||
4093 | 169 | raise NoSuchCruftError(name) | ||
4094 | 170 | self._authenticate(sender, connection) | ||
4095 | 171 | if not self.dry_run: | ||
4096 | 172 | self.state.ignore.add(name) | ||
4097 | 173 | |||
4098 | 174 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4099 | 175 | in_signature='s', | ||
4100 | 176 | # Must wrap these in str() because Python < 2.6.5 | ||
4101 | 177 | # does not like unicode keyword arguments. | ||
4102 | 178 | sender_keyword=str('sender'), | ||
4103 | 179 | connection_keyword=str('connection')) | ||
4104 | 180 | def unignore(self, name, sender=None, connection=None): | ||
4105 | 181 | """Unignore the named cruft. | ||
4106 | 182 | |||
4107 | 183 | :param name: The name of the cruft to unignore. | ||
4108 | 184 | :type filename: string | ||
4109 | 185 | """ | ||
4110 | 186 | cruft = self.collector.cruft_by_name.get(name, MISSING) | ||
4111 | 187 | if cruft is MISSING: | ||
4112 | 188 | log.error('ignore(): No such cruft: {0}'.format(name)) | ||
4113 | 189 | raise NoSuchCruftError(name) | ||
4114 | 190 | self._authenticate(sender, connection) | ||
4115 | 191 | if not self.dry_run: | ||
4116 | 192 | # Don't worry if we're already not ignoring the cruft (i.e. don't | ||
4117 | 193 | # raise a KeyError here if 'name' is not in the set). | ||
4118 | 194 | self.state.ignore.discard(name) | ||
4119 | 195 | |||
4120 | 196 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4121 | 197 | out_signature='as') | ||
4122 | 198 | def ignored(self): | ||
4123 | 199 | """Return the list of ignored cruft. | ||
4124 | 200 | |||
4125 | 201 | :return: The names of the ignored cruft. | ||
4126 | 202 | :rtype: list of strings | ||
4127 | 203 | """ | ||
4128 | 204 | return list(self.state.ignore) | ||
4129 | 205 | |||
4130 | 206 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4131 | 207 | in_signature='s', | ||
4132 | 208 | out_signature='s') | ||
4133 | 209 | def get_description(self, name): | ||
4134 | 210 | """Return the description of the named cruft. | ||
4135 | 211 | |||
4136 | 212 | :param name: The cruft name. | ||
4137 | 213 | :type name: string | ||
4138 | 214 | :return: The description of the cruft. | ||
4139 | 215 | :rtype: string | ||
4140 | 216 | """ | ||
4141 | 217 | cruft = self.collector.cruft_by_name.get(name, MISSING) | ||
4142 | 218 | if cruft is MISSING: | ||
4143 | 219 | log.error('get_description(): No such cruft: {0}'.format(name)) | ||
4144 | 220 | raise NoSuchCruftError(name) | ||
4145 | 221 | return cruft.get_description() | ||
4146 | 222 | |||
4147 | 223 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4148 | 224 | in_signature='s', | ||
4149 | 225 | out_signature='s') | ||
4150 | 226 | def get_shortname(self, name): | ||
4151 | 227 | """Return the short name of the named cruft. | ||
4152 | 228 | |||
4153 | 229 | :param name: The cruft name. | ||
4154 | 230 | :type name: string | ||
4155 | 231 | :return: The short nameof the cruft. | ||
4156 | 232 | :rtype: string | ||
4157 | 233 | """ | ||
4158 | 234 | cruft = self.collector.cruft_by_name.get(name, MISSING) | ||
4159 | 235 | if cruft is MISSING: | ||
4160 | 236 | log.error('get_shortname(): No such cruft: {0}'.format(name)) | ||
4161 | 237 | raise NoSuchCruftError(name) | ||
4162 | 238 | return cruft.get_shortname() | ||
4163 | 239 | |||
4164 | 240 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4165 | 241 | in_signature='s', | ||
4166 | 242 | out_signature='st') | ||
4167 | 243 | def get_details(self, name): | ||
4168 | 244 | """Return some extra details about the named cruft. | ||
4169 | 245 | |||
4170 | 246 | :param name: The cruft name. | ||
4171 | 247 | :type name: string | ||
4172 | 248 | :return: Some extra details about the named cruft, specifically its | ||
4173 | 249 | 'type' and the amount of disk space it consumes. The type is | ||
4174 | 250 | simply the name of the cruft instance's class. | ||
4175 | 251 | :rtype: string, uint64 | ||
4176 | 252 | """ | ||
4177 | 253 | cruft = self.collector.cruft_by_name.get(name, MISSING) | ||
4178 | 254 | if cruft is MISSING: | ||
4179 | 255 | log.error('get_shortname(): No such cruft: {0}'.format(name)) | ||
4180 | 256 | raise NoSuchCruftError(name) | ||
4181 | 257 | return cruft.__class__.__name__, cruft.get_disk_usage() | ||
4182 | 258 | |||
4183 | 259 | @dbus.service.method(DBUS_INTERFACE_NAME, | ||
4184 | 260 | in_signature='as', # array of strings | ||
4185 | 261 | # Must wrap these in str() because Python < 2.6.5 | ||
4186 | 262 | # does not like unicode keyword arguments. | ||
4187 | 263 | sender_keyword=str('sender'), | ||
4188 | 264 | connection_keyword=str('connection')) | ||
4189 | 265 | def clean(self, names, sender=None, connection=None): | ||
4190 | 266 | """Clean the named crufts. | ||
4191 | 267 | |||
4192 | 268 | :param names: The names of the cruft to clean. | ||
4193 | 269 | :type names: list of strings | ||
4194 | 270 | """ | ||
4195 | 271 | self._authenticate(sender, connection) | ||
4196 | 272 | self.collector.clean(names, self.dry_run) | ||
4197 | 273 | |||
4198 | 274 | @dbus.service.signal(DBUS_INTERFACE_NAME, | ||
4199 | 275 | signature='s') | ||
4200 | 276 | def cleanup_status(self, cruft): | ||
4201 | 277 | """Signal cleanup status. | ||
4202 | 278 | |||
4203 | 279 | This signal is used to incrementally inform clients that some cleanup | ||
4204 | 280 | work is being done. It is called at the beginning of the cleanup | ||
4205 | 281 | process and after each plugin has completed its `post_cleanup()` | ||
4206 | 282 | method. | ||
4207 | 283 | |||
4208 | 284 | :param done: The name of the next piece of cruft to be cleaned up, or | ||
4209 | 285 | the empty string when there's nothing left to do. | ||
4210 | 286 | :type done: string | ||
4211 | 287 | """ | ||
4212 | 288 | log.debug('cleanup_status: {0}'.format(cruft)) | ||
4213 | 0 | 289 | ||
4214 | === added file 'computerjanitord/state.py' | |||
4215 | --- computerjanitord/state.py 1970-01-01 00:00:00 +0000 | |||
4216 | +++ computerjanitord/state.py 2011-02-28 19:09:32 +0000 | |||
4217 | @@ -0,0 +1,92 @@ | |||
4218 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4219 | 2 | # | ||
4220 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4221 | 4 | # it under the terms of the GNU General Public License as published by | ||
4222 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4223 | 6 | # | ||
4224 | 7 | # This program is distributed in the hope that it will be useful, | ||
4225 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4226 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4227 | 10 | # GNU General Public License for more details. | ||
4228 | 11 | # | ||
4229 | 12 | # You should have received a copy of the GNU General Public License | ||
4230 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4231 | 14 | |||
4232 | 15 | """Maintaining package ignored state.""" | ||
4233 | 16 | |||
4234 | 17 | from __future__ import absolute_import, unicode_literals | ||
4235 | 18 | |||
4236 | 19 | __metaclass__ = type | ||
4237 | 20 | __all__ = [ | ||
4238 | 21 | 'DEFAULT_STATE_FILE', | ||
4239 | 22 | 'State', | ||
4240 | 23 | ] | ||
4241 | 24 | |||
4242 | 25 | |||
4243 | 26 | import ConfigParser | ||
4244 | 27 | import textwrap | ||
4245 | 28 | |||
4246 | 29 | |||
4247 | 30 | DEFAULT_STATE_FILE = '/var/lib/computer-janitor/state.dat' | ||
4248 | 31 | |||
4249 | 32 | |||
4250 | 33 | class State: | ||
4251 | 34 | """Maintain the state of cruft which should be ignored. | ||
4252 | 35 | |||
4253 | 36 | The file's format is a `ConfigParser` style .ini file. Each section is a | ||
4254 | 37 | cruft's `.get_name()` value and contains a single boolean setting | ||
4255 | 38 | `ignore`. If true, then the cruft is ignored. | ||
4256 | 39 | |||
4257 | 40 | For backward compatibility purposes, the setting `enabled` is also | ||
4258 | 41 | recognized (on read only). If `enabled` is false then the cruft is | ||
4259 | 42 | ignored. | ||
4260 | 43 | """ | ||
4261 | 44 | |||
4262 | 45 | def __init__(self): | ||
4263 | 46 | self.ignore = set() | ||
4264 | 47 | |||
4265 | 48 | def load(self, filename): | ||
4266 | 49 | """Load ignored state from a file. | ||
4267 | 50 | |||
4268 | 51 | This reset any previously determined state and re-initializes it with | ||
4269 | 52 | the state stored in the file. | ||
4270 | 53 | |||
4271 | 54 | :param filename: The file to load. | ||
4272 | 55 | :type filename: string | ||
4273 | 56 | """ | ||
4274 | 57 | parser = ConfigParser.ConfigParser() | ||
4275 | 58 | parser.read(filename) | ||
4276 | 59 | # Reset the set of ignored packages. | ||
4277 | 60 | self.ignore = set() | ||
4278 | 61 | for cruft_name in parser.sections(): | ||
4279 | 62 | # For backwards compatibility, recognize both the 'ignore' setting | ||
4280 | 63 | # and the 'enabled' setting. We only write the former. | ||
4281 | 64 | try: | ||
4282 | 65 | ignore = parser.getboolean(cruft_name, 'ignore') | ||
4283 | 66 | except ConfigParser.NoOptionError: | ||
4284 | 67 | try: | ||
4285 | 68 | ignore = not parser.getboolean(cruft_name, 'enabled') | ||
4286 | 69 | except ConfigParser.NoOptionError: | ||
4287 | 70 | # No other settings are recognized. | ||
4288 | 71 | ignore = False | ||
4289 | 72 | if ignore: | ||
4290 | 73 | self.ignore.add(cruft_name) | ||
4291 | 74 | |||
4292 | 75 | def save(self, filename): | ||
4293 | 76 | """Save the ignored state to a file. | ||
4294 | 77 | |||
4295 | 78 | Only the packages being ignored are stored to the file, and writing | ||
4296 | 79 | overwrites the previous contents of the file. | ||
4297 | 80 | |||
4298 | 81 | :param filename: The file to load. | ||
4299 | 82 | :type filename: string | ||
4300 | 83 | """ | ||
4301 | 84 | # It's easier just to write the .ini file directly instead of using | ||
4302 | 85 | # the ConfigParser interface. This way we can guarantee sort order | ||
4303 | 86 | # and can automatically cull unignored packages from the file. | ||
4304 | 87 | with open(filename, 'w') as fp: | ||
4305 | 88 | for cruft_name in self.ignore: | ||
4306 | 89 | print >> fp, textwrap.dedent("""\ | ||
4307 | 90 | [{0}] | ||
4308 | 91 | ignore: true | ||
4309 | 92 | """.format(cruft_name)) | ||
4310 | 0 | 93 | ||
4311 | === added directory 'computerjanitord/tests' | |||
4312 | === added file 'computerjanitord/tests/__init__.py' | |||
4313 | === added directory 'computerjanitord/tests/data' | |||
4314 | === added file 'computerjanitord/tests/data/empty' | |||
4315 | === added directory 'computerjanitord/tests/data/etc' | |||
4316 | === added directory 'computerjanitord/tests/data/etc/apt' | |||
4317 | === added file 'computerjanitord/tests/data/etc/apt/sources.list' | |||
4318 | --- computerjanitord/tests/data/etc/apt/sources.list 1970-01-01 00:00:00 +0000 | |||
4319 | +++ computerjanitord/tests/data/etc/apt/sources.list 2011-02-28 19:09:32 +0000 | |||
4320 | @@ -0,0 +1,1 @@ | |||
4321 | 1 | deb http://archive.ubuntu.com/ubuntu intrepid main restricted | ||
4322 | 0 | 2 | ||
4323 | === added directory 'computerjanitord/tests/data/var' | |||
4324 | === added directory 'computerjanitord/tests/data/var/cache' | |||
4325 | === added directory 'computerjanitord/tests/data/var/cache/apt' | |||
4326 | === added directory 'computerjanitord/tests/data/var/cache/apt/archives' | |||
4327 | === added directory 'computerjanitord/tests/data/var/cache/apt/archives/partial' | |||
4328 | === added directory 'computerjanitord/tests/data/var/lib' | |||
4329 | === added directory 'computerjanitord/tests/data/var/lib/apt' | |||
4330 | === added directory 'computerjanitord/tests/data/var/lib/apt/lists' | |||
4331 | === added file 'computerjanitord/tests/data/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_intrepid_restricted_binary-i386_Packages' | |||
4332 | --- computerjanitord/tests/data/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_intrepid_restricted_binary-i386_Packages 1970-01-01 00:00:00 +0000 | |||
4333 | +++ computerjanitord/tests/data/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_intrepid_restricted_binary-i386_Packages 2011-02-28 19:09:32 +0000 | |||
4334 | @@ -0,0 +1,54 @@ | |||
4335 | 1 | Package: dash | ||
4336 | 2 | Priority: required | ||
4337 | 3 | Section: shells | ||
4338 | 4 | Installed-Size: 236 | ||
4339 | 5 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
4340 | 6 | Original-Maintainer: Gerrit Pape <pape@smarden.org> | ||
4341 | 7 | Architecture: all | ||
4342 | 8 | Version: 0.5.5.1-3ubuntu1 | ||
4343 | 9 | Depends: debianutils (>= 2.15), dpkg (>= 1.15.0) | ||
4344 | 10 | Pre-Depends: libc6 (>= 2.11~20100104-0ubuntu2) | ||
4345 | 11 | Filename: pool/main/d/dash/dash_0.5.5.1-3ubuntu1_all.deb | ||
4346 | 12 | Size: 104190 | ||
4347 | 13 | MD5sum: a7f08fe3ee941d06c0d98e5e99c02190 | ||
4348 | 14 | SHA1: d2dda78f9a6f82c58c01d34f18b94aebfcb33f19 | ||
4349 | 15 | SHA256: 69709747f854ac1bd671dff37b47c18e589b095ecb8f3116beaed7fc0eeb657e | ||
4350 | 16 | Description: POSIX-compliant shell | ||
4351 | 17 | The Debian Almquist Shell (dash) is a POSIX-compliant shell derived | ||
4352 | 18 | from ash. | ||
4353 | 19 | . | ||
4354 | 20 | Since it executes scripts faster than bash, and has fewer library | ||
4355 | 21 | dependencies (making it more robust against software or hardware | ||
4356 | 22 | failures), it is used as the default system shell on Debian systems. | ||
4357 | 23 | Homepage: http://gondor.apana.org.au/~herbert/dash/ | ||
4358 | 24 | Bugs: https://bugs.launchpad.net/ubuntu/+filebug | ||
4359 | 25 | Origin: Ubuntu | ||
4360 | 26 | Supported: 5y | ||
4361 | 27 | Task: minimal | ||
4362 | 28 | |||
4363 | 29 | Package: gzip | ||
4364 | 30 | Essential: yes | ||
4365 | 31 | Priority: required | ||
4366 | 32 | Section: utils | ||
4367 | 33 | Installed-Size: 284 | ||
4368 | 34 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
4369 | 35 | Original-Maintainer: Bdale Garbee <bdale@gag.com> | ||
4370 | 36 | Architecture: all | ||
4371 | 37 | Version: 1.3.12-9ubuntu1 | ||
4372 | 38 | Pre-Depends: libc6 (>= 2.4) | ||
4373 | 39 | Suggests: less | ||
4374 | 40 | Filename: pool/main/g/gzip/gzip_1.3.12-9ubuntu1_all.deb | ||
4375 | 41 | Size: 107030 | ||
4376 | 42 | MD5sum: f64beb93d2d1a3348cfc47f1fd176ee1 | ||
4377 | 43 | SHA1: 3dd3e56f551fb85ba2ad385df463adeff1fff2d9 | ||
4378 | 44 | SHA256: 2545f0a28514535006adf9ee8576ca3be2aa6da3d890047f92eeda18c0e3aa57 | ||
4379 | 45 | Description: GNU compression utilities | ||
4380 | 46 | This package provides the standard GNU file compression utilities, which | ||
4381 | 47 | are also the default compression tools for Debian. They typically operate | ||
4382 | 48 | on files with names ending in '.gz', but can also decompress files ending | ||
4383 | 49 | in '.Z' created with 'compress'. | ||
4384 | 50 | Bugs: https://bugs.launchpad.net/ubuntu/+filebug | ||
4385 | 51 | Origin: Ubuntu | ||
4386 | 52 | Supported: 5y | ||
4387 | 53 | Task: minimal | ||
4388 | 54 | |||
4389 | 0 | 55 | ||
4390 | === added directory 'computerjanitord/tests/data/var/lib/apt/lists/partial' | |||
4391 | === added directory 'computerjanitord/tests/data/var/lib/dpkg' | |||
4392 | === added file 'computerjanitord/tests/data/var/lib/dpkg/status' | |||
4393 | --- computerjanitord/tests/data/var/lib/dpkg/status 1970-01-01 00:00:00 +0000 | |||
4394 | +++ computerjanitord/tests/data/var/lib/dpkg/status 2011-02-28 19:09:32 +0000 | |||
4395 | @@ -0,0 +1,28 @@ | |||
4396 | 1 | Package: dash-nodownload | ||
4397 | 2 | Priority: required | ||
4398 | 3 | Section: shells | ||
4399 | 4 | Installed-Size: 236 | ||
4400 | 5 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
4401 | 6 | Original-Maintainer: Gerrit Pape <pape@smarden.org> | ||
4402 | 7 | Architecture: all | ||
4403 | 8 | Version: 0.5.5.1-3ubuntu1 | ||
4404 | 9 | Depends: debianutils (>= 2.15), dpkg (>= 1.15.0) | ||
4405 | 10 | Pre-Depends: libc6 (>= 2.11~20100104-0ubuntu2) | ||
4406 | 11 | Filename: pool/main/d/dash/dash_0.5.5.1-3ubuntu1_all.deb | ||
4407 | 12 | Size: 104190 | ||
4408 | 13 | MD5sum: a7f08fe3ee941d06c0d98e5e99c02190 | ||
4409 | 14 | SHA1: d2dda78f9a6f82c58c01d34f18b94aebfcb33f19 | ||
4410 | 15 | SHA256: 69709747f854ac1bd671dff37b47c18e589b095ecb8f3116beaed7fc0eeb657e | ||
4411 | 16 | Description: POSIX-compliant shell | ||
4412 | 17 | The Debian Almquist Shell (dash) is a POSIX-compliant shell derived | ||
4413 | 18 | from ash. | ||
4414 | 19 | . | ||
4415 | 20 | Since it executes scripts faster than bash, and has fewer library | ||
4416 | 21 | dependencies (making it more robust against software or hardware | ||
4417 | 22 | failures), it is used as the default system shell on Debian systems. | ||
4418 | 23 | Homepage: http://gondor.apana.org.au/~herbert/dash/ | ||
4419 | 24 | Bugs: https://bugs.launchpad.net/ubuntu/+filebug | ||
4420 | 25 | Origin: Ubuntu | ||
4421 | 26 | Supported: 5y | ||
4422 | 27 | Task: minimal | ||
4423 | 28 | |||
4424 | 0 | 29 | ||
4425 | === added file 'computerjanitord/tests/test_all.py' | |||
4426 | --- computerjanitord/tests/test_all.py 1970-01-01 00:00:00 +0000 | |||
4427 | +++ computerjanitord/tests/test_all.py 2011-02-28 19:09:32 +0000 | |||
4428 | @@ -0,0 +1,41 @@ | |||
4429 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4430 | 2 | # | ||
4431 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4432 | 4 | # it under the terms of the GNU General Public License as published by | ||
4433 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4434 | 6 | # | ||
4435 | 7 | # This program is distributed in the hope that it will be useful, | ||
4436 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4437 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4438 | 10 | # GNU General Public License for more details. | ||
4439 | 11 | # | ||
4440 | 12 | # You should have received a copy of the GNU General Public License | ||
4441 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4442 | 14 | |||
4443 | 15 | """Test suite for Computer Janitor daemon (dbus backend).""" | ||
4444 | 16 | |||
4445 | 17 | from __future__ import absolute_import, unicode_literals | ||
4446 | 18 | |||
4447 | 19 | __metaclass__ = type | ||
4448 | 20 | __all__ = [ | ||
4449 | 21 | 'test_suite', | ||
4450 | 22 | ] | ||
4451 | 23 | |||
4452 | 24 | |||
4453 | 25 | import unittest | ||
4454 | 26 | |||
4455 | 27 | from computerjanitord.tests import test_application | ||
4456 | 28 | from computerjanitord.tests import test_authenticator | ||
4457 | 29 | from computerjanitord.tests import test_collector | ||
4458 | 30 | from computerjanitord.tests import test_state | ||
4459 | 31 | from computerjanitord.tests import test_whitelist | ||
4460 | 32 | |||
4461 | 33 | |||
4462 | 34 | def test_suite(): | ||
4463 | 35 | suite = unittest.TestSuite() | ||
4464 | 36 | suite.addTests(test_application.test_suite()) | ||
4465 | 37 | suite.addTests(test_authenticator.test_suite()) | ||
4466 | 38 | suite.addTests(test_collector.test_suite()) | ||
4467 | 39 | suite.addTests(test_state.test_suite()) | ||
4468 | 40 | suite.addTests(test_whitelist.test_suite()) | ||
4469 | 41 | return suite | ||
4470 | 0 | 42 | ||
4471 | === added file 'computerjanitord/tests/test_application.py' | |||
4472 | --- computerjanitord/tests/test_application.py 1970-01-01 00:00:00 +0000 | |||
4473 | +++ computerjanitord/tests/test_application.py 2011-02-28 19:09:32 +0000 | |||
4474 | @@ -0,0 +1,105 @@ | |||
4475 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4476 | 2 | # | ||
4477 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4478 | 4 | # it under the terms of the GNU General Public License as published by | ||
4479 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4480 | 6 | # | ||
4481 | 7 | # This program is distributed in the hope that it will be useful, | ||
4482 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4483 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4484 | 10 | # GNU General Public License for more details. | ||
4485 | 11 | # | ||
4486 | 12 | # You should have received a copy of the GNU General Public License | ||
4487 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4488 | 14 | |||
4489 | 15 | """Test the plugin application interfaces.""" | ||
4490 | 16 | |||
4491 | 17 | from __future__ import absolute_import, unicode_literals | ||
4492 | 18 | |||
4493 | 19 | __metaclass__ = type | ||
4494 | 20 | __all__ = [ | ||
4495 | 21 | 'ApplicationTestSetupMixin', | ||
4496 | 22 | 'test_suite', | ||
4497 | 23 | ] | ||
4498 | 24 | |||
4499 | 25 | |||
4500 | 26 | import os | ||
4501 | 27 | import apt | ||
4502 | 28 | import apt_pkg | ||
4503 | 29 | import unittest | ||
4504 | 30 | import warnings | ||
4505 | 31 | import pkg_resources | ||
4506 | 32 | |||
4507 | 33 | from contextlib import contextmanager | ||
4508 | 34 | |||
4509 | 35 | import computerjanitord.application | ||
4510 | 36 | |||
4511 | 37 | from computerjanitord.application import ( | ||
4512 | 38 | Application, MissingLandmarkError, NonDownloadableError) | ||
4513 | 39 | |||
4514 | 40 | |||
4515 | 41 | @contextmanager | ||
4516 | 42 | def landmarks(*packages): | ||
4517 | 43 | # Hack the module global list of known landmark packages. | ||
4518 | 44 | old_landmarks = computerjanitord.application.LANDMARK_PACKAGES[:] | ||
4519 | 45 | computerjanitord.application.LANDMARK_PACKAGES[:] = packages | ||
4520 | 46 | yield | ||
4521 | 47 | computerjanitord.application.LANDMARK_PACKAGES[:] = old_landmarks | ||
4522 | 48 | |||
4523 | 49 | |||
4524 | 50 | class MockCruft: | ||
4525 | 51 | def __init__(self, name): | ||
4526 | 52 | self.name = name | ||
4527 | 53 | |||
4528 | 54 | def get_name(self): | ||
4529 | 55 | warnings.warn('.get_name() is deprecated; use .name', | ||
4530 | 56 | DeprecationWarning) | ||
4531 | 57 | return self.name | ||
4532 | 58 | |||
4533 | 59 | |||
4534 | 60 | class ApplicationTestSetupMixin: | ||
4535 | 61 | """Set up an `Application` instance with test data in its apt_cache.""" | ||
4536 | 62 | |||
4537 | 63 | def setUp(self): | ||
4538 | 64 | self.data_dir = os.path.abspath( | ||
4539 | 65 | pkg_resources.resource_filename('computerjanitord.tests', 'data')) | ||
4540 | 66 | # Make the test insensitive to the platform's architecture. | ||
4541 | 67 | apt_pkg.Config.set('APT::Architecture', 'i386') | ||
4542 | 68 | self.cache = apt.Cache(rootdir=self.data_dir) | ||
4543 | 69 | self.app = Application(self.cache) | ||
4544 | 70 | |||
4545 | 71 | def tearDown(self): | ||
4546 | 72 | # Clear the cache. | ||
4547 | 73 | cache_dir = os.path.join(self.data_dir, 'var', 'cache', 'apt') | ||
4548 | 74 | for filename in os.listdir(cache_dir): | ||
4549 | 75 | if filename.endswith('.bin'): | ||
4550 | 76 | os.remove(os.path.join(cache_dir, filename)) | ||
4551 | 77 | |||
4552 | 78 | |||
4553 | 79 | class TestApplication(unittest.TestCase, ApplicationTestSetupMixin): | ||
4554 | 80 | """Test the `Application` interface.""" | ||
4555 | 81 | |||
4556 | 82 | def setUp(self): | ||
4557 | 83 | ApplicationTestSetupMixin.setUp(self) | ||
4558 | 84 | |||
4559 | 85 | def tearDown(self): | ||
4560 | 86 | ApplicationTestSetupMixin.tearDown(self) | ||
4561 | 87 | |||
4562 | 88 | def test_verify_apt_cache_good_path(self): | ||
4563 | 89 | # All essential packages are in the cache by default. | ||
4564 | 90 | self.assertEqual(self.app.verify_apt_cache(), None) | ||
4565 | 91 | |||
4566 | 92 | def test_verify_apt_cache_with_nondownloadable_landmark(self): | ||
4567 | 93 | # Test that a missing landmark file causes an exception. | ||
4568 | 94 | with landmarks('gzip', 'dash-nodownload'): | ||
4569 | 95 | self.assertRaises(NonDownloadableError, self.app.verify_apt_cache) | ||
4570 | 96 | |||
4571 | 97 | def test_verify_apt_cache_with_missing_landmark(self): | ||
4572 | 98 | with landmarks('gzip', 'dash', 'i-am-not-here'): | ||
4573 | 99 | self.assertRaises(MissingLandmarkError, self.app.verify_apt_cache) | ||
4574 | 100 | |||
4575 | 101 | |||
4576 | 102 | def test_suite(): | ||
4577 | 103 | suite = unittest.TestSuite() | ||
4578 | 104 | suite.addTests(unittest.makeSuite(TestApplication)) | ||
4579 | 105 | return suite | ||
4580 | 0 | 106 | ||
4581 | === added file 'computerjanitord/tests/test_authenticator.py' | |||
4582 | --- computerjanitord/tests/test_authenticator.py 1970-01-01 00:00:00 +0000 | |||
4583 | +++ computerjanitord/tests/test_authenticator.py 2011-02-28 19:09:32 +0000 | |||
4584 | @@ -0,0 +1,97 @@ | |||
4585 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4586 | 2 | # | ||
4587 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4588 | 4 | # it under the terms of the GNU General Public License as published by | ||
4589 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4590 | 6 | # | ||
4591 | 7 | # This program is distributed in the hope that it will be useful, | ||
4592 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4593 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4594 | 10 | # GNU General Public License for more details. | ||
4595 | 11 | # | ||
4596 | 12 | # You should have received a copy of the GNU General Public License | ||
4597 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4598 | 14 | |||
4599 | 15 | """Test the authenticator.""" | ||
4600 | 16 | |||
4601 | 17 | import unittest | ||
4602 | 18 | |||
4603 | 19 | from computerjanitord.authenticator import Authenticator | ||
4604 | 20 | |||
4605 | 21 | SUCCESS_PID = 801 | ||
4606 | 22 | FAILURE_PID = 999 | ||
4607 | 23 | |||
4608 | 24 | AUTHENTICATED_USER = 'desktop-user' | ||
4609 | 25 | IMPOSTER_USER = 'imposter' | ||
4610 | 26 | EXPECTED_PRIVILEGE = 'com.ubuntu.computerjanitor.cleanpackages' | ||
4611 | 27 | BOGUS_PRIVILEGE = 'com.example.evil-corp.killsystem' | ||
4612 | 28 | |||
4613 | 29 | |||
4614 | 30 | class MockPolicyKit(object): | ||
4615 | 31 | """Mock the PolicyKit's CheckAuthorization() method.""" | ||
4616 | 32 | |||
4617 | 33 | def CheckAuthorization(self, subject, privilege, details, flags, | ||
4618 | 34 | cancellation_id): | ||
4619 | 35 | """See `policykit.CheckAuthorization()`. | ||
4620 | 36 | |||
4621 | 37 | :return: (is_authorized, is_challenge, details) | ||
4622 | 38 | """ | ||
4623 | 39 | if privilege == BOGUS_PRIVILEGE: | ||
4624 | 40 | return False, False, '' | ||
4625 | 41 | assert isinstance(subject, tuple) and len(subject) == 2, ( | ||
4626 | 42 | 'subject is not a 2-tuple') | ||
4627 | 43 | assert subject[0] == 'unix-process', 'Badly formed subject' | ||
4628 | 44 | assert isinstance(subject[1], dict), 'Badly formed subject details' | ||
4629 | 45 | assert subject[1]['start-time'] == 0, 'subject missing start-time' | ||
4630 | 46 | if subject[1]['pid'] == SUCCESS_PID: | ||
4631 | 47 | return True, False, '' | ||
4632 | 48 | else: | ||
4633 | 49 | return False, False, '' | ||
4634 | 50 | |||
4635 | 51 | |||
4636 | 52 | class TestableAuthenticator(Authenticator): | ||
4637 | 53 | """See `Authenticator`.""" | ||
4638 | 54 | |||
4639 | 55 | def _get_policykit_proxy(self): | ||
4640 | 56 | """See `Authenticator`.""" | ||
4641 | 57 | return MockPolicyKit() | ||
4642 | 58 | |||
4643 | 59 | def _get_sender_pid(self, connection, sender): | ||
4644 | 60 | """See `Authenticator`.""" | ||
4645 | 61 | if sender == AUTHENTICATED_USER: | ||
4646 | 62 | return SUCCESS_PID | ||
4647 | 63 | else: | ||
4648 | 64 | return FAILURE_PID | ||
4649 | 65 | |||
4650 | 66 | |||
4651 | 67 | class TestAuthenticator(unittest.TestCase): | ||
4652 | 68 | """Tests of the PolicyKit authenticator.""" | ||
4653 | 69 | |||
4654 | 70 | def setUp(self): | ||
4655 | 71 | """See `unittest.TestCase`.""" | ||
4656 | 72 | self.authenticator = TestableAuthenticator() | ||
4657 | 73 | self.connection = object() | ||
4658 | 74 | |||
4659 | 75 | def tearDown(self): | ||
4660 | 76 | """See `unittest.TestCase`.""" | ||
4661 | 77 | |||
4662 | 78 | def test_good_path(self): | ||
4663 | 79 | # Test for successful authentication. | ||
4664 | 80 | self.assertTrue(self.authenticator.authenticate( | ||
4665 | 81 | AUTHENTICATED_USER, self.connection, EXPECTED_PRIVILEGE)) | ||
4666 | 82 | |||
4667 | 83 | def test_bogus_privilege(self): | ||
4668 | 84 | # Test for bogus privilege fails. | ||
4669 | 85 | self.assertFalse(self.authenticator.authenticate( | ||
4670 | 86 | AUTHENTICATED_USER, self.connection, BOGUS_PRIVILEGE)) | ||
4671 | 87 | |||
4672 | 88 | def test_unauthorized(self): | ||
4673 | 89 | # Test for some imposter not being able to authenticate. | ||
4674 | 90 | self.assertFalse(self.authenticator.authenticate( | ||
4675 | 91 | IMPOSTER_USER, self.connection, EXPECTED_PRIVILEGE)) | ||
4676 | 92 | |||
4677 | 93 | |||
4678 | 94 | def test_suite(): | ||
4679 | 95 | suite = unittest.TestSuite() | ||
4680 | 96 | suite.addTests(unittest.makeSuite(TestAuthenticator)) | ||
4681 | 97 | return suite | ||
4682 | 0 | 98 | ||
4683 | === added file 'computerjanitord/tests/test_collector.py' | |||
4684 | --- computerjanitord/tests/test_collector.py 1970-01-01 00:00:00 +0000 | |||
4685 | +++ computerjanitord/tests/test_collector.py 2011-02-28 19:09:32 +0000 | |||
4686 | @@ -0,0 +1,225 @@ | |||
4687 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4688 | 2 | # | ||
4689 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4690 | 4 | # it under the terms of the GNU General Public License as published by | ||
4691 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4692 | 6 | # | ||
4693 | 7 | # This program is distributed in the hope that it will be useful, | ||
4694 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4695 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4696 | 10 | # GNU General Public License for more details. | ||
4697 | 11 | # | ||
4698 | 12 | # You should have received a copy of the GNU General Public License | ||
4699 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4700 | 14 | |||
4701 | 15 | """Test the cruft collector.""" | ||
4702 | 16 | |||
4703 | 17 | from __future__ import absolute_import, unicode_literals | ||
4704 | 18 | |||
4705 | 19 | __metaclass__ = type | ||
4706 | 20 | __all__ = [ | ||
4707 | 21 | 'test_suite', | ||
4708 | 22 | ] | ||
4709 | 23 | |||
4710 | 24 | |||
4711 | 25 | import os | ||
4712 | 26 | import shutil | ||
4713 | 27 | import apt_pkg | ||
4714 | 28 | import tempfile | ||
4715 | 29 | import unittest | ||
4716 | 30 | import pkg_resources | ||
4717 | 31 | import multiprocessing | ||
4718 | 32 | |||
4719 | 33 | from computerjanitor.plugin import Plugin | ||
4720 | 34 | from computerjanitord.collector import Collector | ||
4721 | 35 | from computerjanitord.errors import DuplicateCruftError, PackageCleanupError | ||
4722 | 36 | from computerjanitord.tests.test_application import ApplicationTestSetupMixin | ||
4723 | 37 | |||
4724 | 38 | |||
4725 | 39 | LOCK_FILE = pkg_resources.resource_filename( | ||
4726 | 40 | 'computerjanitord.tests', | ||
4727 | 41 | os.path.join('data', 'var', 'lib', 'dpkg', 'status')) | ||
4728 | 42 | |||
4729 | 43 | |||
4730 | 44 | class MockCruft: | ||
4731 | 45 | """Mock cruft that supports the required `get_name()` interface.""" | ||
4732 | 46 | |||
4733 | 47 | def __init__(self, name): | ||
4734 | 48 | self.name = name | ||
4735 | 49 | |||
4736 | 50 | def get_name(self): | ||
4737 | 51 | return self.name | ||
4738 | 52 | |||
4739 | 53 | |||
4740 | 54 | class MockPlugin(Plugin): | ||
4741 | 55 | cruft_class = MockCruft | ||
4742 | 56 | |||
4743 | 57 | def __init__(self, prefix, shortnames): | ||
4744 | 58 | super(MockPlugin, self).__init__() | ||
4745 | 59 | self.prefix = prefix | ||
4746 | 60 | self.shortnames = shortnames | ||
4747 | 61 | |||
4748 | 62 | def get_cruft(self): | ||
4749 | 63 | for shortname in self.shortnames: | ||
4750 | 64 | yield self.cruft_class('{0}:{1}'.format(self.prefix, shortname)) | ||
4751 | 65 | |||
4752 | 66 | |||
4753 | 67 | class SawAppPlugin(Plugin): | ||
4754 | 68 | """All this plugin does is set a marker attribute on the `Application`. | ||
4755 | 69 | |||
4756 | 70 | This proves that access to the application through the plugin works. | ||
4757 | 71 | """ | ||
4758 | 72 | def get_cruft(self): | ||
4759 | 73 | self.app.saw_app_plugin = True | ||
4760 | 74 | return [] | ||
4761 | 75 | |||
4762 | 76 | |||
4763 | 77 | class LockingPlugin(Plugin): | ||
4764 | 78 | """All this plugin does is acquire a fake apt lock after cleanup.""" | ||
4765 | 79 | |||
4766 | 80 | def get_cruft(self): | ||
4767 | 81 | return [] | ||
4768 | 82 | |||
4769 | 83 | def post_cleanup(self): | ||
4770 | 84 | # If the lock cannot be acquired, an exception is raised. | ||
4771 | 85 | with apt_pkg.FileLock(LOCK_FILE): | ||
4772 | 86 | # Do something. | ||
4773 | 87 | pass | ||
4774 | 88 | |||
4775 | 89 | |||
4776 | 90 | class MockPluginManager: | ||
4777 | 91 | def __init__(self, app, plugin_dirs): | ||
4778 | 92 | # Ignore plugin_dirs | ||
4779 | 93 | self.app = app | ||
4780 | 94 | |||
4781 | 95 | def get_plugins(self): | ||
4782 | 96 | shortnames = ('one', 'two', 'three') | ||
4783 | 97 | for prefix in ('foo', 'bar', 'baz'): | ||
4784 | 98 | plugin = MockPlugin(prefix, shortnames) | ||
4785 | 99 | plugin.set_application(self.app) | ||
4786 | 100 | yield plugin | ||
4787 | 101 | for plugin_class in (SawAppPlugin, LockingPlugin): | ||
4788 | 102 | plugin = plugin_class() | ||
4789 | 103 | plugin.set_application(self.app) | ||
4790 | 104 | yield plugin | ||
4791 | 105 | |||
4792 | 106 | |||
4793 | 107 | class MockCruftExtra(MockCruft): | ||
4794 | 108 | """Cruft with a different class.""" | ||
4795 | 109 | |||
4796 | 110 | |||
4797 | 111 | class MockPluginExtra(MockPlugin): | ||
4798 | 112 | """A mock plugin that returns cruft with a different class.""" | ||
4799 | 113 | |||
4800 | 114 | cruft_class = MockCruftExtra | ||
4801 | 115 | |||
4802 | 116 | |||
4803 | 117 | class IgnoredDuplicateCruftPluginManager(MockPluginManager): | ||
4804 | 118 | """Add an additional piece of ignorable duplication cruft.""" | ||
4805 | 119 | |||
4806 | 120 | def __init__(self, app, plugin_dirs): | ||
4807 | 121 | self.app = app | ||
4808 | 122 | # Ignore plugin_dirs | ||
4809 | 123 | |||
4810 | 124 | def get_plugins(self): | ||
4811 | 125 | yield MockPlugin('one', ('foo', 'bar')) | ||
4812 | 126 | yield MockPlugin('one', ('baz', 'foo')) | ||
4813 | 127 | |||
4814 | 128 | |||
4815 | 129 | class BadDuplicateCruftPluginManager(MockPluginManager): | ||
4816 | 130 | """Add an additional piece of bad duplicate cruft.""" | ||
4817 | 131 | def __init__(self, app, plugin_dirs): | ||
4818 | 132 | self.app = app | ||
4819 | 133 | # Ignore plugin_dirs | ||
4820 | 134 | |||
4821 | 135 | def get_plugins(self): | ||
4822 | 136 | yield MockPlugin('one', ('foo', 'bar')) | ||
4823 | 137 | yield MockPluginExtra('one', ('baz', 'foo')) | ||
4824 | 138 | |||
4825 | 139 | |||
4826 | 140 | class TestCollector(unittest.TestCase, ApplicationTestSetupMixin): | ||
4827 | 141 | """Test the cruft collector.""" | ||
4828 | 142 | |||
4829 | 143 | def setUp(self): | ||
4830 | 144 | # Set up the test data Application. | ||
4831 | 145 | ApplicationTestSetupMixin.setUp(self) | ||
4832 | 146 | self.tempdir = tempfile.mkdtemp() | ||
4833 | 147 | whitelist_dirs = (self.tempdir,) | ||
4834 | 148 | with open(os.path.join(self.tempdir, 'one.whitelist'), 'w') as fp: | ||
4835 | 149 | print >> fp, 'foo:two' | ||
4836 | 150 | print >> fp, 'bar:one' | ||
4837 | 151 | print >> fp, 'baz:three' | ||
4838 | 152 | self.collector = Collector(self.app, MockPluginManager, whitelist_dirs) | ||
4839 | 153 | |||
4840 | 154 | def tearDown(self): | ||
4841 | 155 | shutil.rmtree(self.tempdir) | ||
4842 | 156 | ApplicationTestSetupMixin.tearDown(self) | ||
4843 | 157 | |||
4844 | 158 | def test_cruft_collector(self): | ||
4845 | 159 | cruft_names = set(cruft.get_name() for cruft in self.collector.cruft) | ||
4846 | 160 | self.assertEqual(cruft_names, set(('foo:one', 'foo:three', | ||
4847 | 161 | 'bar:two', 'bar:three', | ||
4848 | 162 | 'baz:one', 'baz:two'))) | ||
4849 | 163 | |||
4850 | 164 | def test_plugin_needs_application(self): | ||
4851 | 165 | # SawAppPlugin returned by the MockPluginManager sets this attribute | ||
4852 | 166 | # on the Application. | ||
4853 | 167 | self.assertTrue(self.app.saw_app_plugin) | ||
4854 | 168 | |||
4855 | 169 | def test_collector_name_mapping(self): | ||
4856 | 170 | cruft_keys = set(self.collector.cruft_by_name) | ||
4857 | 171 | cruft_names = set(cruft.get_name() for cruft in self.collector.cruft) | ||
4858 | 172 | self.assertEqual(cruft_keys, cruft_names) | ||
4859 | 173 | |||
4860 | 174 | def test_cleanup_lock(self): | ||
4861 | 175 | # Pretend we're running synaptic at the same time. We have to acquire | ||
4862 | 176 | # this fake-synaptic lock in a subprocess. | ||
4863 | 177 | lock_event = multiprocessing.Event() | ||
4864 | 178 | continue_event = multiprocessing.Event() | ||
4865 | 179 | class AptLockThread(multiprocessing.Process): | ||
4866 | 180 | def run(self): | ||
4867 | 181 | with apt_pkg.FileLock(LOCK_FILE): | ||
4868 | 182 | lock_event.set() | ||
4869 | 183 | continue_event.wait(1.0) | ||
4870 | 184 | apt_locker = AptLockThread() | ||
4871 | 185 | apt_locker.start() | ||
4872 | 186 | lock_event.wait(1.0) | ||
4873 | 187 | self.assertRaises(PackageCleanupError, self.collector.clean, []) | ||
4874 | 188 | continue_event.set() | ||
4875 | 189 | |||
4876 | 190 | |||
4877 | 191 | class TestDuplicateCruftCollector( | ||
4878 | 192 | unittest.TestCase, ApplicationTestSetupMixin): | ||
4879 | 193 | |||
4880 | 194 | def setUp(self): | ||
4881 | 195 | # Set up the test data Application. | ||
4882 | 196 | ApplicationTestSetupMixin.setUp(self) | ||
4883 | 197 | |||
4884 | 198 | def tearDown(self): | ||
4885 | 199 | ApplicationTestSetupMixin.tearDown(self) | ||
4886 | 200 | |||
4887 | 201 | def test_duplicate_cruft_error(self): | ||
4888 | 202 | self.assertRaises(DuplicateCruftError, Collector, | ||
4889 | 203 | self.app, BadDuplicateCruftPluginManager, []) | ||
4890 | 204 | |||
4891 | 205 | def test_duplicate_cruft_error_message(self): | ||
4892 | 206 | try: | ||
4893 | 207 | Collector(self.app, BadDuplicateCruftPluginManager, []) | ||
4894 | 208 | except DuplicateCruftError as error: | ||
4895 | 209 | self.assertEqual( | ||
4896 | 210 | str(error), | ||
4897 | 211 | 'Duplicate cruft with different cleanup: one:foo') | ||
4898 | 212 | else: | ||
4899 | 213 | raise AssertionError('DuplicateCruftError expected') | ||
4900 | 214 | |||
4901 | 215 | def test_ignored_duplicate_cruft(self): | ||
4902 | 216 | collector = Collector(self.app, IgnoredDuplicateCruftPluginManager, []) | ||
4903 | 217 | self.assertEqual(list(cruft.get_name() for cruft in collector.cruft), | ||
4904 | 218 | ['one:foo', 'one:bar', 'one:baz']) | ||
4905 | 219 | |||
4906 | 220 | |||
4907 | 221 | def test_suite(): | ||
4908 | 222 | suite = unittest.TestSuite() | ||
4909 | 223 | suite.addTests(unittest.makeSuite(TestCollector)) | ||
4910 | 224 | suite.addTests(unittest.makeSuite(TestDuplicateCruftCollector)) | ||
4911 | 225 | return suite | ||
4912 | 0 | 226 | ||
4913 | === added file 'computerjanitord/tests/test_state.py' | |||
4914 | --- computerjanitord/tests/test_state.py 1970-01-01 00:00:00 +0000 | |||
4915 | +++ computerjanitord/tests/test_state.py 2011-02-28 19:09:32 +0000 | |||
4916 | @@ -0,0 +1,141 @@ | |||
4917 | 1 | # Copyright (C) 2008-2011 Canonical, Ltd. | ||
4918 | 2 | # | ||
4919 | 3 | # This program is free software: you can redistribute it and/or modify | ||
4920 | 4 | # it under the terms of the GNU General Public License as published by | ||
4921 | 5 | # the Free Software Foundation, version 3 of the License. | ||
4922 | 6 | # | ||
4923 | 7 | # This program is distributed in the hope that it will be useful, | ||
4924 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4925 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4926 | 10 | # GNU General Public License for more details. | ||
4927 | 11 | # | ||
4928 | 12 | # You should have received a copy of the GNU General Public License | ||
4929 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4930 | 14 | |||
4931 | 15 | """Test the package state.""" | ||
4932 | 16 | |||
4933 | 17 | from __future__ import absolute_import, unicode_literals | ||
4934 | 18 | |||
4935 | 19 | __metaclass__ = type | ||
4936 | 20 | __all__ = [ | ||
4937 | 21 | 'test_suite', | ||
4938 | 22 | ] | ||
4939 | 23 | |||
4940 | 24 | |||
4941 | 25 | import os | ||
4942 | 26 | import difflib | ||
4943 | 27 | import tempfile | ||
4944 | 28 | import textwrap | ||
4945 | 29 | import unittest | ||
4946 | 30 | |||
4947 | 31 | from computerjanitord.state import State | ||
4948 | 32 | |||
4949 | 33 | NL = '\n' | ||
4950 | 34 | |||
4951 | 35 | |||
4952 | 36 | class TestState(unittest.TestCase): | ||
4953 | 37 | """Test the `State` class.""" | ||
4954 | 38 | |||
4955 | 39 | def setUp(self): | ||
4956 | 40 | self.state = State() | ||
4957 | 41 | # Create a temporary file with some enabled and disabled packages. | ||
4958 | 42 | fd, self._state_file = tempfile.mkstemp() | ||
4959 | 43 | os.close(fd) | ||
4960 | 44 | with open(self._state_file, 'w') as fp: | ||
4961 | 45 | print >> fp, textwrap.dedent("""\ | ||
4962 | 46 | [deb:foo] | ||
4963 | 47 | ignore: false | ||
4964 | 48 | [deb:bar] | ||
4965 | 49 | ignore: true | ||
4966 | 50 | [deb:baz] | ||
4967 | 51 | ignore: true | ||
4968 | 52 | """) | ||
4969 | 53 | fd, self._state_file_old = tempfile.mkstemp() | ||
4970 | 54 | os.close(fd) | ||
4971 | 55 | with open(self._state_file_old, 'w') as fp: | ||
4972 | 56 | print >> fp, textwrap.dedent("""\ | ||
4973 | 57 | [deb:qux] | ||
4974 | 58 | enabled: false | ||
4975 | 59 | [deb:fno] | ||
4976 | 60 | enabled: true | ||
4977 | 61 | [deb:bla] | ||
4978 | 62 | enabled: true | ||
4979 | 63 | """) | ||
4980 | 64 | fd, self._write_file = tempfile.mkstemp() | ||
4981 | 65 | os.close(fd) | ||
4982 | 66 | |||
4983 | 67 | def tearDown(self): | ||
4984 | 68 | os.remove(self._state_file) | ||
4985 | 69 | os.remove(self._state_file_old) | ||
4986 | 70 | os.remove(self._write_file) | ||
4987 | 71 | |||
4988 | 72 | def assertEqualNdiff(self, expected, got): | ||
4989 | 73 | expected_lines = expected.splitlines() | ||
4990 | 74 | got_lines = got.splitlines() | ||
4991 | 75 | self.assertEqual( | ||
4992 | 76 | expected, got, | ||
4993 | 77 | '\n' + NL.join(difflib.ndiff(expected_lines, got_lines))) | ||
4994 | 78 | |||
4995 | 79 | def test_initially_no_previously_ignored(self): | ||
4996 | 80 | self.assertEqual(self.state.ignore, set()) | ||
4997 | 81 | |||
4998 | 82 | def test_load_state(self): | ||
4999 | 83 | self.state.load(self._state_file) | ||
5000 | 84 | self.assertEqual(self.state.ignore, set(('deb:bar', 'deb:baz'))) |
Thanks for following along in the UDD class on irc. It was my fault but your original branch should have been against ubuntu: computer- janitor instead of lp:computer-janitor.