from wataru.rules.models import (
    EmptyFile,
    EmptyDirectory,
    ProjectRoot,
)


class RuleGraph:
    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)

        self._project = ProjectRoot (
            rootdir = project_rootdir,
            name = project_name,
            virtualenv = project_venv
        )
        if project_children is None:
            return self # プロジェクトが空なので終了

        self._process_recursive(self._project, project_children)
        return self

    def _process_recursive(self, node, d_children):
        for dc in d_children:
            if dc['type'] == 'file':
                f = EmptyFile(parent=node, name=dc['name'])
                node.add_node(f)
            elif dc['type'] == 'directory':
                d = EmptyDirectory(parent=node, name=dc['name'])
                if 'children' in dc:
                    self._process_recursive(d, dc['children'])
                node.add_node(d)
            else:
                raise ValueError('invalid node type')

    @property
    def project(self):
        return self._project


def get_by_theme(tm):
    return RuleGraph(tm).build()

55946e91a0ea24ee284862ce7bb8aab7b3720a52
<mask token>


class RuleGraph:

    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)
        self._project = ProjectRoot(rootdir=project_rootdir, name=
            project_name, virtualenv=project_venv)
        if project_children is None:
            return self
        self._process_recursive(self._project, project_children)
        return self
    <mask token>

    @property
    def project(self):
        return self._project


<mask token>

<mask token>


class RuleGraph:

    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)
        self._project = ProjectRoot(rootdir=project_rootdir, name=
            project_name, virtualenv=project_venv)
        if project_children is None:
            return self
        self._process_recursive(self._project, project_children)
        return self

    def _process_recursive(self, node, d_children):
        for dc in d_children:
            if dc['type'] == 'file':
                f = EmptyFile(parent=node, name=dc['name'])
                node.add_node(f)
            elif dc['type'] == 'directory':
                d = EmptyDirectory(parent=node, name=dc['name'])
                if 'children' in dc:
                    self._process_recursive(d, dc['children'])
                node.add_node(d)
            else:
                raise ValueError('invalid node type')

    @property
    def project(self):
        return self._project


<mask token>

<mask token>


class RuleGraph:

    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)
        self._project = ProjectRoot(rootdir=project_rootdir, name=
            project_name, virtualenv=project_venv)
        if project_children is None:
            return self
        self._process_recursive(self._project, project_children)
        return self

    def _process_recursive(self, node, d_children):
        for dc in d_children:
            if dc['type'] == 'file':
                f = EmptyFile(parent=node, name=dc['name'])
                node.add_node(f)
            elif dc['type'] == 'directory':
                d = EmptyDirectory(parent=node, name=dc['name'])
                if 'children' in dc:
                    self._process_recursive(d, dc['children'])
                node.add_node(d)
            else:
                raise ValueError('invalid node type')

    @property
    def project(self):
        return self._project


def get_by_theme(tm):
    return RuleGraph(tm).build()

from wataru.rules.models import EmptyFile, EmptyDirectory, ProjectRoot


class RuleGraph:

    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)
        self._project = ProjectRoot(rootdir=project_rootdir, name=
            project_name, virtualenv=project_venv)
        if project_children is None:
            return self
        self._process_recursive(self._project, project_children)
        return self

    def _process_recursive(self, node, d_children):
        for dc in d_children:
            if dc['type'] == 'file':
                f = EmptyFile(parent=node, name=dc['name'])
                node.add_node(f)
            elif dc['type'] == 'directory':
                d = EmptyDirectory(parent=node, name=dc['name'])
                if 'children' in dc:
                    self._process_recursive(d, dc['children'])
                node.add_node(d)
            else:
                raise ValueError('invalid node type')

    @property
    def project(self):
        return self._project


def get_by_theme(tm):
    return RuleGraph(tm).build()

from wataru.rules.models import (
    EmptyFile,
    EmptyDirectory,
    ProjectRoot,
)


class RuleGraph:
    def __init__(self, tm):
        self._gd = tm.top_node
        self._project = None

    def build(self):
        project_name = self._gd['name']
        project_rootdir = self._gd['rootdir']
        project_children = self._gd.get('children')
        project_venv = self._gd.get('virtualenv', True)

        self._project = ProjectRoot (
            rootdir = project_rootdir,
            name = project_name,
            virtualenv = project_venv
        )
        if project_children is None:
            return self # プロジェクトが空なので終了

        self._process_recursive(self._project, project_children)
        return self

    def _process_recursive(self, node, d_children):
        for dc in d_children:
            if dc['type'] == 'file':
                f = EmptyFile(parent=node, name=dc['name'])
                node.add_node(f)
            elif dc['type'] == 'directory':
                d = EmptyDirectory(parent=node, name=dc['name'])
                if 'children' in dc:
                    self._process_recursive(d, dc['children'])
                node.add_node(d)
            else:
                raise ValueError('invalid node type')

    @property
    def project(self):
        return self._project


def get_by_theme(tm):
    return RuleGraph(tm).build()
