[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] Removing read articles according to .newsrc



On Sun, Jan 23, 2005 at 06:51:31PM +0100, Matthias Andree wrote:
> Kris Kennaway schrieb am 2005-01-22:
> 
> > I'd like to remove from my leafnode spool all the articles that I have
> > read, as listed in my .newsrc file (slrn, if it matters).  Has anyone
> > written a script to do this?
> 
> I am not aware of any scripts that would parse the .newsrc.
> 
> If someone has a decent script to treat .newsrc, let me know and I may
> consider setting a link to it.

I wrote the following awk script which seemed to work nicely for me
(it spits out a list of files corresponding to articles that are
listed in the .jnewsrc as read, which can be piped to xargs rm).  a
texpire run will then clean up the actual articles that are no longer
linked.

Kris
# Copyright (C) 2005 Kristian D. Kennaway.  All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

# Parse a .jnewsrc from slrn (other news readers may also be compatible)
# and generate a corresponding list of read articles in the news spool.
# These files may be removed, e.g. by running
#
# awk -f cleanspool | xargs rm
#
# and the corresponding articles will be unlinked the next time texpire
# is run.
#
# You will need to adjust the newsrc and spooldir variables as appropriate
# before using.

function nextlist(   err) {
	while (getline < newsrc) {
		if ($0 !~ /\!/) {
			break
		}
	}
	return $0
}

function findgroup(name,   line) {
	while (1) {
		getline line < newsrc
		reg=sprintf("^%s: ", name)
		if (match(line,reg)) {
			break
		}
	}
	return line
}

BEGIN {
	newsrc="/home/kkenn/.jnewsrc"
	spooldir="/mnt/news/leafnode/"

	group="XXX"
	while(group != "") {
		group=nextlist();
		rangelist=gensub(/^.*:( )*/,"","g",group)
		nranges=split(rangelist,ranges,",")
		currange=0
		nextrange()
	
		dir=spooldir tolower(gensub("\\\.","/","g",substr(group,0,index(group,":")-1)))
		if (dir == spooldir) {
			exit 0
		}
		cmd=sprintf("test -d %s && cd %s && find . -name '[0-9]*' -depth 1 -type f | sed -e 's,^./,,' | sort -n", dir, dir)
		while (cmd | getline) {
			while ( ($0 + 0) > (rangeupper + 0)) {
				err = nextrange()
				if (err) {
				break
				}
			}
			if ( ($0+0) >= (rangelower+0) && ($0+0) <= (rangeupper+0)) {
				print dir "/" $0
			}
		}
	}
}


function nextrange() {
	currange++
	if (currange > nranges) {
		return 1
	}
	range=ranges[currange]
	if ( range !~ "-" ) {
		rangelower=range
		rangeupper=range
	} else {
		rangelower=gensub(/-[0-9]+$/,"",g,range)
		rangeupper=gensub(/^[0-9]+-/,"",g,range)
	}
}

Attachment: pgpIx2R8BRg0H.pgp
Description: PGP signature

-- 
_______________________________________________
leafnode-list mailing list
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
http://www.dt.e-technik.uni-dortmund.de/mailman/listinfo/leafnode-list
http://leafnode.sourceforge.net/