1 |
On Thu, 15 Jan 2015 20:53:02 -0800 |
2 |
Zac Medico <zmedico@g.o> wrote: |
3 |
|
4 |
> On 01/15/2015 07:00 PM, Brian Dolbec wrote: |
5 |
> > On Thu, 15 Jan 2015 17:27:23 -0800 |
6 |
> > Zac Medico <zmedico@g.o> wrote: |
7 |
> >> # Add -q to bzip2 opts, in order to avoid |
8 |
> >> "trailing garbage after # EOF ignored" warning messages due to |
9 |
> >> xpak trailer. |
10 |
> >> + if comp == "bzip2": |
11 |
> >> + decomp_cmd = |
12 |
> >> "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}" |
13 |
> >> + elif comp == "xz": |
14 |
> >> + decomp_cmd = "xz -d" |
15 |
> >> + elif comp == "gzip": |
16 |
> >> + decomp_cmd = "gzip -d" |
17 |
> >> + else: |
18 |
> >> + raise AssertionError("Unexpected |
19 |
> > |
20 |
> > No offense, but yuk to the if foo .... else bar... else... |
21 |
> |
22 |
> It's simple and it works. Why don't we just go with this simple |
23 |
> approach first, and add fancy stuff later on? |
24 |
> |
25 |
|
26 |
PORTAGE_COMPRESSORS = { |
27 |
"bzip2": "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}", |
28 |
"xz": "xz -d", |
29 |
"gzip": "gzip -d", |
30 |
} |
31 |
|
32 |
try: |
33 |
decomp_cmd = PORTAGE_COMPRESSORS[comp] |
34 |
except: AtributeError: |
35 |
writemsg("You fool we don't support the %s (de)compression type!) |
36 |
|
37 |
|
38 |
|
39 |
makes it simple to add new types, saves mile long if, elif, elif, else |
40 |
code ;) There is also a good chance the code won't need editing to add |
41 |
a new type, just add it to the dict definition. Second advantage is the |
42 |
code should be slightly faster. (yes, I realize this isn't in a |
43 |
multi k iteration loop, so speed-up is minuscule) but portage can't |
44 |
afford to waste many cycles ;) it all adds up... |
45 |
|
46 |
P.S. I don't expect you to use the writemsg(...) as is :D |
47 |
|
48 |
|
49 |
|
50 |
> > I already have code that does this much better, I decided I was |
51 |
> > going to release it separately from catalyst because it is |
52 |
> > generally useful and in many ways more future proof. I know you |
53 |
> > were interested in it, but I hadn't gotten around to establishing |
54 |
> > it in a separate repo. I also didn't know you were already working |
55 |
> > on this. |
56 |
> > |
57 |
> > I've attached it to this email for you to look over. It needs a |
58 |
> > bit of work for an independent release, but it is easily extended |
59 |
> > with configuration changes. It can also be easily extended with |
60 |
> > custom commands if needed. |
61 |
> > |
62 |
> > If you are interested, it would not take long to have it release |
63 |
> > worthy and in the tree. |
64 |
> |
65 |
> I am interested in your library, but it does much more than is needed |
66 |
> in BinpkgExtractorAsync.The requirements are: |
67 |
> |
68 |
> 1) Map bzip2, xz, or gzip to an appropriate decompression command. The |
69 |
> command should be guaranteed to support -c and -q options, since |
70 |
> BinpkgExtractorAsync relies on them. |
71 |
> |
72 |
> 2) Respect the user's PORTAGE_BUNZIP2_COMMAND and |
73 |
> PORTAGE_BZIP2_COMMAND variables. |
74 |
|
75 |
yes, I know there is more there than is needed and a few options need |
76 |
adding. |
77 |
|
78 |
-- |
79 |
Brian Dolbec <dolsen> |