[bitbake-devel,03/14] toaster: do not load all available timezones

Submitted by Alexandru DAMIAN on April 4, 2014, 2:10 p.m.

Details

Message ID 8ab63a668e94e4179850e4e8d901e719d071d3bc.1396620556.git.alexandru.damian@intel.com
State New
Headers show

Commit Message

Alexandru DAMIAN April 4, 2014, 2:10 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch makes sure that we only load pytz-recognized
timezones. Pytz is used to transform the timezone information
for the database queries, and needs to be able to deal with
the TIME_ZONE value that we set up.

[YOCTO #6093]

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 lib/toaster/toastermain/settings.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index e26ee3c..e39b4cb 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -64,7 +64,13 @@  else:
     for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
         for fn in filenames:
             filepath = os.path.join(dirpath, fn)
-            zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = filepath.lstrip(ZONEINFOPATH).strip()
+            try:
+                import pytz
+                zonename = filepath.lstrip(ZONEINFOPATH).strip()
+                if pytz.timezone(zonename) is not None:
+                    zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
+            except Exception:
+                pass
 
     TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime').read()).hexdigest()]
 

Comments

Paul Eggleton April 4, 2014, 3:20 p.m.
On Friday 04 April 2014 15:10:42 Alex DAMIAN wrote:
> From: Alexandru DAMIAN <alexandru.damian@intel.com>
> 
> This patch makes sure that we only load pytz-recognized
> timezones. Pytz is used to transform the timezone information
> for the database queries, and needs to be able to deal with
> the TIME_ZONE value that we set up.
> 
> [YOCTO #6093]
> 
> Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
> ---
>  lib/toaster/toastermain/settings.py | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/toaster/toastermain/settings.py
> b/lib/toaster/toastermain/settings.py index e26ee3c..e39b4cb 100644
> --- a/lib/toaster/toastermain/settings.py
> +++ b/lib/toaster/toastermain/settings.py
> @@ -64,7 +64,13 @@ else:
>      for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
>          for fn in filenames:
>              filepath = os.path.join(dirpath, fn)
> -            zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] =
> filepath.lstrip(ZONEINFOPATH).strip() +            try:
> +                import pytz
> +                zonename = filepath.lstrip(ZONEINFOPATH).strip()
> +                if pytz.timezone(zonename) is not None:
> +                   
> zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename 
> +          except Exception:
> +                pass

Please do not do blanket exception catching like this. You need to catch the 
exact class of exception you expect to receive.

Cheers,
Paul
Alexandru DAMIAN April 7, 2014, 10:10 a.m.
Thank you for spotting this,

New patch will be sent with the next submission.

Thanks,
Alex


On Fri, Apr 4, 2014 at 4:20 PM, Paul Eggleton <paul.eggleton@linux.intel.com
> wrote:

> On Friday 04 April 2014 15:10:42 Alex DAMIAN wrote:
> > From: Alexandru DAMIAN <alexandru.damian@intel.com>
> >
> > This patch makes sure that we only load pytz-recognized
> > timezones. Pytz is used to transform the timezone information
> > for the database queries, and needs to be able to deal with
> > the TIME_ZONE value that we set up.
> >
> > [YOCTO #6093]
> >
> > Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
> > ---
> >  lib/toaster/toastermain/settings.py | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/toaster/toastermain/settings.py
> > b/lib/toaster/toastermain/settings.py index e26ee3c..e39b4cb 100644
> > --- a/lib/toaster/toastermain/settings.py
> > +++ b/lib/toaster/toastermain/settings.py
> > @@ -64,7 +64,13 @@ else:
> >      for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
> >          for fn in filenames:
> >              filepath = os.path.join(dirpath, fn)
> > -
>  zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] =
> > filepath.lstrip(ZONEINFOPATH).strip() +            try:
> > +                import pytz
> > +                zonename = filepath.lstrip(ZONEINFOPATH).strip()
> > +                if pytz.timezone(zonename) is not None:
> > +
> > zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
> > +          except Exception:
> > +                pass
>
> Please do not do blanket exception catching like this. You need to catch
> the
> exact class of exception you expect to receive.
>
> Cheers,
> Paul
>
> --
>
> Paul Eggleton
> Intel Open Source Technology Centre
>