Patchwork oe.types: add 'path' type

login
register
mail settings
Submitter Christopher Larson
Date Aug. 20, 2013, 2:48 a.m.
Message ID <1376966880-4557-1-git-send-email-kergoth@gmail.com>
Download mbox | patch
Permalink /patch/56013/
State Accepted
Commit 66eac2df0ccd0c7e17bf7f1117a7612d6151629c
Headers show

Comments

Christopher Larson - Aug. 20, 2013, 2:48 a.m.
From: Christopher Larson <chris_larson@mentor.com>

- path normalization ('normalize' flag, defaults to enabled)
- existence verification for paths we know should exist ('mustexist' flag)
- supports clean handling of relative paths ('relativeto' flag)

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
 meta/lib/oe/types.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Otavio Salvador - Aug. 20, 2013, 3:23 p.m.
On Mon, Aug 19, 2013 at 11:48 PM, Christopher Larson <kergoth@gmail.com> wrote:
> From: Christopher Larson <chris_larson@mentor.com>
>
> - path normalization ('normalize' flag, defaults to enabled)
> - existence verification for paths we know should exist ('mustexist' flag)
> - supports clean handling of relative paths ('relativeto' flag)
>
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>

Great addition :-)

> ---
>  meta/lib/oe/types.py | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
> index 5dac9de..7f47c17 100644
> --- a/meta/lib/oe/types.py
> +++ b/meta/lib/oe/types.py
> @@ -1,4 +1,7 @@
> +import errno
>  import re
> +import os
> +

No need for another new and empty line here.

Rest of code looks alright :-)
Christopher Larson - Aug. 20, 2013, 3:45 p.m.
On Tue, Aug 20, 2013 at 8:23 AM, Otavio Salvador <otavio@ossystems.com.br>wrote:

> On Mon, Aug 19, 2013 at 11:48 PM, Christopher Larson <kergoth@gmail.com>
> wrote:
> > From: Christopher Larson <chris_larson@mentor.com>
> >
> > - path normalization ('normalize' flag, defaults to enabled)
> > - existence verification for paths we know should exist ('mustexist'
> flag)
> > - supports clean handling of relative paths ('relativeto' flag)
> >
> > Signed-off-by: Christopher Larson <chris_larson@mentor.com>
>
> Great addition :-)
>
> > ---
> >  meta/lib/oe/types.py | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
> > index 5dac9de..7f47c17 100644
> > --- a/meta/lib/oe/types.py
> > +++ b/meta/lib/oe/types.py
> > @@ -1,4 +1,7 @@
> > +import errno
> >  import re
> > +import os
> > +
>
> No need for another new and empty line here.
>
> Rest of code looks alright :-)


Good call, will tweak slightly and re-submit. Thanks for the review.

Patch

diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index 5dac9de..7f47c17 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -1,4 +1,7 @@ 
+import errno
 import re
+import os
+
 
 class OEList(list):
     """OpenEmbedded 'list' type
@@ -133,3 +136,18 @@  def float(value, fromhex='false'):
         return _float.fromhex(value)
     else:
         return _float(value)
+
+def path(value, relativeto='', normalize='true', mustexist='false'):
+    value = os.path.join(relativeto, value)
+
+    if boolean(normalize):
+        value = os.path.normpath(value)
+
+    if boolean(mustexist):
+        try:
+            open(value, 'r')
+        except IOError as exc:
+            if exc.errno == errno.ENOENT:
+                raise ValueError("{0}: {1}".format(value, os.strerror(errno.ENOENT)))
+
+    return value