From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id CBB3BE00E28; Mon, 28 Sep 2015 02:02:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [134.134.136.20 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id A16D0E00C0B for ; Mon, 28 Sep 2015 02:02:27 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 28 Sep 2015 02:02:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,602,1437462000"; d="scan'208";a="778820730" Received: from linux.intel.com ([10.23.219.25]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2015 02:02:27 -0700 Received: from linux.intel.com (vmed.fi.intel.com [10.237.72.51]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTP id 0636A6A4083; Mon, 28 Sep 2015 02:01:30 -0700 (PDT) Date: Mon, 28 Sep 2015 12:02:21 +0300 From: Ed Bartosh To: Elliot Smith Message-ID: <20150928090221.GA7533@linux.intel.com> References: <1443098064-12972-1-git-send-email-elliot.smith@intel.com> MIME-Version: 1.0 In-Reply-To: <1443098064-12972-1-git-send-email-elliot.smith@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.5.21 (2010-09-15) Cc: toaster@yoctoproject.org Subject: Re: [review-request][PATCH] toaster: Use Python's mimetypes module X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: ed.bartosh@linux.intel.com List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2015 09:02:32 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Elliot, Patch looks good to me, thanks. Acked-by: Ed Bartosh On Thu, Sep 24, 2015 at 01:34:24PM +0100, Elliot Smith wrote: > filemagic is used to guess the mimetype of files when a user > requests a download. However, this adds a dependency on an > external library. > > Python does have a mimetypes module, though this guesses the > mimetype rather than doing anything clever with the actual > file content. But for our purposes, it's more than adequate. > (NB Django also uses this module when serving static files.) > > Use this instead of relying on any external code, and remove > the filemagic dependency. > > Signed-off-by: Elliot Smith > --- > bitbake/lib/toaster/toastergui/views.py | 15 +++++++++++---- > bitbake/toaster-requirements.txt | 1 - > 2 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py > index 8689a12..0a2a959 100755 > --- a/bitbake/lib/toaster/toastergui/views.py > +++ b/bitbake/lib/toaster/toastergui/views.py > @@ -46,19 +46,26 @@ from toastergui.templatetags.projecttags import json as jsonfilter > import json > from os.path import dirname > import itertools > +import mimetypes > > -import magic > import logging > > logger = logging.getLogger("toaster") > > class MimeTypeFinder(object): > - _magic = magic.Magic(flags = magic.MAGIC_MIME_TYPE) > + # setting this to False enables additional non-standard mimetypes > + # to be included in the guess > + _strict = False > > - # returns the mimetype for a file path > + # returns the mimetype for a file path as a string, > + # or 'application/octet-stream' if the type couldn't be guessed > @classmethod > def get_mimetype(self, path): > - return self._magic.id_filename(path) > + guess = mimetypes.guess_type(path, self._strict) > + guessed_type = guess[0] > + if guessed_type == None: > + guessed_type = 'application/octet-stream' > + return guessed_type > > # all new sessions should come through the landing page; > # determine in which mode we are running in, and redirect appropriately > diff --git a/bitbake/toaster-requirements.txt b/bitbake/toaster-requirements.txt > index c4a2221..1d7d21b 100644 > --- a/bitbake/toaster-requirements.txt > +++ b/bitbake/toaster-requirements.txt > @@ -2,5 +2,4 @@ Django==1.6 > South==0.8.4 > argparse==1.2.1 > wsgiref==0.1.2 > -filemagic==1.6 > beautifulsoup4>=4.4.0 > -- > Elliot Smith > Software Engineer > Intel OTC > > --------------------------------------------------------------------- > Intel Corporation (UK) Limited > Registered No. 1134945 (England) > Registered Office: Pipers Way, Swindon SN3 1RJ > VAT No: 860 2173 47 > > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies. > > -- > _______________________________________________ > toaster mailing list > toaster@yoctoproject.org > https://lists.yoctoproject.org/listinfo/toaster -- -- Regards, Ed