Gentoo Archives: gentoo-dev

From: hasufell <hasufell@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] enhancement for doicon/newicon in eutils.eclass
Date: Thu, 24 May 2012 00:19:41
Message-Id: 4FBD7DCC.1010607@gentoo.org
In Reply to: Re: [gentoo-dev] enhancement for doicon/newicon in eutils.eclass by Mike Frysinger
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA1
3
4 On 05/22/2012 04:49 AM, Mike Frysinger wrote:
5 > On Sunday 20 May 2012 19:24:13 hasufell wrote:
6 >> case ${2} in
7 >
8 > please use $1/$2/etc... with positional variables when possible
9 >
10 >> 16|22|24|32|36|48|64|72|96|128|192|256) size=${2}x${2};;
11 >> 16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|
12 > 192x192|256x256)
13 >> size=${2};; scalable) size=scalable;; *) eqawarn "${2} is an
14 >> unsupported icon size!" ((++ret));; esac
15 >
16 > you can write this w/out having to duplicate two lists: size= if [[
17 > $2 == "scalable" ]] ; then size=$2 elif [[ ${2:0:2}x${2:0:2} ==
18 > "$2" ]] ; then size=${2:0:2} case ${size} in
19 > 16|22|24|32|36|48|64|72|96|128|192|256) ;; *) size= ;; esac fi if
20 > [[ -z ${size} ]] ; then eqawarn "${2} is an unsupported icon
21 > size!" ((++ret)) fi shift 2
22 >
23 > shift 2;; -t|--theme) theme=${2} shift 2;; -c|--context)
24 > context=${2} shift 2;; *)
25 >> if [[ -z ${size} ]] ; then dir=/usr/share/pixmaps else
26 >> dir=/usr/share/icons/${theme}/${size}/${context} fi insinto
27 >> "${dir}"
28 >
29 > considering you only use $dir once, you could just call `insinto`
30 > directly on the path rather than using the dir variable at all
31 >
32 >> elif [[ -d ${1} ]] ; then for i in "${1}"/*.{png,svg} ; do doins
33 >> "${i}" ((ret+=$?)) done
34 >
35 > why loop ? `doins "${1}"/*.{png,svg}` works just as well
36 >
37 > you probably want to enable nullglobbing here, otherwise this will
38 > cause problems if you try to doicon on a dir that contains just
39 > svg.
40 >
41 > also, what about other file types ? people install xpm, svgz, gif,
42 > and other file types ...
43 >
44 >> exit ${ret}
45 >
46 > bash masks error codes to [0..255], so all the ret updates should
47 > probably be changed to just: ret=1
48 >
49 > after all, i doubt anyone cares how many errors there were, just
50 > that one occurred. and while you're here, might want to make it
51 > auto die on failure like we've done with all our other helpers.
52 > -mike
53
54 Thanks, I'v implemented most of that, but your proposal about
55 non-duplicated list in case) has multiple problems. The only cases
56 that actually work with that snippet are:
57 16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|scalable.
58 All others will fail (like 128x128 or just 48).
59 So it would end up like this:
60
61 case $1 in
62 -s|--size)
63 if [[ ${2:0:2}x${2:0:2} == "$2" ]] ; then
64 size=${2:0:2}
65 elif [[ ${2:0:3}x${2:0:3} == "$2" ]] ; then
66 size=${2:0:3}
67 else
68 size=${2}
69 fi
70 case ${size} in
71 16|22|24|32|36|48|64|72|96|128|192|256)
72 size=${size}x${size};;
73 scalable)
74 ;;
75 *)
76 eerror "${size} is an unsupported icon size!"
77 exit 1;;
78 esac
79 shift 2;;
80 -t|--theme)
81
82
83 This does not really look cleaner than just using two lists. I would
84 prefer the latter for readability.
85
86 -----BEGIN PGP SIGNATURE-----
87 Version: GnuPG v2.0.19 (GNU/Linux)
88 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
89
90 iQEcBAEBAgAGBQJPvX3MAAoJEFpvPKfnPDWzxvMH/16kN1Zkby6LHg2Ev7H2qNPh
91 ajbqVonTuuLnIVxEwXYXYABEkF+qwD5xnJPMEclvkn8FXAVerFeyaxJgBelldXnr
92 DJMHiPhz0umJaMfvAFrEsbIo5IrxKMTpMMj3fuu5ruQMrSboV4alPSM7l2haXZ5W
93 3TbfbFmWoQzft1DolDlFb38M0TtRko7viZ1KQJUZjxCEClh8tEiOrQVxR8xcoi33
94 MiwEVZlib4KnWetq3qGZdU+xRFi/yzUmtFVv0pfbYIV51w4KHoi8cD6OkpiVzLdI
95 bhWCmyDeKq6wOcfXfcfGKzYc+2M/hP8xkhiG3/KjDXe6FUzdG63+U1Wmu521VDM=
96 =Rn8t
97 -----END PGP SIGNATURE-----

Replies

Subject Author
Re: [gentoo-dev] enhancement for doicon/newicon in eutils.eclass Mike Frysinger <vapier@g.o>