# HG changeset patch # User Brett Smith # Date 1224469250 14400 # Node ID d9319958bb5a06394f2f6d14e6d5ad3eeb4d2f0e # Parent b19bdd67aa6c7675202ca81abd48308cf0de3c32 Add RAR support. Thanks to Peter Kelemen for the patch. diff -r b19bdd67aa6c -r d9319958bb5a contributions.mbox --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contributions.mbox Sun Oct 19 22:20:50 2008 -0400 @@ -0,0 +1,109 @@ +From Peter.Kelemen@gmail.com Fri Sep 19 18:51:00 2008 +Return-Path: +Date: Sat, 20 Sep 2008 00:51:17 +0200 +From: KELEMEN Peter +To: Brett Smith +Subject: [PATCH] dtrx: RAR support +Message-ID: <20080919225117.GA993@kaylee> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.5.17+20080114 (2008-01-14) +Status: RO +X-Status: A +Content-Length: 1589 +Lines: 48 + +Brett, + +The following patch adds RAR support for dtrx. + +HTH, +Peter + +diff -r ececf7836546 scripts/dtrx +--- a/scripts/dtrx Tue Sep 16 21:51:59 2008 -0400 ++++ b/scripts/dtrx Sat Sep 20 00:50:16 2008 +0200 +@@ -515,6 +515,25 @@ class ShieldExtractor(NoPipeExtractor): + return result + + ++class RarExtractor(NoPipeExtractor): ++ file_type = 'RAR archive' ++ extract_command = ['unrar', 'x'] ++ list_command = ['unrar', 'l'] ++ border_re = re.compile('^-+$') ++ ++ def get_filenames(self): ++ inside = False ++ for line in NoPipeExtractor.get_filenames(self): ++ if self.border_re.match(line): ++ if inside: ++ break ++ else: ++ inside = True ++ elif inside: ++ yield line.split(' ')[1] ++ self.archive.close() ++ ++ + class BaseHandler(object): + def __init__(self, extractor, options): + self.extractor = extractor +@@ -775,6 +794,10 @@ class ExtractorBuilder(object): + 'mimetypes': ('x-cab',), + 'extensions': ('cab',), + 'magic': ('Microsoft Cabinet Archive',)}, ++ 'rar': {'extractor': RarExtractor, ++ 'mimetypes': ('rar',), ++ 'extensions': ('rar'), ++ 'magic': ('RAR archive')}, + 'shield': {'extractor': ShieldExtractor, + 'mimetypes': ('x-cab',), + 'extensions': ('cab', 'hdr'), + + +From Peter.Kelemen@gmail.com Wed Sep 24 09:42:18 2008 +X-Original-To: me@brettcsmith.org +Date: Wed, 24 Sep 2008 15:31:18 +0200 +From: KELEMEN Peter +To: Brett Smith +Subject: Re: [PATCH] dtrx: RAR support +Message-ID: <20080924133118.GG8943@kyra> +References: <20080919225117.GA993@kaylee> <20080921180522.GB15446@canonical.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +In-Reply-To: <20080921180522.GB15446@canonical.org> +User-Agent: Mutt/1.5.17+20080114 (2008-01-14) +Status: RO +Content-Length: 684 +Lines: 25 + +* Brett Smith (me@brettcsmith.org) [20080921 14:05]: + +> Thanks very much for this; it looks great. + +You're welcome. + +> Can you please confirm for me that it's licensed under GPLv3 or +> any later version? A simple "yes" will do. :) + +Sure, GPLv3 is OK. + +> Also, do you want me to add any copyright notice(s) for your +> contribution? + +I'm ambivalent, I trust your judgement. Should you choose to do +so, please use my Peter.Kelemen@gmail.com address. + +Thanks, +Peter + +-- + .+'''+. .+'''+. .+'''+. .+'''+. .+'' + Kelemen Péter / \ / \ Peter.Kelemen@gmail.com +.+' `+...+' `+...+' `+...+' `+...+' + + diff -r b19bdd67aa6c -r d9319958bb5a scripts/dtrx --- a/scripts/dtrx Sat Jul 26 13:02:53 2008 -0400 +++ b/scripts/dtrx Sun Oct 19 22:20:50 2008 -0400 @@ -1,7 +1,9 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- # # dtrx -- Intelligently extract various archive types. -# Copyright (c) 2006, 2007, 2008 Brett Smith . +# Copyright ⓒ 2006, 2007, 2008 Brett Smith +# Copyright ⓒ 2008 Peter Kelemen # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -515,6 +517,25 @@ return result +class RarExtractor(NoPipeExtractor): + file_type = 'RAR archive' + extract_command = ['unrar', 'x'] + list_command = ['unrar', 'l'] + border_re = re.compile('^-+$') + + def get_filenames(self): + inside = False + for line in NoPipeExtractor.get_filenames(self): + if self.border_re.match(line): + if inside: + break + else: + inside = True + elif inside: + yield line.split(' ')[1] + self.archive.close() + + class BaseHandler(object): def __init__(self, extractor, options): self.extractor = extractor @@ -775,6 +796,10 @@ 'mimetypes': ('x-cab',), 'extensions': ('cab',), 'magic': ('Microsoft Cabinet Archive',)}, + 'rar': {'extractor': RarExtractor, + 'mimetypes': ('rar',), + 'extensions': ('rar',), + 'magic': ('RAR archive',)}, 'shield': {'extractor': ShieldExtractor, 'mimetypes': ('x-cab',), 'extensions': ('cab', 'hdr'),