aboutsummaryrefslogtreecommitdiff
path: root/0.4.0/eselect/news.eselect
diff options
context:
space:
mode:
Diffstat (limited to '0.4.0/eselect/news.eselect')
-rw-r--r--0.4.0/eselect/news.eselect225
1 files changed, 225 insertions, 0 deletions
diff --git a/0.4.0/eselect/news.eselect b/0.4.0/eselect/news.eselect
new file mode 100644
index 0000000..5d57a2e
--- /dev/null
+++ b/0.4.0/eselect/news.eselect
@@ -0,0 +1,225 @@
+# Copyright 2006 Ciaran McCreesh
+# Distributed under the terms of the GNU General Public License v2
+# $Id: $
+
+DESCRIPTION="Read GLEP 42 news items"
+MAINTAINER="ciaran.mccreesh@blueyonder.co.uk"
+SVN_DATE='$Date: $'
+VERSION=$(svn_date_to_version "${SVN_DATE}" )
+
+paludis_command() {
+ echo ${PALUDIS_COMMAND:-paludis}
+}
+
+get_repositories() {
+ $(paludis_command ) --list-repositories | \
+ sed -n -e 's/^\* *//p'
+}
+
+get_unread() {
+ local repo repos
+ repos=( $(get_repositories ) )
+ for repo in ${repos[@]} ; do
+ [[ -f "${ROOT}/var/lib/paludis/news/news-${repo}.unread" ]] || continue
+ sed -e '/^#/d' -e "/./s,$,::${repo}," < \
+ ${ROOT}/var/lib/paludis/news/news-${repo}.unread
+ done
+}
+
+get_read() {
+ local repo repos
+ repos=( $(get_repositories ) )
+ for repo in ${repos[@]} ; do
+ [[ -f "${ROOT}/var/lib/paludis/news/news-${repo}.read" ]] || continue
+ sed -e '/^#/d' -e "/./s,$,::${repo}," < \
+ ${ROOT}/var/lib/paludis/news/news-${repo}.read
+ done
+}
+
+mark_read() {
+ local name=${1%::*} repo=${1##*::}
+
+ touch "${ROOT}"/var/lib/paludis/news/news-${repo}.read || \
+ die -q "Couldn't touch read file for ${1}"
+
+ if ! grep -q "^${name}\$" < "${ROOT}"/var/lib/paludis/news/news-${repo}.read ; then
+ echo "${name}" >> "${ROOT}"/var/lib/paludis/news/news-${repo}.read || \
+ die -q "Couldn't mark ${1} as read"
+ fi
+
+ sed -i -e "/^${name}\$/d" "${ROOT}"/var/lib/paludis/news/news-${repo}.unread || \
+ die -q "Couldn't remove ${1} from unread list"
+}
+
+mark_unread() {
+ local name=${1%::*} repo=${1##*::}
+
+ touch "${ROOT}"/var/lib/paludis/news/news-${repo}.unread || \
+ die -q "Couldn't touch unread file for ${1}"
+
+ if ! grep -q "^${name}\$" < "${ROOT}"/var/lib/paludis/news/news-${repo}.unread ; then
+ echo "${name}" >> "${ROOT}"/var/lib/paludis/news/news-${repo}.unread || \
+ die -q "Couldn't mark ${1} as unread"
+ fi
+
+ sed -i -e "/^${name}\$/d" "${ROOT}"/var/lib/paludis/news/news-${repo}.read || \
+ die -q "Couldn't remove ${1} from read list"
+}
+
+purge_read() {
+ local repo
+ for repo in $(get_repositories ) ; do
+ : > "${ROOT}"/var/lib/paludis/news/news-${repo}.read || \
+ die -q "Couldn't purge ${repo} read list"
+ done
+}
+
+get_dir_name() {
+ local name=${1%::*} repo=${1##*::}
+ $(paludis_command ) --list-repositories --repository ${repo} | \
+ sed -n -e "s~^ *newsdir: *\(.*\)~\1/${name}/~p"
+}
+
+get_headers() {
+ local dir=${1}
+ dir=${dir}/$(basename ${1%/} ).en.txt
+ sed -e '/^$/,$d' < ${dir}
+}
+
+get_body() {
+ local dir=${1}
+ dir=${dir}/$(basename ${1%/} ).en.txt
+ sed -e '1,/^$/d' < ${dir}
+}
+
+get_title() {
+ local f=$(get_dir_name ${1} )
+ if [[ -d ${f} ]] ; then
+ get_headers ${f} | sed -n -e 's/^Title:\s*//p'
+ else
+ echo "(no title available)"
+ fi
+}
+
+### list action ###
+
+describe_list() {
+ echo "List news items"
+}
+
+do_list() {
+ targets=( $(get_unread ) )
+ write_list_start "Unread news items:"
+ if [[ -n ${targets[@]} ]] ; then
+ local target
+ for target in ${targets[@]} ; do
+ write_kv_list_entry "${target%::*}" "$(get_title ${target} )"
+ done
+ else
+ write_kv_list_entry "(none found)" ""
+ fi
+
+ targets=( $(get_read ) )
+ write_list_start "Read news items:"
+ if [[ -n ${targets[@]} ]] ; then
+ local target
+ for target in ${targets[@]} ; do
+ write_kv_list_entry "${target%::*}" "$(get_title ${target} )"
+ done
+ else
+ write_kv_list_entry "(none found)" ""
+ fi
+}
+
+### read action ###
+
+describe_read() {
+ echo "Read a news item"
+}
+
+describe_read_parameters() {
+ echo "<target>"
+}
+
+describe_read_options() {
+ echo "target : News item ID (from 'list' action)"
+}
+
+do_read() {
+ [[ -z ${1} ]] && die -q "You didn't tell me what you want to read"
+
+ local i item= items
+ items=( $(get_unread ) )
+ for i in ${items[@]} ; do
+ [[ -n "${item}" ]] && break
+ [[ "${i%::*}" == "${1}" ]] || continue
+ item=${i}
+ done
+
+ items=( $(get_read ) )
+ for i in ${items[@]} ; do
+ [[ -n "${item}" ]] && break
+ [[ "${i%::*}" == "${1}" ]] || continue
+ item=${i}
+ done
+
+ [[ -z "${item}" ]] && die -q "Can't find news item '${1}'"
+
+ write_list_start "${item%::*}"
+ local f=$(get_dir_name ${item} ) line
+ get_headers ${f} | \
+ while read line ; do
+ local k=${line%%:*}
+ case ${k} in
+ Title|Author|Posted|Revision|Translator)
+ write_kv_list_entry "${k}" "${line#*:}"
+ ;;
+ esac
+ done
+ echo
+ get_body ${f}
+
+ mark_read "${item}"
+}
+
+### unread action ###
+
+describe_unread() {
+ echo "Unread a news item"
+}
+
+describe_unread_parameters() {
+ echo "<target>"
+}
+
+describe_unread_options() {
+ echo "target : News item ID (from 'list' action)"
+}
+
+do_unread() {
+ [[ -z ${1} ]] && die -q "You didn't tell me what you want to unread"
+
+ local i item= items
+ items=( $(get_read ) )
+ for i in ${items[@]} ; do
+ [[ -n "${item}" ]] && break
+ [[ "${i%::*}" == "${1}" ]] || continue
+ item=${i}
+ done
+
+ [[ -z "${item}" ]] && die -q "Can't find read news item '${1}'"
+
+ mark_unread "${item}"
+}
+
+### purge action ###
+
+describe_purge() {
+ echo "Purge read news items"
+}
+
+do_purge() {
+ purge_read
+}
+
+# vim: ts=4 sw=4 noet :