FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-20-2011, 06:12 PM
Dave Reisner
 
Default repo-add: reuse write_list_entry for desc file

Repurpose the write_list_entry function for everything we write to the
depends and desc files by appending our own extra newline after each
single line data point.

This also refactors write_list_entry into a single printf statement.

Signed-off-by: Dave Reisner <d@falconindy.com>
---
More repo-add madness. Reusable code, ftw.

dave

scripts/repo-add.sh.in | 31 +++++++++++++++----------------
1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 14506dc..a23f89e 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -88,8 +88,7 @@ There is NO WARRANTY, to the extent permitted by law.
")"
# arg3 - File to write to
write_list_entry() {
if [[ -n $2 ]]; then
- echo "%$1%" >>$3
- echo -e $2 >>$3
+ printf "%%%s%%
$2
" "$1" >>"$3"
fi
}

@@ -301,27 +300,27 @@ db_write_entry()

# create desc entry
msg2 "$(gettext "Creating '%s' db entry...")" 'desc'
- echo -e "%FILENAME%
${1##*/}
" >>desc
- echo -e "%NAME%
$pkgname
" >>desc
- [[ -n $pkgbase ]] && echo -e "%BASE%
$pkgbase
" >>desc
- echo -e "%VERSION%
$pkgver
" >>desc
- [[ -n $pkgdesc ]] && echo -e "%DESC%
$pkgdesc
" >>desc
+ write_list_entry "FILENAME" "${1##*/}
" "desc"
+ write_list_entry "NAME" "$pkgname
" "desc"
+ [[ -n $pkgbase ]] && write_list_entry "BASE" "$pkgbase
" "desc"
+ write_list_entry "VERSION" "$pkgver
" "desc"
+ [[ -n $pkgdesc ]] && write_list_entry "DESC" "$pkgdesc
" "desc"
write_list_entry "GROUPS" "$_groups" "desc"
- [[ -n $csize ]] && echo -e "%CSIZE%
$csize
" >>desc
- [[ -n $size ]] && echo -e "%ISIZE%
$size
" >>desc
+ [[ -n $csize ]] && write_list_entry "CSIZE" "$csize
" "desc"
+ [[ -n $size ]] && write_list_entry "ISIZE" "$size
" "desc"

# add checksums
- echo -e "%MD5SUM%
$md5sum
" >>desc
- echo -e "%SHA256SUM%
$sha256sum
" >>desc
+ write_list_entry "MD5SUM" "$md5sum
" "desc"
+ write_list_entry "SHA256SUM" "$sha256sum
" "desc"

# add PGP sig
- [[ -n $pgpsig ]] && echo -e "%PGPSIG%
$pgpsig
" >>desc
+ [[ -n $pgpsig ]] && write_list_entry "PGPSIG" "$pgpsig
" "desc"

- [[ -n $url ]] && echo -e "%URL%
$url
" >>desc
+ [[ -n $url ]] && write_list_entry "URL" "$url
" "desc"
write_list_entry "LICENSE" "$_licenses" "desc"
- [[ -n $arch ]] && echo -e "%ARCH%
$arch
" >>desc
- [[ -n $builddate ]] && echo -e "%BUILDDATE%
$builddate
" >>desc
- [[ -n $packager ]] && echo -e "%PACKAGER%
$packager
" >>desc
+ [[ -n $arch ]] && write_list_entry "ARCH" "$arch
" "desc"
+ [[ -n $builddate ]] && write_list_entry "BUILDDATE" "$builddate
" "desc"
+ [[ -n $packager ]] && write_list_entry "PACKAGER" "$packager
" "desc"
write_list_entry "REPLACES" "$_replaces" "desc"

# create depends entry
--
1.7.5.4
 
Old 06-20-2011, 06:38 PM
Dave Reisner
 
Default repo-add: reuse write_list_entry for desc file

On Mon, Jun 20, 2011 at 01:27:07PM -0500, Dan McGee wrote:
> On Mon, Jun 20, 2011 at 1:12 PM, Dave Reisner <d@falconindy.com> wrote:
> > Repurpose the write_list_entry function for everything we write to the
> > depends and desc files by appending our own extra newline after each
> > single line data point.
> >
> > This also refactors write_list_entry into a single printf statement.
> >
> > Signed-off-by: Dave Reisner <d@falconindy.com>
> > ---
> > More repo-add madness. Reusable code, ftw.
> >
> > dave
> >
> > *scripts/repo-add.sh.in | * 31 +++++++++++++++----------------
> > *1 files changed, 15 insertions(+), 16 deletions(-)
> >
> > diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> > index 14506dc..a23f89e 100644
> > --- a/scripts/repo-add.sh.in
> > +++ b/scripts/repo-add.sh.in
> > @@ -88,8 +88,7 @@ There is NO WARRANTY, to the extent permitted by law.
")"
> > *# * * * * * * *arg3 - File to write to
> > *write_list_entry() {
> > * * * *if [[ -n $2 ]]; then
> > - * * * * * * * echo "%$1%" >>$3
> > - * * * * * * * echo -e $2 >>$3
> > + * * * * * * * printf "%%%s%%
$2
" "$1" >>"$3"
> Does it make sense to use both %s and var substitution at the same
> time? Why not:
> printf "%%%s%%
%s
" "$1" "$2" >>"$3"
>

$ foo=bar
baz
$ print '%s
' "$foo"
bar
baz

In other words, the embedded newlines have to be within the format.
But really, I'm just going to scrap this and redo it properly. We should
use arrays here and a proper format function that looks something like:

format_list_entry() {
local field=$1; shift

if (( $# )); then
printf '%%%s%%
' "$field"
printf '%s
' "$@"
printf '
'
fi
}

We then do the writing to file on the calling side, e.g.,

{
format_list_entry 'PKGNAME' foo
format_list_entry 'PKGVER' 1.2.3
format_list_entry 'DEPENDS' 'libfoo' 'libbar' 'libbaz'
} >desc

> > * * * *fi
> > *}
> >
> > @@ -301,27 +300,27 @@ db_write_entry()
> >
> > * * * *# create desc entry
> > * * * *msg2 "$(gettext "Creating '%s' db entry...")" 'desc'
> > - * * * echo -e "%FILENAME%
${1##*/}
" >>desc
> > - * * * echo -e "%NAME%
$pkgname
" >>desc
> > - * * * [[ -n $pkgbase ]] && echo -e "%BASE%
$pkgbase
" >>desc
> > - * * * echo -e "%VERSION%
$pkgver
" >>desc
> > - * * * [[ -n $pkgdesc ]] && echo -e "%DESC%
$pkgdesc
" >>desc
> > + * * * write_list_entry "FILENAME" "${1##*/}
" "desc"
> > + * * * write_list_entry "NAME" "$pkgname
" "desc"
> > + * * * [[ -n $pkgbase ]] && write_list_entry "BASE" "$pkgbase
" "desc"
> It would be cleaner to move the -n bits inside write_list_entry.
> Otherwise I like this change to make things a bit more consistent.
>

Agreed. Makes things a lot cleaner and easier to read. Covered above in
conceptual blah blah blah.

> > + * * * write_list_entry "VERSION" "$pkgver
" "desc"
> > + * * * [[ -n $pkgdesc ]] && write_list_entry "DESC" "$pkgdesc
" "desc"
> > * * * *write_list_entry "GROUPS" "$_groups" "desc"
> > - * * * [[ -n $csize ]] && echo -e "%CSIZE%
$csize
" >>desc
> > - * * * [[ -n $size ]] && echo -e "%ISIZE%
$size
" >>desc
> > + * * * [[ -n $csize ]] && write_list_entry "CSIZE" "$csize
" "desc"
> > + * * * [[ -n $size ]] && write_list_entry "ISIZE" "$size
" "desc"
> >
> > * * * *# add checksums
> > - * * * echo -e "%MD5SUM%
$md5sum
" >>desc
> > - * * * echo -e "%SHA256SUM%
$sha256sum
" >>desc
> > + * * * write_list_entry "MD5SUM" "$md5sum
" "desc"
> > + * * * write_list_entry "SHA256SUM" "$sha256sum
" "desc"
> >
> > * * * *# add PGP sig
> > - * * * [[ -n $pgpsig ]] && echo -e "%PGPSIG%
$pgpsig
" >>desc
> > + * * * [[ -n $pgpsig ]] && write_list_entry "PGPSIG" "$pgpsig
" "desc"
> >
> > - * * * [[ -n $url ]] && echo -e "%URL%
$url
" >>desc
> > + * * * [[ -n $url ]] && write_list_entry "URL" "$url
" "desc"
> > * * * *write_list_entry "LICENSE" "$_licenses" "desc"
> > - * * * [[ -n $arch ]] && echo -e "%ARCH%
$arch
" >>desc
> > - * * * [[ -n $builddate ]] && echo -e "%BUILDDATE%
$builddate
" >>desc
> > - * * * [[ -n $packager ]] && echo -e "%PACKAGER%
$packager
" >>desc
> > + * * * [[ -n $arch ]] && write_list_entry "ARCH" "$arch
" "desc"
> > + * * * [[ -n $builddate ]] && write_list_entry "BUILDDATE" "$builddate
" "desc"
> > + * * * [[ -n $packager ]] && write_list_entry "PACKAGER" "$packager
" "desc"
> > * * * *write_list_entry "REPLACES" "$_replaces" "desc"
> >
> > * * * *# create depends entry
> > --
> > 1.7.5.4
> >
> >
> >
>
 

Thread Tools




All times are GMT. The time now is 08:58 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org