PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/layout.py

http://github.com/hyde/hyde
Python | 46 lines | 21 code | 8 blank | 17 comment | 6 complexity | fd199b74f184fb4bb1ad8f7e8cab2543 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Classes, functions and utilties related to hyde layouts
 4"""
 5import os
 6
 7from fswrap import File, Folder
 8
 9from hyde._compat import str
10
11HYDE_DATA = "HYDE_DATA"
12LAYOUTS = "layouts"
13
14
15class Layout(object):
16
17    """
18    Represents a layout package
19    """
20
21    @staticmethod
22    def find_layout(layout_name='basic'):
23        """
24        Find the layout with a given name.
25        Search order:
26        1. env(HYDE_DATA)
27        2. <hyde script path>/layouts/
28        """
29        layout_folder = None
30        if HYDE_DATA in os.environ:
31            layout_folder = Layout._get_layout_folder(
32                os.environ[HYDE_DATA], layout_name)
33        if not layout_folder:
34            layout_folder = Layout._get_layout_folder(
35                File(__file__).parent, layout_name)
36        return layout_folder
37
38    @staticmethod
39    def _get_layout_folder(root, layout_name='basic'):
40        """
41        Finds the layout folder from the given root folder.
42        If it does not exist, return None
43        """
44        layouts_folder = Folder(str(root)).child_folder(LAYOUTS)
45        layout_folder = layouts_folder.child_folder(layout_name)
46        return layout_folder if layout_folder.exists else None