Merge lp:~eugenesan/ppa-purge/trunk into lp:ppa-purge

Proposed by Eugene San
Status: Needs review
Proposed branch: lp:~eugenesan/ppa-purge/trunk
Merge into: lp:ppa-purge
Diff against target: 144 lines (+47/-33)
3 files modified
debian/changelog (+9/-0)
debian/control (+1/-1)
ppa-purge (+37/-32)
To merge this branch: bzr merge lp:~eugenesan/ppa-purge/trunk
Reviewer Review Type Date Requested Status
Tormod Volden Needs Fixing
Review via email: mp+46673@code.launchpad.net

This proposal supersedes a proposal from 2011-01-18.

Description of the change

Adding support for compressed and empty packages lists

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

Hi, thanks for the code. This could also have been three commits though: 1) whitespace clean-up, 2) adding support for compressed package lists, 3) add support for empty package lists.

Anyway, does it really work? $LIST is always an existing file (as long as the * in PPA_LIST successfully expands, otherwise it is useless, that was what the original -e checked for), so 1) the elif's can not be reached and 2) $LIST.gz can not exist at the same time as $LIST, right? I don't have any compressed lists on my machine so I can not verify this case :)

Basically, 1) the PPA_LIST does not match anything ending in .gz etc, and 2) if it would, $LIST.gz would not exist since the .gz would already be included in $LIST.

I can suggest instead adding * to the end of the PPA_LIST so that any filename suffix gets expanded, then use lesspipe to decompress $LIST whatever its file type is (kind of a hack).

Revision history for this message
Eugene San (eugenesan) wrote : Posted in a previous version of this proposal

Hi, thanks for prompt review.

Sorry for combining all changes together, wasn't sure they deserve separate
commits.
After reading your points I realized that the shouldn't work, but some how
it does!
I probably was still sleeping while committing :-)
I am going to review the code one more time later.

Just in case you willing to play with it, this is how you enable compressed
lists:
echo "
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
" >> /etc/apt/apt.conf

And for empty repository:
add-apt-repository unity/ppa

On Tue, Jan 18, 2011 at 11:25, Tormod Volden <email address hidden>wrote:

> Hi, thanks for the code. This could also have been three commits though: 1)
> whitespace clean-up, 2) adding support for compressed package lists, 3) add
> support for empty package lists.
>
> Anyway, does it really work? $LIST is always an existing file (as long as
> the * in PPA_LIST successfully expands, otherwise it is useless, that was
> what the original -e checked for), so 1) the elif's can not be reached and
> 2) $LIST.gz can not exist at the same time as $LIST, right? I don't have any
> compressed lists on my machine so I can not verify this case :)
>
> Basically, 1) the PPA_LIST does not match anything ending in .gz etc, and
> 2) if it would, $LIST.gz would not exist since the .gz would already be
> included in $LIST.
>
> I can suggest instead adding * to the end of the PPA_LIST so that any
> filename suffix gets expanded, then use lesspipe to decompress $LIST
> whatever its file type is (kind of a hack).
> --
> https://code.launchpad.net/~eugenesan/ppa-purge/trunk/+merge/46570<https://code.launchpad.net/%7Eeugenesan/ppa-purge/trunk/+merge/46570>
> You are the owner of lp:~eugenesan/ppa-purge/trunk.
>

Revision history for this message
Eugene San (eugenesan) wrote : Posted in a previous version of this proposal

Hi,

I followed Tormod Volden's great suggestion and used lesspipe, now everything is working.

Also I've added "err" function, since till now we used "warn" also for fatal errors.

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

What are you filtering out here? I would filter away as little as possible, so that the day something unexpected happens, the error message can be seen.
119 done 2> /dev/null > /dev/null

This won't work:
+[ -z "$LIST" ] && err "Could not find packages list for PPA: $PPAOWNER $PPANAME"
because $LIST is always non-zero. If no match it will just not expand the *.

What is exactly the use case for empty apt lists? What do we want to happen in this case? Asking since it is a long time since I worked on this, and also check that we agree on the overall logic.

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

And by the way, if you are preparing a new release in debian/changelog, and you made all the changes, put yourself on the signing line! Don't be shy :) It will have to be sponsored for uploading anyway.

Revision history for this message
Eugene San (eugenesan) wrote :

Hi,

I've got your points.
This is what I propose instead:
for LIST in /var/lib/apt/lists/${PPAHOST}_${PPAOWNER}_${PPANAME}_*_Packages* ; do
        if [ -e "$LIST" ]; then
                lesspipe ${LIST} | grep "^Package: " | cut -d " " -f2 | sort >> $PPA_PKGS
        else
                err "Could not find packages list for PPA: $PPAOWNER $PPANAME"
        fi
done

In case there is no lists by wildcard, [ -e ] will fail.

Regarding empty/missing lists.
Today I've tried to remove empty repo (without knowing it is empty) and ppa-purge failed. So I added treatment of this case. And missing lists treated to distinguish that from case when list is just empty.

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

Thanks, that looks very good. Note that we don't use {} around variables other places unless it is needed, and it is not needed on this lesspipe command either.

The empty repo is something that ppa-purge can not handle. It is a bad PPA which removes packages that have been published :) The hacky logic in ppa-purge uses the existing packages in the PPA to figure out which packages need to be reverted. So if there are no packages there, ppa-purge should fail in my opinion. All it can do in this case is removing the PPA from the sources.list, but the user should rather use Software Sources for this. Well, somebody should write apt-delete-repository to pair with apt-add-repository :) Then we could also just call that internally when things are ok, and bail out and tell the user to just use that when the PPA is empty, and not give the user the impression that ppa-purge did its job, which is mainly the reverting packages part.

There are tricks like "aptitude search '~i!~Oubuntu' to find packages that are not installed from Ubuntu repositories, but I don't know a way to find packages installed from a PPA.

lp:~eugenesan/ppa-purge/trunk updated
60. By Eugene San

Fixng failed empty list detection

61. By Eugene San

Update debian/changelog

Unmerged revisions

61. By Eugene San

Update debian/changelog

60. By Eugene San

Fixng failed empty list detection

59. By Eugene San

Fixing nonblocking typos

58. By Eugene San

Finalizing support for compressed and empty apt lists

57. By Eugene San

Merged main branch

56. By Eugene San

Adding support for compressed and empty packages lists

55. By eugenesan <eugenesan@portsan>

Fixing typo in changelog

54. By eugenesan <eugenesan@portsan>

Fixing typo causing permanent aptitude usage

53. By eugenesan <eugenesan@portsan>

Few changes for upcoming 0.2.8

52. By eugenesan <eugenesan@portsan>

Adding reverse order of apt tool usage and support for symlinked lists

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2010-11-10 20:13:14 +0000
3+++ debian/changelog 2011-02-22 14:57:19 +0000
4@@ -1,3 +1,12 @@
5+ppa-purge (0.2.8+bzr59) natty; urgency=low
6+
7+ [ Eugene San (eugenesan) ]
8+ * Replace "warn() && exit 1" with err()
9+ * Cosmetic changes
10+ * Add support for compressed and empty apt lists
11+
12+ -- Eugene San (eugenesan) <eugenesan@gmail.com> Tue, 22 Feb 2011 16:43:00 +0300
13+
14 ppa-purge (0.2.8+bzr56) natty; urgency=low
15
16 * Really implement the "-y" option.
17
18=== modified file 'debian/control'
19--- debian/control 2010-10-15 21:22:59 +0000
20+++ debian/control 2011-02-22 14:57:19 +0000
21@@ -8,7 +8,7 @@
22
23 Package: ppa-purge
24 Architecture: all
25-Depends: ${misc:Depends}, aptitude
26+Depends: ${misc:Depends}, aptitude, less
27 Description: disables a PPA and reverts to official packages
28 This program disables a PPA from your Software Sources and reverts your
29 system back to the official Ubuntu packages. You can use this to return your
30
31=== modified file 'ppa-purge'
32--- ppa-purge 2010-11-10 20:13:14 +0000
33+++ ppa-purge 2011-02-22 14:57:19 +0000
34@@ -20,7 +20,12 @@
35 }
36
37 warn() {
38- write_msg "Warning: $*" 1>&2
39+ write_msg "Warning: $*" 1>&2
40+}
41+
42+err() {
43+ write_msg "Error: $*" 1>&2
44+ exit 1
45 }
46
47 usage() {
48@@ -61,7 +66,7 @@
49 s ) PPAHOST="$OPTARG" ;;
50 d ) DIST="$OPTARG" ;;
51 y ) FORCEINSTALL="true" ;;
52- i ) APTALT="true" ;;
53+ i ) APTALT="true" ;;
54 h ) usage 0; ;;
55 \?) usage 1; ;;
56 * ) warn "Unknown option '$opt'"; usage 1; ;;
57@@ -73,12 +78,12 @@
58 APTARG=""
59 if [ ! -z "$APTALT" ]; then
60 if [ ! -z "$FORCEINSTALL" ]; then
61- APTARG="-y"
62+ APTARG="-y"
63 fi
64 APT=aptitude; APTALT=apt-get
65 else
66 if [ ! -z "$FORCEINSTALL" ]; then
67- APTARG="-y --force-yes"
68+ APTARG="-y --force-yes"
69 fi
70 APT=apt-get; APTALT=aptitude
71 fi
72@@ -109,36 +114,36 @@
73 msg "PPA to be removed: $PPAOWNER $PPANAME"
74
75 # Make list of all packages in PPA
76-PPA_LIST=/var/lib/apt/lists/${PPAHOST}_${PPAOWNER}_${PPANAME}_*_Packages
77-for LIST in $PPA_LIST; do
78- if [ -e $LIST ]; then
79- grep "^Package: " $LIST | cut -d " " -f2 | sort >> $PPA_PKGS
80+for LIST in /var/lib/apt/lists/${PPAHOST}_${PPAOWNER}_${PPANAME}_*_Packages* ; do
81+ if [ -e "$LIST" ]; then
82+ lesspipe ${LIST} | grep "^Package: " | cut -d " " -f2 | sort >> $PPA_PKGS
83+ else
84+ err "Could not find packages list for PPA: $PPAOWNER $PPANAME"
85 fi
86 done
87
88 if [ ! -s $PPA_PKGS ]; then
89- warn "Could not find package list for PPA: $PPAOWNER $PPANAME"
90- exit 1
91-fi
92-
93-# Ignore the ppa-purge package
94-if grep -q "ppa-purge" $PPA_PKGS; then
95- sed -i '/ppa-purge/d' $PPA_PKGS
96- msg "Note: Not removing ppa-purge package"
97-fi
98-
99-dpkg --get-selections | awk '/install$/{print $1}' |
100- sort | comm -12 - $PPA_PKGS > $REVERTS
101-
102-# Create apt argument list for reverting packages
103-REINSTALL=""
104-for PACKAGE in $(cat $REVERTS); do
105- REINSTALL="$REINSTALL $PACKAGE/$DIST"
106-done
107-
108-msg "Package revert list generated:"
109-msg "$REINSTALL"
110-echo
111+ warn "PPA: $PPAOWNER $PPANAME is empty, skipping packages treatment."
112+else
113+ # Ignore the ppa-purge package
114+ if grep -q "ppa-purge" $PPA_PKGS; then
115+ sed -i '/ppa-purge/d' $PPA_PKGS
116+ msg "Note: Not removing ppa-purge package"
117+ fi
118+
119+ dpkg --get-selections | awk '/install$/{print $1}' |
120+ sort | comm -12 - $PPA_PKGS > $REVERTS
121+
122+ # Create apt argument list for reverting packages
123+ REINSTALL=""
124+ for PACKAGE in $(cat $REVERTS); do
125+ REINSTALL="$REINSTALL $PACKAGE/$DIST"
126+ done
127+
128+ msg "Package revert list generated:"
129+ msg "$REINSTALL"
130+ echo
131+fi
132
133 # Disable PPA from sources.list files
134 for LIST in $(find /etc/apt/ -name "*.list" -exec readlink -f '{}' \;); do
135@@ -161,7 +166,7 @@
136 elif $APTALT $APTARG install $REINSTALL; then
137 msg "PPA purged successfully using $APTALT fallback"
138 else
139- warn "Something went wrong, packages may not have been reverted"
140- exit 1
141+ err "Something went wrong, packages may not have been reverted"
142 fi
143+
144 exit 0

Subscribers

People subscribed via source and target branches

to all changes: