import mafs

import json

fs = mafs.MagicFS()
fs.add_argument('file', help='json file to read from')

# read json file
with open(fs.args.file) as f:
    items = json.load(f)


def dig(d, parts):
    if parts:
        try:
            res = d.get(parts[0])
            if res:
                return dig(res, parts[1:])
        except (KeyError, AttributeError):
            return None
    else:
        return d


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)

    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 0o755 | mafs.FileType.DIRECTORY}
        else:
            return {}

    raise FileNotFoundError()


fs.run()

9453e4ce2cd92fa79bea82961d7a3c272ae9a135
<mask token>


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)
    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 493 | mafs.FileType.DIRECTORY}
        else:
            return {}
    raise FileNotFoundError()


<mask token>

<mask token>


def dig(d, parts):
    if parts:
        try:
            res = d.get(parts[0])
            if res:
                return dig(res, parts[1:])
        except (KeyError, AttributeError):
            return None
    else:
        return d


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)
    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 493 | mafs.FileType.DIRECTORY}
        else:
            return {}
    raise FileNotFoundError()


<mask token>

<mask token>
fs.add_argument('file', help='json file to read from')
with open(fs.args.file) as f:
    items = json.load(f)


def dig(d, parts):
    if parts:
        try:
            res = d.get(parts[0])
            if res:
                return dig(res, parts[1:])
        except (KeyError, AttributeError):
            return None
    else:
        return d


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)
    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 493 | mafs.FileType.DIRECTORY}
        else:
            return {}
    raise FileNotFoundError()


fs.run()

import mafs
import json
fs = mafs.MagicFS()
fs.add_argument('file', help='json file to read from')
with open(fs.args.file) as f:
    items = json.load(f)


def dig(d, parts):
    if parts:
        try:
            res = d.get(parts[0])
            if res:
                return dig(res, parts[1:])
        except (KeyError, AttributeError):
            return None
    else:
        return d


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)
    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 493 | mafs.FileType.DIRECTORY}
        else:
            return {}
    raise FileNotFoundError()


fs.run()

import mafs

import json

fs = mafs.MagicFS()
fs.add_argument('file', help='json file to read from')

# read json file
with open(fs.args.file) as f:
    items = json.load(f)


def dig(d, parts):
    if parts:
        try:
            res = d.get(parts[0])
            if res:
                return dig(res, parts[1:])
        except (KeyError, AttributeError):
            return None
    else:
        return d


@fs.read('/*item')
def read_item(path, ps):
    return str(dig(items, ps.item)) + '\n'


@fs.list('/')
def list_root(path, ps):
    return items.keys()


@fs.list('/*item')
def list_item(path, ps):
    return dig(items, ps.item).keys()


@fs.stat('/*item')
def stat_item(path, ps):
    item = dig(items, ps.item)

    if item:
        if hasattr(item, 'get'):
            return {'st_mode': 0o755 | mafs.FileType.DIRECTORY}
        else:
            return {}

    raise FileNotFoundError()


fs.run()
