Gentoo Archives: gentoo-dev

From: Chris White <chriswhite@g.o>
To: gentoo-dev@××××××××××××.org
Subject: Re: [gentoo-dev] Parsing emerge
Date: Sat, 05 Mar 2005 05:46:11
Message-Id: 1109999484.11103.54.camel@secures
In Reply to: [gentoo-dev] Parsing emerge by Chris White
1 2005-03-04 (金) の 17:29 +0900 に Chris White さんは書きました:
2 I've updated the script now, it has a better more functional layout than
3 before (A large page script :).
4
5 Re-cap of the install is here:
6
7 >
8 > http://dev.gentoo.org/~chriswhite/emerge_parse.pl
9 >
10 > In order to install this, you'll need to `g-cpan.pl Expect` in order to
11 > get the Expect module (which interestingly enough also installs the dep
12 > of IO::Tty).
13
14 the main update was the parsing of category, package, and versions from
15 ebuilds. The code of interest comes from these lines of code:
16
17 sub package_nvsplit {
18 $i=0;
19 while($_[$i] !~ /^\d/) {
20 $i++;
21 }
22 $package_end=$i-1;
23 $pn=join("-",@_[0..$package_end]);
24 $pv=@_[$i..$#package_array];
25 return $pn, $pv;
26 }
27
28 So for those interested in parsing out package versions and what not,
29 this is basically how to go about it. First, you splitup the category
30 and the package name+version (or $P). So...
31
32 media-video/xine-lib-1.0 gets splitup into:
33 media-video (category) and xine-lib-1.0 ($P). Now then, to get package
34 and version seperation, one simply splits up $P with the - seperator.
35 This gives us:
36
37 xine lib 1.0
38
39 Which, a simple loop checks to see if we've hit a section that starts
40 with a digit (the version number), and re-combines the values before it
41 with -'s, giving us:
42
43 $pv = 1.0
44 $pn = xine-lib
45
46 So there you have it, the basis on seperation of package category, name,
47 and version. Hopefully this will help those who wish to hack around a
48 little get an idea of what's involved in the minute areas of portage.
49 Note that while the code is perl, the concept is very language
50 non-specific (I could do one in C.. but I'd rather save some of my
51 sanity ;).
52
53 Next stop will be getting USE flag descriptions in a more speedy manner
54 than simple grep-ing. Please note that suggestions for
55 improvement/comments/etc. are welcome, and I hope this turns into a nice
56 informative developer's discussion.
57
58 _big note_
59 I'd also like to thank Nick (carpaski) for his insight on the above
60 code :).
61 _big note_

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-dev] Parsing emerge Aron Griffis <agriffis@g.o>