<commit_before>import random
from .models.context import Corpus
from .models.annotation import AnnotationKeySet, AnnotationKey

def split_corpus(session, corpus, train=0.8, development=0.1, test=0.1, seed=None):
    if train + development + test != 1:
        raise ValueError("Values for train + development + test must sum to 1")

    random.seed(seed)
    docs = [doc for doc in corpus.documents]
    docs.sort(key=lambda d: d.name)
    random.shuffle(docs)

    n = len(docs)
    num_train = int(train * n)
    num_development = int(development * n)

    train_corpus = Corpus(name=corpus.name + ' Training')
    for doc in docs[:num_train]:
        train_corpus.append(doc)
    session.add(train_corpus)
    print "%d Documents added to corpus %s" % (len(train_corpus), train_corpus.name)

    development_corpus = Corpus(name=corpus.name + ' Development')
    for doc in docs[num_train:num_train + num_development]:
        development_corpus.append(doc)
    session.add(development_corpus)
    print "%d Documents added to corpus %s" % (len(development_corpus), development_corpus.name)

    test_corpus = Corpus(name=corpus.name + ' Test')
    for doc in docs[num_train + num_development:]:
        test_corpus.append(doc)
    session.add(test_corpus)
    print "%d Documents added to corpus %s" % (len(test_corpus), test_corpus.name)

    session.commit()

def get_or_create_single_key_set(session, name):
    key_set = session.query(AnnotationKeySet).filter(AnnotationKeySet.name == name).first()
    if key_set is None:
        key_set = AnnotationKeySet(name=name)
        session.add(key_set)
        session.commit()

    if len(key_set) > 1:
        raise ValueError('AnnotationKeySet with name ' + unicode(name) + ' already exists and has more than one ' +
                         'AnnotationKey. Please specify a new name.')
    elif len(key_set) == 1:
        if key_set.keys[0].name == name:
            key = key_set.keys[0]
        else:
            raise ValueError('AnnotationKeySet named ' + unicode(name) + ' already exists and has one ' +
                             'AnnotationKey with a different name. Please specify a new name.')
    else:
        key = session.query(AnnotationKey).filter(AnnotationKey.name == name).first()
        if key is None:
            key = AnnotationKey(name=name)
            session.add(key)
            session.commit()
        key_set.append(key)
        session.commit()
    return key_set, key
<commit_msg>Don't print Test Corpus stats if it doesn't exist<commit_after>import random
from .models.context import Corpus
from .models.annotation import AnnotationKeySet, AnnotationKey

def split_corpus(session, corpus, train=0.8, development=0.1, test=0.1, seed=None):
    if train + development + test != 1:
        raise ValueError("Values for train + development + test must sum to 1")

    random.seed(seed)
    docs = [doc for doc in corpus.documents]
    docs.sort(key=lambda d: d.name)
    random.shuffle(docs)

    n = len(docs)
    num_train = int(train * n)
    num_development = int(development * n)
    num_test = n - (num_train + num_development)

    if num_train:
        train_corpus = Corpus(name=corpus.name + ' Training')
        for doc in docs[:num_train]:
            train_corpus.append(doc)
        session.add(train_corpus)
        print "%d Documents added to corpus %s" % (len(train_corpus), train_corpus.name)

    if num_development:
        development_corpus = Corpus(name=corpus.name + ' Development')
        for doc in docs[num_train:num_train + num_development]:
            development_corpus.append(doc)
        session.add(development_corpus)
        print "%d Documents added to corpus %s" % (len(development_corpus), development_corpus.name)

    if num_test:
        test_corpus = Corpus(name=corpus.name + ' Test')
        for doc in docs[num_train + num_development:]:
            test_corpus.append(doc)
        session.add(test_corpus)
        print "%d Documents added to corpus %s" % (len(test_corpus), test_corpus.name)

    session.commit()

def get_or_create_single_key_set(session, name):
    key_set = session.query(AnnotationKeySet).filter(AnnotationKeySet.name == name).first()
    if key_set is None:
        key_set = AnnotationKeySet(name=name)
        session.add(key_set)
        session.commit()

    if len(key_set) > 1:
        raise ValueError('AnnotationKeySet with name ' + unicode(name) + ' already exists and has more than one ' +
                         'AnnotationKey. Please specify a new name.')
    elif len(key_set) == 1:
        if key_set.keys[0].name == name:
            key = key_set.keys[0]
        else:
            raise ValueError('AnnotationKeySet named ' + unicode(name) + ' already exists and has one ' +
                             'AnnotationKey with a different name. Please specify a new name.')
    else:
        key = session.query(AnnotationKey).filter(AnnotationKey.name == name).first()
        if key is None:
            key = AnnotationKey(name=name)
            session.add(key)
            session.commit()
        key_set.append(key)
        session.commit()
    return key_set, key
<|endoftext|>


<commit_before>"""
Snuggs are s-expressions for Numpy.
"""

import functools
import itertools
import operator
import re
import sys

from pyparsing import (
    alphanums, ZeroOrMore, nums, oneOf, Word, Literal, Combine, QuotedString,
    ParseException, Forward, Group, CaselessLiteral, Optional, alphas,
    OneOrMore, ParseResults, ParseException)

import numpy

__all__ = ['eval']
__version__ = "1.3.1"

# Python 2-3 compatibility
string_types = (str,) if sys.version_info[0] >= 3 else (basestring,)

class Context(object):

    def __init__(self):
        self._data = {}

    def add(self, name, val):
        self._data[name] = val

    def get(self, name):
        return self._data[name]

    def lookup(self, index, subindex=None):
        s = list(self._data.values())[int(index)-1]
        if subindex:
            return s[int(subindex)-1]
        else:
            return s

    def clear(self):
        self._data = {}

_ctx = Context()

class ctx(object):

    def __init__(self, **kwds):
        self.kwds = kwds

    def __enter__(self):
        _ctx.clear()
        for k, v in self.kwds.items():
            _ctx.add(k, v)
        return self

    def __exit__(self, exc_type=None, exc_val=None, exc_tb=None):
        self.kwds = None
        _ctx.clear()

class ExpressionError(SyntaxError):
    """Snuggs specific syntax errors"""
    filename = "<string>"
    lineno = 1

op_map = {
    '*': operator.mul,
    '+': operator.add,
    '/': operator.div,
    '-': operator.sub,
    '<': operator.lt,
    '<=': operator.le,
    '==': operator.eq,
    '!=': operator.ne,
    '>=': operator.ge,
    '>': operator.gt,
    '&': operator.and_,
    '|': operator.or_,
    }

def asarray(*args):
    if len(args) == 1 and hasattr(args[0], '__iter__'):
        return numpy.asanyarray(list(args[0]))
    else:
        return numpy.asanyarray(list(args))

func_map = {
    'asarray': asarray,
    'read': _ctx.lookup,
    'take': lambda a, idx: numpy.take(a, idx-1, axis=0),
    }

higher_func_map = {
    'map': map if sys.version_info[0] >= 3 else itertools.imap,
    'partial': functools.partial,
    }

# Definition of the grammar.
decimal = Literal('.')
e = CaselessLiteral('E')
sign = Literal('+') | Literal('-')
number = Word(nums)
name = Word(alphas)
nil = Literal('nil').setParseAction(lambda s, l, t: [None])

def resolve_var(s, l, t):
    try:
        return _ctx.get(t[0])
    except KeyError:
        err = ExpressionError(
            "name '%s' is not defined" % t[0])
        err.text = s
        err.offset = l + 1
        raise err

var = name.setParseAction(resolve_var)

integer = Combine(
    Optional(sign) +
    number
    ).setParseAction(lambda s, l, t: int(t[0]))

real = Combine(
    integer +
    decimal + Optional(number) +
    Optional(e + integer)
    ).setParseAction(lambda s, l, t: float(t[0]))

string = QuotedString("'") | QuotedString('"')

lparen = Literal('(').suppress()
rparen = Literal(')').suppress()

op = oneOf(' '.join(op_map.keys())).setParseAction(
    lambda s, l, t: op_map[t[0]])

def resolve_func(s, l, t):
    try:
        return func_map[t[0]] if t[0] in func_map else getattr(numpy, t[0])
    except AttributeError:
        err = ExpressionError(
            "'%s' is not a function or operator" % t[0])
        err.text = s
        err.offset = l + 1
        raise err

func = Word(alphanums + '_').setParseAction(resolve_func)

higher_func = oneOf('map partial').setParseAction(
    lambda s, l, t: higher_func_map[t[0]])

func_expr = Forward()
higher_func_expr = Forward()
expr = higher_func_expr | func_expr

operand = higher_func_expr | func_expr | nil | var | real | integer | string

func_expr << Group(
    lparen +
    (higher_func_expr | op | func) +
    operand +
    ZeroOrMore(operand) +
    rparen)

higher_func_expr << Group(
    lparen +
    higher_func +
    (nil | higher_func_expr | op | func) +
    ZeroOrMore(operand) +
    rparen)

def processArg(arg):
    if not isinstance(arg, ParseResults):
        return arg
    else:
        return processList(arg)

def processList(lst):
    args = [processArg(x) for x in lst[1:]]
    func = processArg(lst[0])
    return func(*args)

def handleLine(line):
    try:
        result = expr.parseString(line)
        return processList(result[0])
    except ParseException as exc:
        text = str(exc)
        m = re.search(r'(Expected .+) \(at char (\d+)\), \(line:(\d+)', text)
        msg = m.group(1)
        if 'map|partial' in msg:
            msg = "expected a function or operator"
        err = ExpressionError(msg)
        err.text = line
        err.offset = int(m.group(2)) + 1
        raise err

def eval(source, **kwds):
    with ctx(**kwds):
        return handleLine(source)
<commit_msg>truediv, not div.<commit_after>"""
Snuggs are s-expressions for Numpy.
"""

import functools
import itertools
import operator
import re
import sys

from pyparsing import (
    alphanums, ZeroOrMore, nums, oneOf, Word, Literal, Combine, QuotedString,
    ParseException, Forward, Group, CaselessLiteral, Optional, alphas,
    OneOrMore, ParseResults, ParseException)

import numpy

__all__ = ['eval']
__version__ = "1.3.1"

# Python 2-3 compatibility
string_types = (str,) if sys.version_info[0] >= 3 else (basestring,)

class Context(object):

    def __init__(self):
        self._data = {}

    def add(self, name, val):
        self._data[name] = val

    def get(self, name):
        return self._data[name]

    def lookup(self, index, subindex=None):
        s = list(self._data.values())[int(index)-1]
        if subindex:
            return s[int(subindex)-1]
        else:
            return s

    def clear(self):
        self._data = {}

_ctx = Context()

class ctx(object):

    def __init__(self, **kwds):
        self.kwds = kwds

    def __enter__(self):
        _ctx.clear()
        for k, v in self.kwds.items():
            _ctx.add(k, v)
        return self

    def __exit__(self, exc_type=None, exc_val=None, exc_tb=None):
        self.kwds = None
        _ctx.clear()

class ExpressionError(SyntaxError):
    """Snuggs specific syntax errors"""
    filename = "<string>"
    lineno = 1

op_map = {
    '*': operator.mul,
    '+': operator.add,
    '/': operator.truediv,
    '-': operator.sub,
    '<': operator.lt,
    '<=': operator.le,
    '==': operator.eq,
    '!=': operator.ne,
    '>=': operator.ge,
    '>': operator.gt,
    '&': operator.and_,
    '|': operator.or_,
    }

def asarray(*args):
    if len(args) == 1 and hasattr(args[0], '__iter__'):
        return numpy.asanyarray(list(args[0]))
    else:
        return numpy.asanyarray(list(args))

func_map = {
    'asarray': asarray,
    'read': _ctx.lookup,
    'take': lambda a, idx: numpy.take(a, idx-1, axis=0),
    }

higher_func_map = {
    'map': map if sys.version_info[0] >= 3 else itertools.imap,
    'partial': functools.partial,
    }

# Definition of the grammar.
decimal = Literal('.')
e = CaselessLiteral('E')
sign = Literal('+') | Literal('-')
number = Word(nums)
name = Word(alphas)
nil = Literal('nil').setParseAction(lambda s, l, t: [None])

def resolve_var(s, l, t):
    try:
        return _ctx.get(t[0])
    except KeyError:
        err = ExpressionError(
            "name '%s' is not defined" % t[0])
        err.text = s
        err.offset = l + 1
        raise err

var = name.setParseAction(resolve_var)

integer = Combine(
    Optional(sign) +
    number
    ).setParseAction(lambda s, l, t: int(t[0]))

real = Combine(
    integer +
    decimal + Optional(number) +
    Optional(e + integer)
    ).setParseAction(lambda s, l, t: float(t[0]))

string = QuotedString("'") | QuotedString('"')

lparen = Literal('(').suppress()
rparen = Literal(')').suppress()

op = oneOf(' '.join(op_map.keys())).setParseAction(
    lambda s, l, t: op_map[t[0]])

def resolve_func(s, l, t):
    try:
        return func_map[t[0]] if t[0] in func_map else getattr(numpy, t[0])
    except AttributeError:
        err = ExpressionError(
            "'%s' is not a function or operator" % t[0])
        err.text = s
        err.offset = l + 1
        raise err

func = Word(alphanums + '_').setParseAction(resolve_func)

higher_func = oneOf('map partial').setParseAction(
    lambda s, l, t: higher_func_map[t[0]])

func_expr = Forward()
higher_func_expr = Forward()
expr = higher_func_expr | func_expr

operand = higher_func_expr | func_expr | nil | var | real | integer | string

func_expr << Group(
    lparen +
    (higher_func_expr | op | func) +
    operand +
    ZeroOrMore(operand) +
    rparen)

higher_func_expr << Group(
    lparen +
    higher_func +
    (nil | higher_func_expr | op | func) +
    ZeroOrMore(operand) +
    rparen)

def processArg(arg):
    if not isinstance(arg, ParseResults):
        return arg
    else:
        return processList(arg)

def processList(lst):
    args = [processArg(x) for x in lst[1:]]
    func = processArg(lst[0])
    return func(*args)

def handleLine(line):
    try:
        result = expr.parseString(line)
        return processList(result[0])
    except ParseException as exc:
        text = str(exc)
        m = re.search(r'(Expected .+) \(at char (\d+)\), \(line:(\d+)', text)
        msg = m.group(1)
        if 'map|partial' in msg:
            msg = "expected a function or operator"
        err = ExpressionError(msg)
        err.text = line
        err.offset = int(m.group(2)) + 1
        raise err

def eval(source, **kwds):
    with ctx(**kwds):
        return handleLine(source)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
'''
Create ssh executor system
'''
# Import python libs
import os
import copy
import json
import logging

# Import salt libs
import salt.client.ssh.shell
import salt.client.ssh.state
import salt.utils
import salt.utils.thin
import salt.roster
import salt.state
import salt.loader
import salt.minion
import salt.log
from salt._compat import string_types

log = logging.getLogger(__name__)

def _merge_extra_filerefs(*args):
    '''
    Takes a list of filerefs and returns a merged list
    '''
    ret = []
    for arg in args:
        if isinstance(arg, string_types):
            if arg:
                ret.extend(arg.split(','))
        elif isinstance(arg, list):
            if arg:
                ret.extend(arg)
    return ','.join(ret)

def sls(mods, saltenv='base', test=None, exclude=None, env=None, **kwargs):
    '''
    Create the seed file for a state.sls run
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    if env is not None:
        salt.utils.warn_until(
            'Boron',
            'Passing a salt environment should be done using \'saltenv\' '
            'not \'env\'. This functionality will be removed in Salt Boron.'
        )
        # Backwards compatibility
        saltenv = env

    __pillar__.update(kwargs.get('pillar', {}))
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    if isinstance(mods, str):
        mods = mods.split(',')
    high_data, errors = st_.render_highstate({saltenv: mods})
    if exclude:
        if isinstance(exclude, str):
            exclude = exclude.split(',')
        if '__exclude__' in high_data:
            high_data['__exclude__'].extend(exclude)
        else:
            high_data['__exclude__'] = exclude
    high_data, ext_errors = st_.state.reconcile_extend(high_data)
    errors += ext_errors
    errors += st_.state.verify_high(high_data)
    if errors:
        return errors
    high_data, req_in_errors = st_.state.requisite_in(high_data)
    errors += req_in_errors
    high_data = st_.state.apply_exclude(high_data)
    # Verify that the high data is structurally sound
    if errors:
        return errors
    # Compile and verify the raw chunks
    chunks = st_.state.compile_high_data(high_data)
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def low(data, **kwargs):
    '''
    Execute a single low data call
    This function is mostly intended for testing the state system

    CLI Example:

    .. code-block:: bash

        salt '*' state.low '{"state": "pkg", "fun": "installed", "name": "vi"}'
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    chunks = [data]
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    err = st_.verify_data(data)
    if err:
        return err
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format(
            __opts__['thin_dir'],
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def high(data, **kwargs):
    '''
    Execute the compound calls stored in a single set of high data
    This function is mostly intended for testing the state system

    CLI Example:

    .. code-block:: bash

        salt '*' state.high '{"vim": {"pkg": ["installed"]}}'
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    chunks = st_.state.compile_high_data(high)
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format(
            __opts__['thin_dir'],
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def highstate(test=None, **kwargs):
    '''
    Retrieve the state data from the salt master for this minion and execute it

    CLI Example:

    .. code-block:: bash

        salt '*' state.highstate

        salt '*' state.highstate exclude=sls_to_exclude
        salt '*' state.highstate exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    chunks = st_.compile_low_chunks()
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    # Check for errors
    for chunk in chunks:
        if not isinstance(chunk, dict):
            return chunks
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def top(topfn, test=None, **kwargs):
    '''
    Execute a specific top file instead of the default

    CLI Example:

    .. code-block:: bash

        salt '*' state.top reverse_top.sls
        salt '*' state.top reverse_top.sls exclude=sls_to_exclude
        salt '*' state.top reverse_top.sls exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    if salt.utils.test_mode(test=test, **kwargs):
        __opts__['test'] = True
    else:
        __opts__['test'] = __opts__.get('test', None)
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    st_.opts['state_top'] = os.path.join('salt://', topfn)
    chunks = st_.compile_low_chunks()
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def show_highstate():
    '''
    Retrieve the highstate data from the salt master and display it

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_highstate
    '''
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    return st_.compile_highstate()

def show_lowstate():
    '''
    List out the low data that will be applied to this minion

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_lowstate
    '''
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    return st_.compile_low_chunks()

def show_sls(mods, saltenv='base', test=None, env=None, **kwargs):
    '''
    Display the state data from a specific sls or list of sls files on the
    master

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_sls core,edit.vim dev
    '''
    __opts__['grains'] = __grains__
    if env is not None:
        salt.utils.warn_until(
            'Boron',
            'Passing a salt environment should be done using \'saltenv\' '
            'not \'env\'. This functionality will be removed in Salt Boron.'
        )
        # Backwards compatibility
        saltenv = env

    opts = copy.copy(__opts__)
    if salt.utils.test_mode(test=test, **kwargs):
        opts['test'] = True
    else:
        opts['test'] = __opts__.get('test', None)
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    if isinstance(mods, string_types):
        mods = mods.split(',')
    high_data, errors = st_.render_highstate({saltenv: mods})
    high_data, ext_errors = st_.state.reconcile_extend(high_data)
    errors += ext_errors
    errors += st_.state.verify_high(high_data)
    if errors:
        return errors
    high_data, req_in_errors = st_.state.requisite_in(high_data)
    errors += req_in_errors
    high_data = st_.state.apply_exclude(high_data)
    # Verify that the high data is structurally sound
    if errors:
        return errors
    return high_data

def show_top():
    '''
    Return the top data that the minion will use for a highstate

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_top
    '''
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    top_data = st_.get_top()
    errors = []
    errors += st_.verify_tops(top_data)
    if errors:
        return errors
    matches = st_.top_matches(top_data)
    return matches
<commit_msg>Update pillar from command line for state runs in salt-ssh<commit_after># -*- coding: utf-8 -*-
'''
Create ssh executor system
'''
# Import python libs
import os
import copy
import json
import logging

# Import salt libs
import salt.client.ssh.shell
import salt.client.ssh.state
import salt.utils
import salt.utils.thin
import salt.roster
import salt.state
import salt.loader
import salt.minion
import salt.log
from salt._compat import string_types

log = logging.getLogger(__name__)

def _merge_extra_filerefs(*args):
    '''
    Takes a list of filerefs and returns a merged list
    '''
    ret = []
    for arg in args:
        if isinstance(arg, string_types):
            if arg:
                ret.extend(arg.split(','))
        elif isinstance(arg, list):
            if arg:
                ret.extend(arg)
    return ','.join(ret)

def sls(mods, saltenv='base', test=None, exclude=None, env=None, **kwargs):
    '''
    Create the seed file for a state.sls run
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    if env is not None:
        salt.utils.warn_until(
            'Boron',
            'Passing a salt environment should be done using \'saltenv\' '
            'not \'env\'. This functionality will be removed in Salt Boron.'
        )
        # Backwards compatibility
        saltenv = env

    __pillar__.update(kwargs.get('pillar', {}))
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    if isinstance(mods, str):
        mods = mods.split(',')
    high_data, errors = st_.render_highstate({saltenv: mods})
    if exclude:
        if isinstance(exclude, str):
            exclude = exclude.split(',')
        if '__exclude__' in high_data:
            high_data['__exclude__'].extend(exclude)
        else:
            high_data['__exclude__'] = exclude
    high_data, ext_errors = st_.state.reconcile_extend(high_data)
    errors += ext_errors
    errors += st_.state.verify_high(high_data)
    if errors:
        return errors
    high_data, req_in_errors = st_.state.requisite_in(high_data)
    errors += req_in_errors
    high_data = st_.state.apply_exclude(high_data)
    # Verify that the high data is structurally sound
    if errors:
        return errors
    # Compile and verify the raw chunks
    chunks = st_.state.compile_high_data(high_data)
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def low(data, **kwargs):
    '''
    Execute a single low data call
    This function is mostly intended for testing the state system

    CLI Example:

    .. code-block:: bash

        salt '*' state.low '{"state": "pkg", "fun": "installed", "name": "vi"}'
    '''
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    chunks = [data]
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    err = st_.verify_data(data)
    if err:
        return err
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format(
            __opts__['thin_dir'],
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def high(data, **kwargs):
    '''
    Execute the compound calls stored in a single set of high data
    This function is mostly intended for testing the state system

    CLI Example:

    .. code-block:: bash

        salt '*' state.high '{"vim": {"pkg": ["installed"]}}'
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    chunks = st_.state.compile_high_data(high)
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format(
            __opts__['thin_dir'],
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def highstate(test=None, **kwargs):
    '''
    Retrieve the state data from the salt master for this minion and execute it

    CLI Example:

    .. code-block:: bash

        salt '*' state.highstate

        salt '*' state.highstate exclude=sls_to_exclude
        salt '*' state.highstate exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    chunks = st_.compile_low_chunks()
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    # Check for errors
    for chunk in chunks:
        if not isinstance(chunk, dict):
            return chunks
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def top(topfn, test=None, **kwargs):
    '''
    Execute a specific top file instead of the default

    CLI Example:

    .. code-block:: bash

        salt '*' state.top reverse_top.sls
        salt '*' state.top reverse_top.sls exclude=sls_to_exclude
        salt '*' state.top reverse_top.sls exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    st_kwargs = __salt__.kwargs
    __opts__['grains'] = __grains__
    if salt.utils.test_mode(test=test, **kwargs):
        __opts__['test'] = True
    else:
        __opts__['test'] = __opts__.get('test', None)
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    st_.opts['state_top'] = os.path.join('salt://', topfn)
    chunks = st_.compile_low_chunks()
    file_refs = salt.client.ssh.state.lowstate_file_refs(
            chunks,
            _merge_extra_filerefs(
                kwargs.get('extra_filerefs', ''),
                __opts__.get('extra_filerefs', '')
                )
            )
    trans_tar = salt.client.ssh.state.prep_trans_tar(
            __context__['fileclient'],
            chunks,
            file_refs,
            __pillar__)
    trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type'])
    cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format(
            __opts__['thin_dir'],
            test,
            trans_tar_sum,
            __opts__['hash_type'])
    single = salt.client.ssh.Single(
            __opts__,
            cmd,
            fsclient=__context__['fileclient'],
            **st_kwargs)
    single.shell.send(
            trans_tar,
            '{0}/salt_state.tgz'.format(__opts__['thin_dir']))
    stdout, stderr, _ = single.cmd_block()

    # Clean up our tar
    try:
        os.remove(trans_tar)
    except (OSError, IOError):
        pass

    # Read in the JSON data and return the data structure
    try:
        return json.loads(stdout, object_hook=salt.utils.decode_dict)
    except Exception as e:
        log.error("JSON Render failed for: {0}\n{1}".format(stdout, stderr))
        log.error(str(e))

    # If for some reason the json load fails, return the stdout
    return stdout

def show_highstate():
    '''
    Retrieve the highstate data from the salt master and display it

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_highstate
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    return st_.compile_highstate()

def show_lowstate():
    '''
    List out the low data that will be applied to this minion

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_lowstate
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    return st_.compile_low_chunks()

def show_sls(mods, saltenv='base', test=None, env=None, **kwargs):
    '''
    Display the state data from a specific sls or list of sls files on the
    master

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_sls core,edit.vim dev
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    __opts__['grains'] = __grains__
    if env is not None:
        salt.utils.warn_until(
            'Boron',
            'Passing a salt environment should be done using \'saltenv\' '
            'not \'env\'. This functionality will be removed in Salt Boron.'
        )
        # Backwards compatibility
        saltenv = env

    opts = copy.copy(__opts__)
    if salt.utils.test_mode(test=test, **kwargs):
        opts['test'] = True
    else:
        opts['test'] = __opts__.get('test', None)
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    if isinstance(mods, string_types):
        mods = mods.split(',')
    high_data, errors = st_.render_highstate({saltenv: mods})
    high_data, ext_errors = st_.state.reconcile_extend(high_data)
    errors += ext_errors
    errors += st_.state.verify_high(high_data)
    if errors:
        return errors
    high_data, req_in_errors = st_.state.requisite_in(high_data)
    errors += req_in_errors
    high_data = st_.state.apply_exclude(high_data)
    # Verify that the high data is structurally sound
    if errors:
        return errors
    return high_data

def show_top():
    '''
    Return the top data that the minion will use for a highstate

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_top
    '''
    __pillar__.update(kwargs.get('pillar', {}))
    __opts__['grains'] = __grains__
    st_ = salt.client.ssh.state.SSHHighState(
            __opts__,
            __pillar__,
            __salt__,
            __context__['fileclient'])
    top_data = st_.get_top()
    errors = []
    errors += st_.verify_tops(top_data)
    if errors:
        return errors
    matches = st_.top_matches(top_data)
    return matches
<|endoftext|>


<commit_before>"""
Django settings for social project.

Generated by 'django-admin startproject' using Django 1.9.4.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 't-3_3wcx1&jzpnlaa2w8r#_ilu*tmx6+(d-@33#bpvnc$4s+%a'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'forum',
    'api',
    'rest_framework',
    'compressor',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'social.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'social.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
db_from_env = dj_database_url.config(
    conn_max_age=500,
    )

DATABASES['default'].update(db_from_env)

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}

# A list of locations of additional static files
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
    'compressor.finders.CompressorFinder',
]

COMPRESS_ENABLED = False

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
<commit_msg>reading envs<commit_after>"""
Django settings for social project.

Generated by 'django-admin startproject' using Django 1.9.4.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 't-3_3wcx1&jzpnlaa2w8r#_ilu*tmx6+(d-@33#bpvnc$4s+%a'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', True)

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'forum',
    'api',
    'rest_framework',
    'compressor',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'social.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'social.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
db_from_env = dj_database_url.config(
    conn_max_age=500,
    )

DATABASES['default'].update(db_from_env)

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}

# A list of locations of additional static files
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
    'compressor.finders.CompressorFinder',
]

COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
<|endoftext|>


<commit_before>from unittest import TestCase
from net.wyun.mer.ink.sample import Sample
from scipy import misc

import numpy as np

'''
all tests in this module and test_stroke.py are base on file data/inkml/65_alfonso.inkml
'''

class TestSample(TestCase):
    def setUp(self):
        self.idd = Sample('data/inkml/65_alfonso.inkml')
        self.stroke0 = self.idd.traces[0]
        self.stroke1 = self.idd.traces[1]
        self.stroke2 = self.idd.traces[2]
        prev = self.idd.traces[1]

    def test_get_bounding_box_h1000(self):
        self.assertEqual((0, 0, 69622, 10000), (self.idd.ox, self.idd.oy, self.idd.os, self.idd.ot))

    def test_getAVGstroke_size(self):
        avgW, avgH = self.idd.getAVGstroke_size()
        targetW = 6075.5
        targetH = 4320.8999
        self.assertTrue(abs(avgW - targetW) < 1.0 / 2)
        self.assertTrue(abs(avgH - targetH) < 1.0 / 2)
        print avgW, avgH

    def test_nStrokes(self):
        ns = self.idd.nStrokes()
        self.assertEquals(10, ns)

    def test_detRefSymbol(self):
        '''
        expect (5764, 5063)
        :return:
        '''
        RX, RY = self.idd.detRefSymbol()
        print RX, RY
        self.assertEquals((5764, 5063), (RX, RY))

    def test_stroke_aspect_area(self):
        # expect 9623, 6794, 1.41639686, 65378662
        i = 0
        ancho, alto, aspectratio, area = self.idd.stroke_aspect_area(i)
        print ancho, alto, aspectratio, area
        self.assertEquals(9623, ancho)
        self.assertEquals(6794, alto)
        self.assertEquals(65378662, area)
        self.assertAlmostEqual(1.41639686, aspectratio)

    def test_median_vmedx(self):
        vmedx = [9623, 6039, 7360, 7360, 6982, 4152, 3586, 3586, 6793, 5284]
        print vmedx
        vmedx.sort()
        print vmedx
        l = len(vmedx)
        print vmedx[l / 2]
        self.assertEquals(6793, vmedx[l / 2])
        import numpy
        medx = numpy.median(vmedx)  # average of 6039 and 6793
        self.assertEquals(6416.0, medx)

    def test_stroke_distance1(self):
        self.idd.render()
        # distance between stroke 0 and stroke 2. the distance is before the normalization
        dmin = self.idd.stroke_distance(0, 2)
        self.assertEqual(7902.4310183639063, dmin)
        print dmin

    def test_stroke_distance2(self):
        img, W, H = self.idd.render()
        dmin = self.idd.stroke_distance(4, 7)
        print dmin

    def test_find_closest_pair(self):
        dmin, p1, p2 = self.idd.find_closest_pair(0, 2)
        print dmin
        self.assertAlmostEqual(7902.43115, dmin, 3)
        self.assertEqual((9433, 9056), p1)
        self.assertEqual((16037, 4716), p2)

    def test_render(self):
        '''
        testing rendering image from inkml file
        save image at temp/all.png
        :return:
        '''
        img, W, H = self.idd.render()
        print 'save image to temp/all.png: '
        misc.imsave('temp/all.png', img)
        print img[15, 9]
        print W, H
        self.assertEqual(255, img[15, 9])
        self.assertEqual((1792, 266), (W, H))

    def test_linea(self):
        W, H = 1792, 266
        img = np.ones((H, W), dtype=int) * 255
        self.idd.pix_stk = np.ones((H, W), dtype=int) * (-1)
        pa = (19.4867649, 149.881516)
        pb = (5, 145.043594)

        self.idd.linea(img, pa, pb, 0)
        print np.where(img == 0)
        print img

        self.assertEqual(0, img[145, 5])
        self.assertEqual(0, img[150, 20])

    def test_compute_strokes_distances(self):
        RX = 5764
        RY = 5063
        img, W, H = self.idd.render()
        stk_dis = self.idd.compute_strokes_distances(RX, RY)

        print '(x, y): (1169, 119): ', img[119][1169], self.idd.pix_stk[119][1169]
        self.assertEqual(0, img[119][1169])
        self.assertEqual(5, self.idd.pix_stk[119][1169])
        print stk_dis

    def test_get_close_strokes(self):
        self.idd.detRefSymbol()
        self.idd.render()
        self.idd.compute_strokes_distances(self.idd.RX, self.idd.RY)
        L = []
        self.idd.get_close_strokes(7, L, 0.69474973)
        self.assertEqual((6, 5), (L[0], L[1]))
        print L

        L = []
        self.idd.get_close_strokes(6, L, 0.69474973)
        self.assertEqual(5, L[0])

        L = []
        self.idd.get_close_strokes(8, L, 0.69474973)
        self.assertEqual((7, 6), (L[0], L[1]))
<commit_msg>add inkml file loading test.<commit_after>from unittest import TestCase
from net.wyun.mer.ink.sample import Sample
from scipy import misc

import numpy as np

'''
all tests in this module and test_stroke.py are base on file data/inkml/65_alfonso.inkml
'''

class TestSample(TestCase):
    def setUp(self):
        self.idd = Sample('data/inkml/65_alfonso.inkml')
        self.stroke0 = self.idd.traces[0]
        self.stroke1 = self.idd.traces[1]
        self.stroke2 = self.idd.traces[2]
        prev = self.idd.traces[1]

    def test_inkml_loading(self):
        print 'loading inkml'
        print 'latex: ', self.idd.latex

    def test_get_bounding_box_h1000(self):
        self.assertEqual((0, 0, 69622, 10000), (self.idd.ox, self.idd.oy, self.idd.os, self.idd.ot))

    def test_getAVGstroke_size(self):
        avgW, avgH = self.idd.getAVGstroke_size()
        targetW = 6075.5
        targetH = 4320.8999
        self.assertTrue(abs(avgW - targetW) < 1.0 / 2)
        self.assertTrue(abs(avgH - targetH) < 1.0 / 2)
        print avgW, avgH

    def test_nStrokes(self):
        ns = self.idd.nStrokes()
        self.assertEquals(10, ns)

    def test_detRefSymbol(self):
        '''
        expect (5764, 5063)
        :return:
        '''
        RX, RY = self.idd.detRefSymbol()
        print RX, RY
        self.assertEquals((5764, 5063), (RX, RY))

    def test_stroke_aspect_area(self):
        # expect 9623, 6794, 1.41639686, 65378662
        i = 0
        ancho, alto, aspectratio, area = self.idd.stroke_aspect_area(i)
        print ancho, alto, aspectratio, area
        self.assertEquals(9623, ancho)
        self.assertEquals(6794, alto)
        self.assertEquals(65378662, area)
        self.assertAlmostEqual(1.41639686, aspectratio)

    def test_median_vmedx(self):
        vmedx = [9623, 6039, 7360, 7360, 6982, 4152, 3586, 3586, 6793, 5284]
        print vmedx
        vmedx.sort()
        print vmedx
        l = len(vmedx)
        print vmedx[l / 2]
        self.assertEquals(6793, vmedx[l / 2])
        import numpy
        medx = numpy.median(vmedx)  # average of 6039 and 6793
        self.assertEquals(6416.0, medx)

    def test_stroke_distance1(self):
        self.idd.render()
        # distance between stroke 0 and stroke 2. the distance is before the normalization
        dmin = self.idd.stroke_distance(0, 2)
        self.assertEqual(7902.4310183639063, dmin)
        print dmin

    def test_stroke_distance2(self):
        img, W, H = self.idd.render()
        dmin = self.idd.stroke_distance(4, 7)
        print dmin

    def test_find_closest_pair(self):
        dmin, p1, p2 = self.idd.find_closest_pair(0, 2)
        print dmin
        self.assertAlmostEqual(7902.43115, dmin, 3)
        self.assertEqual((9433, 9056), p1)
        self.assertEqual((16037, 4716), p2)

    def test_render(self):
        '''
        testing rendering image from inkml file
        save image at temp/all.png
        :return:
        '''
        img, W, H = self.idd.render()
        print 'save image to temp/all.png: '
        misc.imsave('temp/all.png', img)
        print img[15, 9]
        print W, H
        self.assertEqual(255, img[15, 9])
        self.assertEqual((1792, 266), (W, H))

    def test_linea(self):
        W, H = 1792, 266
        img = np.ones((H, W), dtype=int) * 255
        self.idd.pix_stk = np.ones((H, W), dtype=int) * (-1)
        pa = (19.4867649, 149.881516)
        pb = (5, 145.043594)

        self.idd.linea(img, pa, pb, 0)
        print np.where(img == 0)
        print img

        self.assertEqual(0, img[145, 5])
        self.assertEqual(0, img[150, 20])

    def test_compute_strokes_distances(self):
        RX = 5764
        RY = 5063
        img, W, H = self.idd.render()
        stk_dis = self.idd.compute_strokes_distances(RX, RY)

        print '(x, y): (1169, 119): ', img[119][1169], self.idd.pix_stk[119][1169]
        self.assertEqual(0, img[119][1169])
        self.assertEqual(5, self.idd.pix_stk[119][1169])
        print stk_dis

    def test_get_close_strokes(self):
        self.idd.detRefSymbol()
        self.idd.render()
        self.idd.compute_strokes_distances(self.idd.RX, self.idd.RY)
        L = []
        self.idd.get_close_strokes(7, L, 0.69474973)
        self.assertEqual((6, 5), (L[0], L[1]))
        print L

        L = []
        self.idd.get_close_strokes(6, L, 0.69474973)
        self.assertEqual(5, L[0])

        L = []
        self.idd.get_close_strokes(8, L, 0.69474973)
        self.assertEqual((7, 6), (L[0], L[1]))
<|endoftext|>


<commit_before>#!/usr/bin/env python
#
# Copyright 2017 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import structlog
from netconf.nc_rpc.rpc import Rpc
import netconf.nc_common.error as ncerror
from netconf.constants import Constants as C

log = structlog.get_logger()

class GetConfig(Rpc):

	def __init__(self, request, request_xml, grpc_client, session, capabilities):
		super(GetConfig, self).__init__(request, request_xml, grpc_client,
										session, capabilities)
		self._validate_parameters()

	def execute(self):
		log.info('get-config-request', session=self.session.session_id)
		if self.rpc_response.is_error:
			return self.rpc_response

	def _validate_parameters(self):
		log.info('validate-parameters', session=self.session.session_id)

		self.params = self.rpc_method.getchildren()
		paramslen = len(self.params)
		# Verify that the source parameter is present
		if paramslen > 2:
			# TODO: need to specify all elements not known
			self.rpc_response.is_error = True
			self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
			return

		self.source_param = self.rpc_method.find(C.NC_SOURCE, namespaces=C.NS_MAP)
		# if self.source_param is None:
		# 	self.rpc_response.is_error = True
		# 	self.rpc_response.node = ncerror.MissingElement(
		# 		self.rpc_request, elm(C.NC_SOURCE))
		# 	return

		self.filter_param = None
		if paramslen == 2:
			self.filter_param = self.rpc_method.find(C.NC_FILTER,
												  namespaces=C.NS_MAP)
			if self.filter_param is None:
				unknown_elm = self.params[0] if self.params[0] != \
												self.source_param else \
												self.params[1]
				self.rpc_response.is_error = True
				self.rpc_response.node = ncerror.UnknownElement(
					self.rpc_request, unknown_elm)

		self.params = [self.source_param, self.filter_param]
<commit_msg>reformatting file to remove tabs<commit_after>#!/usr/bin/env python
#
# Copyright 2017 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import structlog
from netconf.nc_rpc.rpc import Rpc
import netconf.nc_common.error as ncerror
from netconf.constants import Constants as C

log = structlog.get_logger()

class GetConfig(Rpc):
    def __init__(self, request, request_xml, grpc_client, session, capabilities):
        super(GetConfig, self).__init__(request, request_xml, grpc_client, session)
        self._validate_parameters()

    def execute(self):
        log.info('get-config-request', session=self.session.session_id)
        if self.rpc_response.is_error:
            return self.rpc_response

    def _validate_parameters(self):
        log.info('validate-parameters', session=self.session.session_id)

        self.params = self.rpc_method.getchildren()
        paramslen = len(self.params)
        # Verify that the source parameter is present
        if paramslen > 2:
            # TODO: need to specify all elements not known
            self.rpc_response.is_error = True
            self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
            return

        self.source_param = self.rpc_method.find(C.NC_SOURCE, namespaces=C.NS_MAP)
        # if self.source_param is None:
        # 	self.rpc_response.is_error = True
        # 	self.rpc_response.node = ncerror.MissingElement(
        # 		self.rpc_request, elm(C.NC_SOURCE))
        # 	return

        self.filter_param = None
        if paramslen == 2:
            self.filter_param = self.rpc_method.find(C.NC_FILTER,
                                                     namespaces=C.NS_MAP)
            if self.filter_param is None:
                unknown_elm = self.params[0] if self.params[0] != \
                                                self.source_param else \
                    self.params[1]
                self.rpc_response.is_error = True
                self.rpc_response.node = ncerror.UnknownElement(
                    self.rpc_request, unknown_elm)

        self.params = [self.source_param, self.filter_param]
<|endoftext|>


<commit_before>'''Sample module showing the creation of blaze arrays'''
from __future__ import print_function

import blaze

def print_section(a_string, spacing=2, underline='='):
    print ('%s%s\n%s' % ('\n'*spacing,
                         a_string,
                         underline*len(a_string)))

print_section('building basic arrays')
# It is possible to build arrays from python lists
a = blaze.array([ 2, 3, 4 ])

# Arrays can be printed
print (a)

# The array will have a datashape. A datashape is a combination of the
# shape and dtype concept found in numpy. Note that when creating from
# a Python iterable, a datashape will be inferred.
print (a.dshape)

b = blaze.array([1.2, 3.5, 5.1])
print (b)
print (b.dshape)

# Arrays can be bi-dimensional
print_section('going 2d', spacing=1, underline='-')
c = blaze.array([ [1, 2], [3, 4] ])
print (c)
print (c.dshape)

# or as many dimensions as you like
print_section('going 3d', spacing=1, underline='-')
d = blaze.array([ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ])
print (d)
print (d.dshape)

# --------------------------------------------------------------------

print_section ('building compressed in-memory arrays')

# A compressed array (backed by BLZ):
blz = blaze.array([1,2,3], caps={'compress': True})
print (blz)

# --------------------------------------------------------------------

print_section('Explicit types in construction')
# It is possible to force a type in a given array. This allows a
# broader selection of types on construction.
e =  blaze.array([ 1, 2, 3], dshape='3, float32')
print (e)

# Note that the dimensions in the datashape when creating from a
# collection can be omitted. If that's the case, the dimensions will
# be inferred. The following is thus equivalent:

f = blaze.array([ 1, 2, 3], dshape='float32')
print (f)

# --------------------------------------------------------------------

print_section('Alternative  constructors')

# Arrays can be created to be all zeros:
g = blaze.zeros('10, 10, int32')
print (g)

# All ones
h = blaze.ones('10, 10, float64')
print (h)

# --------------------------------------------------------------------

print_section('Indexing')

print ('starting with a 4d array')
array4d = blaze.ones('10,10,10,10, float32')
print (array4d)

print ('index once')
print (array4d[3])
print ('index twice')
print (array4d[3,2])
print ('index thrice')
print (array4d[3,2,4])
print ('index 4 times')
print (array4d[3,2,4,1])
<commit_msg>improvement on indexing sample output<commit_after>'''Sample module showing the creation of blaze arrays'''
from __future__ import print_function

import blaze

def print_section(a_string, spacing=2, underline='='):
    print ('%s%s\n%s' % ('\n'*spacing,
                         a_string,
                         underline*len(a_string)))

print_section('building basic arrays')
# It is possible to build arrays from python lists
a = blaze.array([ 2, 3, 4 ])

# Arrays can be printed
print (a)

# The array will have a datashape. A datashape is a combination of the
# shape and dtype concept found in numpy. Note that when creating from
# a Python iterable, a datashape will be inferred.
print (a.dshape)

b = blaze.array([1.2, 3.5, 5.1])
print (b)
print (b.dshape)

# Arrays can be bi-dimensional
print_section('going 2d', spacing=1, underline='-')
c = blaze.array([ [1, 2], [3, 4] ])
print (c)
print (c.dshape)

# or as many dimensions as you like
print_section('going 3d', spacing=1, underline='-')
d = blaze.array([ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ])
print (d)
print (d.dshape)

# --------------------------------------------------------------------

print_section ('building compressed in-memory arrays')

# A compressed array (backed by BLZ):
blz = blaze.array([1,2,3], caps={'compress': True})
print (blz)

# --------------------------------------------------------------------

print_section('Explicit types in construction')
# It is possible to force a type in a given array. This allows a
# broader selection of types on construction.
e =  blaze.array([ 1, 2, 3], dshape='3, float32')
print (e)

# Note that the dimensions in the datashape when creating from a
# collection can be omitted. If that's the case, the dimensions will
# be inferred. The following is thus equivalent:

f = blaze.array([ 1, 2, 3], dshape='float32')
print (f)

# --------------------------------------------------------------------

print_section('Alternative  constructors')

# Arrays can be created to be all zeros:
g = blaze.zeros('10, 10, int32')
print (g)

# All ones
h = blaze.ones('10, 10, float64')
print (h)

# --------------------------------------------------------------------

print_section('Indexing')

print ('starting with a 4d array')
array4d = blaze.ones('10,10,10,10, float32')

def describe_array(label, array):
    print (label)
    print ('dshape: ', array.dshape)
    print (array)

describe_array('base', array4d)
describe_array('index once', array4d[3])
describe_array('index twice', array4d[3,2])
describe_array('index thrice', array4d[3,2,4])
describe_array('index four times', array4d[3,2,4,1])

del describe_array
<|endoftext|>


<commit_before>import windows
import windows.generated_def as gdef

manager = windows.system.device_manager
print(manager)
for devcls in manager.classes:
    print("- {0!r}".format(devcls))
    for device in devcls.devices:
        print(u"    - [{dev.name}] <{dev.description}> ({dev.device_object_name})".format(dev=device))
        devconf = device.get_first_logical_configuration(gdef.ALLOC_LOG_CONF)
        if devconf:
            # import pdb;pdb.set_trace()
            # print(devconf)
            print("      <config:>")
            for resource in devconf.resources:
                print("        - {0}".format(resource))

        # print(dev.description)
        # print(dev.device_object_name)
        # # x = dev.get_first_logical_configuration(gdef.ALLOC_LOG_CONF)
        # x = dev.get_first_logical_configuration(gdef.BOOT_LOG_CONF)
        # if x:
        #     print(x)
        #     for res in x.resources:
        #         print(res)
        #         # print(repr(res.rawdata))
        #         print(res.header)
        #         assert not res.data
        #         # import pdb;pdb.set_trace()
        #     import pdb;pdb.set_trace()
        #     print("BYE")

<commit_msg>Added some comment about unsure high-level API choice/possibility to discuss<commit_after>import windows
import windows.generated_def as gdef

manager = windows.system.device_manager
print(manager)
for devcls in manager.classes:
    print("- {0!r}".format(devcls))
    for device in devcls.devices:
        print(u"    - [{dev.name}] <{dev.description}> ({dev.device_object_name})".format(dev=device))
        # Je sais pas trop quoi faire comme API sur ce truc
        # Apparement on peut avoir plusieurs logical_configuration par type
        #   - Je sais meme pas si c'est possible en vrai meme si <CM_Get_Next_Log_Conf> existe
        # Idées:
        #   * get_allocated_conf + get_boot_conf & co
        #   * logical_configurations() qui retourne la liste complete
        #   * Je sais pas trop
        #
        devconf = device.get_first_logical_configuration(gdef.ALLOC_LOG_CONF)
        if devconf:
            # import pdb;pdb.set_trace()
            # print(devconf)
            print("      <config:>")
            for resource in devconf.resources:
                print("        - {0}".format(resource))

        # print(dev.description)
        # print(dev.device_object_name)
        # # x = dev.get_first_logical_configuration(gdef.ALLOC_LOG_CONF)
        # x = dev.get_first_logical_configuration(gdef.BOOT_LOG_CONF)
        # if x:
        #     print(x)
        #     for res in x.resources:
        #         print(res)
        #         # print(repr(res.rawdata))
        #         print(res.header)
        #         assert not res.data
        #         # import pdb;pdb.set_trace()
        #     import pdb;pdb.set_trace()
        #     print("BYE")

<|endoftext|>