Пример #1
0
    def load(self):
        self.config = {}
        for fname in [os.path.abspath(self.configfilename), os.path.join('/etc/myownci', self.configfilename)]:
          if os.path.isfile(fname):
            self.config = simpleyaml.load(open(fname).read())
            break

        self.config['var'] = {}
        try:
            self.config['var'].update(simpleyaml.load(open(os.path.join('/var/tmp', self.configfilename), 'r')))
        except IOError:
            pass
Пример #2
0
def test_unicode_input(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    value = ' '.join(data.split())
    output = yaml.load(_unicode_open(StringIO.StringIO(data.encode('utf-8')), 'utf-8'))
    assert output == value, (output, value)
    for input in [data, data.encode('utf-8'),
                    codecs.BOM_UTF8+data.encode('utf-8'),
                    codecs.BOM_UTF16_BE+data.encode('utf-16-be'),
                    codecs.BOM_UTF16_LE+data.encode('utf-16-le')]:
        if verbose:
            print "INPUT:", repr(input[:10]), "..."
        output = yaml.load(input)
        assert output == value, (output, value)
        output = yaml.load(StringIO.StringIO(input))
        assert output == value, (output, value)
def main(yamlfilename, csvfilename):
    vectors = yaml.load(open(yamlfilename))
    symbol_class = [[c for c in r] for r in csv.reader(open(csvfilename))]
    rows = len(vectors)
    cols = len(vectors[0])

    # sort the data by class
    by_class = dict()
    for i in range(rows):
        for j in range(cols):
            vec = vectors[i][j]
            sym = symbol_class[i][j]
            if sym in by_class:
                by_class[sym].append(vec)
            else:
                by_class[sym] = [vec]

    # plot the data as an average over the class
    for sym, vecs in by_class.items():
        for key in vecs[0].keys():
            pad = 2
            key_matrix = np.array([v[key][pad:-pad] for v in vecs])
            y = key_matrix.mean(0)
            x = range(pad, len(key_matrix[0]) + pad)
            err = key_matrix.std(0)
            plt.errorbar(x, y, yerr=err)
            name = "output-%s-%s--%d.png" % (sym, key, len(vecs))
            plt.title(name)
            plt.savefig(name)
            plt.close()
Пример #4
0
def test_representer_types(code_filename, verbose=False):
    test_constructor._make_objects()
    for allow_unicode in [False, True]:
        for encoding in ['utf-8', 'utf-16-be', 'utf-16-le']:
            native1 = test_constructor._load_code(open(code_filename, 'rb').read())
            native2 = None
            try:
                output = yaml.dump(native1, Dumper=test_constructor.MyDumper,
                            allow_unicode=allow_unicode, encoding=encoding)
                native2 = yaml.load(output, Loader=test_constructor.MyLoader)
                try:
                    if native1 == native2:
                        continue
                except TypeError:
                    pass
                value1 = test_constructor._serialize_value(native1)
                value2 = test_constructor._serialize_value(native2)
                if verbose:
                    print "SERIALIZED NATIVE1:"
                    print value1
                    print "SERIALIZED NATIVE2:"
                    print value2
                assert value1 == value2, (native1, native2)
            finally:
                if verbose:
                    print "NATIVE1:"
                    pprint.pprint(native1)
                    print "NATIVE2:"
                    pprint.pprint(native2)
                    print "OUTPUT:"
                    print output
Пример #5
0
def get_config():
    """
    Load the config file, either from the user data
    directory, or if that is not available, the installed
    copy.
    :returns: config
    :rtype: dict
    """

    # First check whether the user has a custom home directory.
    script_dir = os.path.dirname(os.path.realpath(__file__))
    home_dir_locfile = os.path.join(script_dir, "user_home.txt")

    config_path = None

    if os.path.exists(home_dir_locfile):
        with open(home_dir_locfile, "rb") as f:
            home_dir_path = f.read()
            config_path = os.path.join(home_dir_path, "config.yml")

    # If it doesn't exist, use the installed copy
    if config_path is None or not os.path.exists(config_path):
        config_path = os.path.join(
            os.path.split(os.path.abspath(__file__))[0],
            "config.yml"
        )
    # Load & return config
    with open(config_path) as cfile:
        return yaml.load(cfile)
Пример #6
0
def get_config():
    """
    Load the config file, either from the user data
    directory, or if that is not available, the installed
    copy.
    :returns: config
    :rtype: dict
    """

    # First check whether the user has a custom home directory.
    script_dir = os.path.dirname(os.path.realpath(__file__))
    home_dir_locfile = os.path.join(script_dir, "user_home.txt")

    config_path = None

    if os.path.exists(home_dir_locfile):
        with open(home_dir_locfile, "rb") as f:
            home_dir_path = f.read()
            config_path = os.path.join(home_dir_path, "config.yml")

    # If it doesn't exist, use the installed copy
    if config_path is None or not os.path.exists(config_path):
        config_path = os.path.join(
            os.path.split(os.path.abspath(__file__))[0], "config.yml")
    # Load & return config
    with open(config_path) as cfile:
        return yaml.load(cfile)
Пример #7
0
def test_emitter_error(error_filename, verbose=False):
    events = list(yaml.load(open(error_filename, "rb"), Loader=test_emitter.EventsLoader))
    try:
        yaml.emit(events)
    except yaml.YAMLError, exc:
        if verbose:
            print "%s:" % exc.__class__.__name__, exc
Пример #8
0
def test_emitter_events(events_filename, verbose=False):
    events = list(yaml.load(open(events_filename, 'rb'), Loader=EventsLoader))
    output = yaml.emit(events)
    if verbose:
        print "OUTPUT:"
        print output
    new_events = list(yaml.parse(output))
    _compare_events(events, new_events)
Пример #9
0
def test_unicode_input_errors(unicode_filename, verbose=False):
    data = open(unicode_filename, 'rb').read().decode('utf-8')
    for input in [data.encode('latin1', 'ignore'),
                    data.encode('utf-16-be'), data.encode('utf-16-le'),
                    codecs.BOM_UTF8+data.encode('utf-16-be'),
                    codecs.BOM_UTF16_BE+data.encode('utf-16-le'),
                    codecs.BOM_UTF16_LE+data.encode('utf-8')+'!']:
        try:
            yaml.load(input)
        except yaml.YAMLError, exc:
            if verbose:
                print exc
        else:
            raise AssertionError("expected an exception")
        try:
            yaml.load(StringIO.StringIO(input))
        except yaml.YAMLError, exc:
            if verbose:
                print exc
Пример #10
0
 def __init__(self):
     super(sjcam, self).__init__()
     self.commands = []
     print "parsing yaml"
     with open('sjcam.yaml', 'r') as yamlFile:
         commands = yaml.load(yamlFile)
         print commands
     for id, values in commands['commands'].items():
         self.commands.append(
             sjcamCommand(id=id,
                          description=values.get('description'),
                          parameters=values.get('parameter', []),
                          readOnly=values.get('readOnly', False),
                          format=values.get('format', '')))
Пример #11
0
def test_recursive(recursive_filename, verbose=False):
    exec open(recursive_filename, "rb").read()
    value1 = value
    output1 = None
    value2 = None
    output2 = None
    try:
        output1 = yaml.dump(value1)
        value2 = yaml.load(output1)
        output2 = yaml.dump(value2)
        assert output1 == output2, (output1, output2)
    finally:
        if verbose:
            # print "VALUE1:", value1
            # print "VALUE2:", value2
            print "OUTPUT1:"
            print output1
            print "OUTPUT2:"
            print output2
Пример #12
0
def main(file):
    stream = open(file, "r")
    docs = yaml.load(stream)
    dirname = os.path.dirname(sys.argv[0])
    for doc in docs:
        id = doc['id']

        newfile = open(dirname + "/../_papers/" + id + ".html", "w")
        #for item in doc.
        doc['layout'] = 'singlepaper'
        doc['picture'] = 'paco2'

        string = yaml.dump(doc,
                           explicit_start=True,
                           default_flow_style=False,
                           allow_unicode=True)
        newfile.write(string)
        newfile.write("---\n\n")
        newfile.write("{% include singlepaper.html paper=page %}")

        newfile.close()
Пример #13
0
def get_config():
    """
    Load the config file, either from the user data
    directory, or if that is not available, the installed
    copy.
    :returns: config
    :rtype: dict
    """
    # First try to load the config file in the
    # user data directory
    config_path = os.path.join(
            appdirs.user_data_dir("superplot", ""),
            "config.yml"
    )
    # If it doesn't exist, use the installed copy
    if not os.path.exists(config_path):
        config_path = os.path.join(
            os.path.split(os.path.abspath(__file__))[0],
            "config.yml"
        )
    # Load & return config
    with open(config_path) as cfile:
        return yaml.load(cfile)
Пример #14
0
def canonical_load(stream):
    return yaml.load(stream, Loader=CanonicalLoader)
import Image, ImageDraw
import simpleyaml as yaml
import argparse
from black_and_white import as_black_and_white

def bb(x, y, w, h):
    return (x, y, x + w, y + h)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('mean_file_yml')
    parser.add_argument('output')
    parser.add_argument('-split', type=int)
    args = parser.parse_args()
    meta_data = yaml.load(open(args.mean_file_yml))
    rows = 0
    max_w = 0
    max_h = 0
    for name, data in meta_data.items():
        rows += 1
        data['image'] = Image.open(data['path'])
        data['template'] = Image.open(data['template_path'])
        if args.split:
            data['image'] = as_black_and_white(data['image'], args.split, contrast=True)
            data['template'] = as_black_and_white(data['template'], args.split, contrast=True)
        max_w = max(max_w, data['template'].size[0])
        max_h = max(max_h, data['template'].size[1])
        max_w = max(max_w, data['image'].size[0])
        max_h = max(max_h, data['image'].size[1])
Пример #16
0
#!/usr/bin/env python2
import sys
sys.path.append("/vagrant/includes.zip")
import graphit, shlex, urlparse, simpleyaml

# MAIN
iid = "0838e286-fab7-465f-9405-b308dc2561ba"

with open("/opt/autopilot/conf/aae.yaml") as aae_yaml:
    try:
        config = simpleyaml.load([
            entry['Value']
            for entry in simpleyaml.load(aae_yaml)['SystemGlobalVariables']
            if entry['Name'] == "KI_Deployment"
        ][0])
    except IndexError:
        print >> sys.stderr, "Config not found in aae.yaml"
        sys.exit(5)

with graphit.Tunnel(
        config['SourceEnvironment']['EngineHost'],
        usr=config['SourceEnvironment']['SSHUser'],
        opts=shlex.split(config['SourceEnvironment']['SSHOptions']),
        fwd={
            'graphit': urlparse.urlparse(
                config['SourceEnvironment']['GraphitURL']).netloc,
            'wso2':
            urlparse.urlparse(config['SourceEnvironment']['WSO2ISURL']).netloc
        }) as tun:
    try:
        source_graph = graphit.GraphAPI(
    proximity_counts = get_proximity_counts(map_list, edge_class, directions, proximity_stats=save_prox)
    proximity_prob = calculate_probabilities(proximity_counts, min_n_size, edge_class)
    if class_prob_csv:
        classprobs = classify_byprob(map_list, proximity_prob, directions, edge_class)
        with open(class_prob_csv, 'w') as f:
            w = csv.writer(f)
            w.writerow(["i", "j"] + proximity_prob.keys() + ["intended"])
            for r in classprobs:
                w.writerow(r)
    prob_headers = csv_probs(proximity_prob, map_classifcation_type)
    header_names = ["i", "j", map_classifcation_type] + get_header_from_prox_prob(prob_headers)
    writer.writerow(header_names)
    for  i in range(0, len(map_list)):
        for j in range(0,len(map_list[i])):
            cell_class = get_class(j, i, map_list)
            writer.writerow([i, j, cell_class]+prob_headers[cell_class].values())


if __name__ == "__main__":
    args = parse_args()
    if args.output:
        out_fd = open(args.output, "w")
    else:
        out_fd = sys.stdout
    prox=dict()
    if args.load:
        prox=yaml.load(open(args.load))
    main(args.map_csv, out_fd, args.edge_class, args.min_n_size, args.map_classification_type, save_prox=prox, class_prob_csv=args.probs)
    if args.save:
        open(args.save, 'w').write(yaml.dump(prox))
Пример #18
0
def configure():
    # Read configuration
    file = open("config/parameters.yml", "r")
    config = yaml.load(file)
    file.close()
    return config
        raise ValueError('Not images given to blend')
    if count == 1:
        return imgs[0].convert('L')
    else:
        return Image.blend(blend_images(imgs[:count/2]), blend_images(imgs[count/2:]), .5)


def bounding_box(x, y, w, h, inset=7):
    return (x + inset, y + inset, x + w - 2 * inset, y + h - 2 * inset)


if __name__ == "__main__":
    args = parse_args()

    if args.gold:
        meta_data = yaml.load(open(args.gold))
        for name, data in meta_data.items():
            meta_data[name]['image'] = Image.open(data['path'])
            meta_data[name]['template'] = Image.open(data['template_path'])
    else:
        meta_data = dict()

    grid = Image.open(args.map)
    classes = [r for r in csv.reader(open(args.intended))]
    rows = len(classes)
    cols = len(classes[0])
    width, height = dims.celldims(grid.size, rows, cols)

    # collect all cells by class name
    img_by_class = dict()
    for j in range(rows):
def gold_classify(gold_images, cell_image, align=True):
    return [(compare_images(gold, cell_image, align=False), className) for className, gold in gold_images.items()]


def bounding_box(x, y, w, h, inset=7):
    return (x + inset, y + inset, x + w - 2 * inset, y + h - 2 * inset)


if __name__ == "__main__":
    args = parse_args()
    grid = Image.open(args.image)
    cell_w, cell_h = dims.celldims(grid.size, args.rows, args.cols)
    answer = []

    gold = yaml.load(open(args.gold))
    for name, mean_img in gold.items():
        if 'path' in mean_img:
            gold[name] = Image.open(mean_img['path'])
        else:
            gold[name] = Image.open(mean_img)
        if args.split:
            gold[name] = as_black_and_white(gold[name], args.split, contrast=True)

    class_errs = [[gold_classify(gold,
                grid.crop(bounding_box(
                    j * cell_w, i * cell_h, cell_w, cell_h)))
                    for j in range(args.cols)] for i in range(args.rows)]

    output = [[min(class_errs[i][j])[1] for j in range(args.cols)] for i in range(args.rows)]
Пример #21
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('tileset', help="directory with images and yaml file")
    parser.add_argument('csv_map', help="csv file to tileize")
    parser.add_argument('output', help="where to output image")
    return parser.parse_args()


def boundingbox(x, y, w, h):
    return (x, y, x + w, y + h)


if __name__ == "__main__":
    args = parse_args()
    tile_set = yaml.load(open(os.path.join(args.tileset, 'tiles.yml')))
    for name, data in tile_set.items():
        if name != 'tiles':
            tile_set[name]['image'] = Image.open(
                os.path.join(args.tileset, data['image']))
    classes = [r for r in csv.reader(open(args.csv_map))]
    
    width = tile_set['tiles']['width']
    height = tile_set['tiles']['height']
    output_size = (width * len(classes[0]), height * len(classes))
    output = Image.new('RGB', output_size, "white")

    old = [list(x) for x in classes]
    for j, row in enumerate(classes):
        for i, cell in enumerate(row):
            if cell and cell in tile_set:
Пример #22
0
import simpleyaml as yaml

data = yaml.load(file("data.yaml","r"))
customers = data['customers']
vipIds = [c['id'] for c in customers if c['vip'] == True]
Пример #23
0
def configure():
    # Read configuration
    file = open("config/parameters.yml", "r")
    config = yaml.load(file)
    file.close()
    return config
Пример #24
0
def test_loader_error_single(error_filename, verbose=False):
    try:
        yaml.load(open(error_filename, "rb").read())
    except yaml.YAMLError, exc:
        if verbose:
            print "%s:" % exc.__class__.__name__, exc
Пример #25
0
import os
import re
import shutil
from fabric.api import local

try:
    # Py2
    import simpleyaml as yaml
    prj_name = '{name}.jms'.format(name=str(raw_input('Enter masher name: ')))
except:
    # Py3
    import yaml
    prj_name = '{name}.jms'.format(name=str(input('Enter masher name: ')))

d_opt = yaml.load(open('options.yaml'))
cur_dir = os.getcwd()
src_dir = d_opt['gen']['src_dir'] if d_opt['gen']['src_dir'].find(
    ':'
) > -1 else os.getcwd() + '\\' + d_opt['gen']['src_dir'].rstrip('\\') + '\\'
jcl_dir = d_opt['gen']['jcl_dir'] if d_opt['gen']['jcl_dir'].find(
    ':'
) > -1 else os.getcwd() + '\\' + d_opt['gen']['jcl_dir'].rstrip('\\') + '\\'
out_dir = d_opt['gen']['out_dir'] if d_opt['gen']['out_dir'].find(
    ':'
) > -1 else os.getcwd() + '\\' + d_opt['gen']['out_dir'].rstrip('\\') + '\\'

############ decorators ###############


def exe_jcl(f):
Пример #26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

VERSION = (1, 4, 0)

import sys

from twisted.internet import reactor
from twisted.python import log

import simpleyaml as yaml

import botfactory

log.startLogging(sys.stderr)

if len(sys.argv) > 1:
    config = yaml.load(open(sys.argv[1]))
else:
    log.msg('no config file specified')

config['version'] = VERSION

f = botfactory.BotFactory(config)

# connect factory to this host and port
reactor.connectTCP(config['server'], config['port'], f)

# run bot
reactor.run()