예제 #1
0
    def load(cls,
             stream,
             constructors=None,
             multi_constructors=None,
             implicit_resolvers=None):
        loader = Loader(stream)

        cs = dict(cls._constructors)
        if constructors:
            cs.update(constructors)

        ir = dict(cls._implicit_resolvers)
        if implicit_resolvers:
            ir.update(implicit_resolvers)

        mcs = dict(cls._multi_constructors)
        if multi_constructors:
            mcs.update(multi_constructors)

        if cs:
            for name, constructor in cs.items():
                loader.add_constructor(name, constructor)

        if mcs:
            for name, constructor in mcs.items():
                loader.add_multi_constructor(name, constructor)

        if ir:
            for name, pattern in ir.items():
                loader.add_implicit_resolver(name, pattern, None)

        try:
            return loader.get_single_data()
        finally:
            loader.dispose()
예제 #2
0
def load(stream, constructors=None):
    loader = Loader(stream)
    constructors = constructors or {}

    if not "timedelta" in constructors:
        loader.add_constructor("!timedelta", _timedelta_contructor)
    if not "re" in constructors:
        loader.add_constructor("!re", _re_constructor)
    if not "ref" in constructors:
        loader.add_constructor("!ref", _ref_constructor)
    if not "obj" in constructors:
        loader.add_constructor("!obj", _obj_constructor)

    if constructors:
        for name, constructor in constructors.items():
            loader.add_constructor("!" + name, constructor)

    try:
        return loader.get_single_data()
    finally:
        loader.dispose()
예제 #3
0
    def _load_data_definitions(self):
        """
        Parse the yaml file of base yaml objects and return the information

        :arg file yaml_file: Open file object to read the yaml from
        :returns: An array of Markets that the user can travel to.
        """
        data_file = os.path.join(self.cfg['data_dir'], 'base', 'stellar.yml')
        schema_file = os.path.join(self.cfg['data_dir'], 'schema',
                                   'stellar-schema.json')

        loader = Loader(open(data_file).read())
        data = loader.get_single_data()

        schema = json.loads(open(schema_file).read())
        jsonschema.validate(data, schema)

        self.system_data = OrderedDict()
        for system in data['system']:
            self.system_data[system['name']] = SystemData(system['name'], None)

            locations = OrderedDict()
            for loc in system['location']:
                locations[loc['name']] = LocationData(
                    loc['name'], loc['type'], self.system_data[system['name']])
            self.system_data[system['name']].locations = locations

        # Commodities are anything that may be bought or sold at a particular
        # location.  The UI may separate these out into separate pieces.
        commodities = OrderedDict()
        for commodity in data['cargo']:
            commodities[commodity['name']] = CommodityData(
                commodity['name'],
                frozenset((commodity['type'], 'cargo')),
                commodity['mean_price'],
                commodity['standard_deviation'],
                commodity['depreciation_rate'],
                1,
                commodity['event'],
            )

        for commodity in data['equipment']:
            commodities[commodity['name']] = CommodityData(
                commodity['name'],
                frozenset((commodity['type'], 'equipment')),
                commodity['mean_price'],
                commodity['standard_deviation'],
                commodity['depreciation_rate'],
                commodity['holdspace'],
                commodity['event'],
            )

        for commodity in data['property']:
            commodities[commodity['name']] = CommodityData(
                commodity['name'],
                frozenset(('property', )),
                commodity['mean_price'],
                commodity['standard_deviation'],
                commodity['depreciation_rate'],
                0,
                commodity['event'],
            )
        self.commodity_data = commodities

        ### FIXME: Put ships into commodities too.
        ships = OrderedDict()
        for ship in data['ship']:
            ships[ship['name']] = ShipData(ship['name'], ship['mean_price'],
                                           ship['standard_deviation'],
                                           ship['depreciation_rate'],
                                           ship['holdspace'],
                                           ship['weaponmount'])
        self.ship_data = ships