Merge lp:~lasall/ppa-purge/dryrun into lp:ppa-purge

Proposed by Dominique Lasserre
Status: Needs review
Proposed branch: lp:~lasall/ppa-purge/dryrun
Merge into: lp:ppa-purge
Diff against target: 109 lines (+50/-8)
1 file modified
ppa-purge (+50/-8)
To merge this branch: bzr merge lp:~lasall/ppa-purge/dryrun
Reviewer Review Type Date Requested Status
Tormod Volden Needs Fixing
Review via email: mp+153845@code.launchpad.net

Description of the change

Add dryrun option.

To post a comment you must log in.
Revision history for this message
Tormod Volden (tormodvolden) wrote :

Thanks, looks good. It would have been even more useful if it could have shown what apt-get would be going to do, but that shouldn't stop this from going in - it is better than nothing.

review: Approve
Revision history for this message
Dominique Lasserre (lasall) wrote :

Do you mean the --simulate switch of apt-get/aptitude?

Revision history for this message
Tormod Volden (tormodvolden) wrote :

Yes, but that won't help much if apt-get update hasn't been run with the modified sources list, will it?

Maybe more useful than your current patch, which only helps to verify the PPA name, would be to actually disable the PPA in the sources list (requiring superuser) and run the apt-get install with --simulate, then restore the sources list?

Revision history for this message
Dominique Lasserre (lasall) wrote :

On 19/03/13 23:09, Tormod Volden wrote:
> Yes, but that won't help much if apt-get update hasn't been run with the modified sources list, will it?
Hm, didn't thought at this.

> Maybe more useful than your current patch, which only helps to verify the PPA name, would be to actually disable the PPA in the sources list (requiring superuser) and run the apt-get install with --simulate, then restore the sources list?
I would rather suggest to use an other switch for that. Because this
operation is much more non-trivial than a "dryrun". If you agree to make
this a new option (and name the switch), I will add the functionality:

 0. Update.
 1. Disable sources but make a backup (where a change is needed),
something like foobar.list.ppa-purge.save (and make sure this file not
already exists).
 2. Update.
 3. --simulate
 4. Restore backup.
 5. Update.

At that point it would be useful to display a message as long the update
is running and remove it with control sequences, e.g.:
  echo -n "Update sources..."; echo -n "\rUpdate finished. \n"

My first motivation for the "dryrun"-switch was to debug the file list
name and see if it's possible to disable other sources than a Launchpad
PPA. (At the moment this is not fully possible - everything works except
disabling the sources entry.)

Revision history for this message
Tormod Volden (tormodvolden) wrote :

Thanks, that sounds like a nice functionality.

Why do you need step 0?

I don't see the need to remove a message after it has been displayed, only if it would be a pure progress indicator (bars) or something repeated over and over again. This is one advantage with command-line interfaces that you can see afterwards what happened.

I agree it is a little more than a dry-run since it actually updates the package lists. But I am still not convinced we would need your original dry-run. You use it to see if the given repo name will match any apt source entries? As long as there is not many false positives there is not much harm in trying.

I understand you would like to have something symmetric to add-apt-repository. This might be a good idea. In my opinion it would make sense to have an remove-apt-repository that just removes the entries in the sources lists, but with a --revert option to "downgrade" back to package versions available in other sources and a --purge option to remove packages that are not available from the remaining sources. And "ppa-purge" would just be remove-apt-repository --revert --purge.

Revision history for this message
Dominique Lasserre (lasall) wrote :

On 20/03/13 21:55, Tormod Volden wrote:
> Thanks, that sounds like a nice functionality.
>
> Why do you need step 0?
It is already implemented: line 107

>
> I don't see the need to remove a message after it has been displayed, only if it would be a pure progress indicator (bars) or something repeated over and over again. This is one advantage with command-line interfaces that you can see afterwards what happened.
Ok (I thought at some "." ".." "..." points to indicate something is
running but that is really only some sugar and not important).

>
> I agree it is a little more than a dry-run since it actually updates the package lists. But I am still not convinced we would need your original dry-run. You use it to see if the given repo name will match any apt source entries? As long as there is not many false positives there is not much harm in trying.
Yes that was my usecase. And I didn't want to run an update of my
sources every time (because a single update takes over a minute).

>
> I understand you would like to have something symmetric to add-apt-repository. This might be a good idea. In my opinion it would make sense to have an remove-apt-repository that just removes the entries in the sources lists, but with a --revert option to "downgrade" back to package versions available in other sources and a --purge option to remove packages that are not available from the remaining sources. And "ppa-purge" would just be remove-apt-repository --revert --purge.
Sounds great. I think it would make sense to use python-apt for this
task because it uses the APT API (for either sources entries and package
list files). Imho the right way is to extend the existing
add-apt-repository and eventually use remove-apt-repository as a
shorthand to it. add-apt-repository already resolves its arguments to
valid source entries (either ppa:... or 'deb ...' or 'protocol://...').

Revision history for this message
Tormod Volden (tormodvolden) wrote :

OK, meanwhile we would be happy to have your --simulate implementation :)

(I won't be reviewing for the next 1-2 weeks, but others might jump in.)

review: Needs Fixing
lp:~lasall/ppa-purge/dryrun updated
60. By Dominique Lasserre

Simulate removal with --simulate switch.

61. By Dominique Lasserre

Fixup variable name.

Revision history for this message
Dominique Lasserre (lasall) wrote :

I have updated the patch and -n now uses the --simulate switch of apt-get/aptitude.

Revision history for this message
Dominique Lasserre (lasall) wrote :

Are there any issues with this updated patch?

Revision history for this message
Tormod Volden (tormodvolden) wrote :

Hi Dominique,
Can you rebase 59-60-61 into one new commit? It is just a bit confusing with commits undoing another.

You have also spelled "disable" wrong at least twice.

Are you serious about checking for 9223372036854775807 backup files? If loads of backup files are already present it will be wrong to add another IMO.

If you are not reusing NUM it is not necessary to unset it.

Revision history for this message
Tim Lunn (darkxst) wrote :

I guess this branch is dead, but incase anyone else decides to work on it.

You don't need to back up UNIT64_MAX files, just the one. the changes should also be reverted in the trap handler. Alternatively it may be sufficent to just revert the changes i.e remove the "# " in a trap handler and exit failure.

Unmerged revisions

61. By Dominique Lasserre

Fixup variable name.

60. By Dominique Lasserre

Simulate removal with --simulate switch.

59. By Dominique Lasserre

Add dryrun switch "-n" (lp: #802853)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ppa-purge'
--- ppa-purge 2012-11-21 09:30:49 +0000
+++ ppa-purge 2013-03-22 17:08:26 +0000
@@ -8,7 +8,8 @@
8F_ARCHS=$(dpkg --print-foreign-architectures)8F_ARCHS=$(dpkg --print-foreign-architectures)
9PPA_PKGS=$(mktemp)9PPA_PKGS=$(mktemp)
10REVERTS=$(mktemp)10REVERTS=$(mktemp)
11trap "rm $PPA_PKGS $REVERTS" 011BACKUPLISTS=$(mktemp)
12trap "rm $PPA_PKGS $REVERTS $BACKUPLISTS" 0
1213
13# Functions to write output nicely.14# Functions to write output nicely.
14write_msg() {15write_msg() {
@@ -35,6 +36,7 @@
35 echo " -d [distribution] Override the default distribution choice."36 echo " -d [distribution] Override the default distribution choice."
36 echo " -y Pass "-y --force-yes" to apt-get or "-y" to aptitude"37 echo " -y Pass "-y --force-yes" to apt-get or "-y" to aptitude"
37 echo " -i Reverse preference of apt-get upon aptitude."38 echo " -i Reverse preference of apt-get upon aptitude."
39 echo " -n Simulate removal (no changes)."
38 echo " -h Display this help text"40 echo " -h Display this help text"
39 echo41 echo
40 echo "Example usage commands:"42 echo "Example usage commands:"
@@ -55,13 +57,14 @@
55}57}
5658
57# Command line options59# Command line options
58while getopts "p:s:d:yih\?" opt; do60while getopts "p:s:d:yinh\?" opt; do
59 case "$opt" in61 case "$opt" in
60 p ) PPANAME="$OPTARG" ;;62 p ) PPANAME="$OPTARG" ;;
61 s ) PPAHOST="$OPTARG" ;;63 s ) PPAHOST="$OPTARG" ;;
62 d ) DIST="$OPTARG" ;;64 d ) DIST="$OPTARG" ;;
63 y ) FORCEINSTALL="true" ;;65 y ) FORCEINSTALL="true" ;;
64 i ) APTALT="true" ;;66 i ) APTALT="true" ;;
67 n ) SIMULATE="true" ;;
65 h ) usage 0; ;;68 h ) usage 0; ;;
66 \?) usage 1; ;;69 \?) usage 1; ;;
67 * ) warn "Unknown option '$opt'"; usage 1; ;;70 * ) warn "Unknown option '$opt'"; usage 1; ;;
@@ -82,6 +85,9 @@
82 fi85 fi
83 APT=apt-get; APTALT=aptitude86 APT=apt-get; APTALT=aptitude
84fi87fi
88if [ -n "$SIMULATE" ]; then
89 APTARG="$APTARG --simulate"
90fi
8591
86if echo $1 | grep -q "^ppa:"; then92if echo $1 | grep -q "^ppa:"; then
87 PPAOWNER=$(echo $1 | sed "s#^ppa:\(.*\)/\(.*$\)#\1#")93 PPAOWNER=$(echo $1 | sed "s#^ppa:\(.*\)/\(.*$\)#\1#")
@@ -156,7 +162,28 @@
156# Disable PPA from sources.list files162# Disable PPA from sources.list files
157for LIST in $(find /etc/apt/ -name "*.list" -exec readlink -f '{}' \;); do163for LIST in $(find /etc/apt/ -name "*.list" -exec readlink -f '{}' \;); do
158 if [ -e $LIST ] && grep -q $PPAOWNER/$PPANAME $LIST; then164 if [ -e $LIST ] && grep -q $PPAOWNER/$PPANAME $LIST; then
159 msg "Disabling $PPAOWNER PPA from $LIST"165 if [ -z "$SIMULATE" ]; then
166 msg "Disabling $PPAOWNER PPA from $LIST"
167 else
168 NUM=""
169 if [ -f "${LIST}.ppa-purge.save" ]; then
170 NUM=1
171 while [ -f "${LIST}.ppa-purge${NUM}.save" ]; do
172 # Take care about the very rare case all files
173 # in range $LIST.ppa-purge{0,ULONG64_MAX}.save
174 # already exist and avoid endless loop (will
175 # not try "negative files" though).
176 if [ $((NUM++)) = 9223372036854775807 ]; then
177 warn "Could not find place for a backup file."
178 exit 1
179 fi
180 done
181 fi
182 msg "Disabe (and backup) $PPAOWNER PPA from $LIST (to ${LIST}.ppa-purge${NUM}.save)"
183 echo "${LIST}.ppa-purge${NUM}.save $LIST" >> $BACKUPLISTS
184 cp -- $LIST "${LIST}.ppa-purge${NUM}.save"
185 unset NUM
186 fi
160 sed -ri "\:^[^#]+/${PPAOWNER}/${PPANAME}/:s/^deb/# deb/" $LIST187 sed -ri "\:^[^#]+/${PPAOWNER}/${PPANAME}/:s/^deb/# deb/" $LIST
161 fi188 fi
162done189done
@@ -170,11 +197,26 @@
170# from $REINSTALL directly.197# from $REINSTALL directly.
171198
172if $APT $APTARG install $REINSTALL; then199if $APT $APTARG install $REINSTALL; then
173 msg "PPA purged successfully"200 STATE=0
174elif $APTALT $APTARG install $REINSTALL; then201elif $APTALT $APTARG install $REINSTALL; then
175 msg "PPA purged successfully using $APTALT fallback"202 STATE=1
176else203else
177 warn "Something went wrong, packages may not have been reverted"204 STATE=2
178 exit 1205fi
179fi206
207if [ -n "$SIMULATE" ]; then
208 msg "Restore disalbed source entries"
209 while read BACKUP; do
210 eval mv -- $BACKUP
211 done < $BACKUPLISTS
212 msg "Updating packages lists"
213 $APT update > /dev/null || warn "$APT update failed for some reason"
214fi
215
216case $STATE in
217 0 ) msg "PPA purged successfully" ;;
218 1 ) msg "PPA purged successfully using $APTALT fallback" ;;
219 2 ) warn "Something went wrong, packages may not have been reverted"; exit 1; ;;
220esac
221
180exit 0222exit 0

Subscribers

People subscribed via source and target branches

to all changes: