def _blueprint(secret, name): """ Fetch a blueprint from S3 and turn it into a real Blueprint object. The name can't be given as a kwarg or Blueprint.__init__ will go looking for the JSON in Git. """ data = backend.get_blueprint(secret, name) if data is None: return None elif data is False: return False b = Blueprint() b.name = name b.update(json.loads(data)) return b
def get_blueprint_resource(): with simple_page.open_resource('static/style.css') as f: code = f.read() from blueprint import Blueprint admin = Blueprint('admin', __name__, static_folder='static', template_folder='templates') url_for('admin.static', filename='style.css')
def pull(server, secret, name): """ Pull a blueprint from the secret and name on the configured server. """ r = http.get("/{0}/{1}".format(secret, name), server=server) if 200 == r.status: b = Blueprint() b.name = name b.update(json.loads(r.read())) for filename in b.sources.itervalues(): logging.info("fetching source tarballs - this may take a while") r = http.get("/{0}/{1}/{2}".format(secret, name, filename), server=server) if 200 == r.status: try: f = open(filename, "w") f.write(r.read()) except OSError: logging.error("could not open {0}".format(filename)) return None finally: f.close() elif 404 == r.status: logging.error("{0} not found".format(filename)) return None elif 502 == r.status: logging.error("upstream storage service failed") return None else: logging.error("unexpected {0} fetching tarball".format(r.status)) return None return b elif 404 == r.status: logging.error("blueprint not found") elif 502 == r.status: logging.error("upstream storage service failed") else: logging.error("unexpected {0} fetching blueprint".format(r.status)) return None
def pull(server, secret, name): """ Pull a blueprint from the secret and name on the configured server. """ r = http.get('/{0}/{1}'.format(secret, name), server=server) if 200 == r.status: b = Blueprint.load(r, name) for filename in b.sources.itervalues(): logging.info('fetching source tarballs - this may take a while') r = http.get('/{0}/{1}/{2}'.format(secret, name, filename), server=server) if 200 == r.status: try: f = open(filename, 'w') f.write(r.read()) except OSError: logging.error('could not open {0}'.format(filename)) return None finally: f.close() elif 404 == r.status: logging.error('{0} not found'.format(filename)) return None elif 502 == r.status: logging.error('upstream storage service failed') return None else: logging.error('unexpected {0} fetching tarball'. format(r.status)) return None return b elif 404 == r.status: logging.error('blueprint not found') elif 502 == r.status: logging.error('upstream storage service failed') else: logging.error('unexpected {0} fetching blueprint'.format(r.status)) return None
action='store_true') group1.add_argument('-j', '--json-schema', help='Return schema of variables for a rendered template', action='store_true') format1.add_argument('-n', '--no-indent', help='Disable Junos-style Indentation', action='store_true', default=False, required=False) args = parser.parse_args() bp = Blueprint(template_dir=args.template_dir, base_template=args.base_template, values=args.config_vars) if args.comments is True and args.stream_only is False: parser.error('--comments requires -s/--stream-only') try: if args.stream_only is True: if args.no_indent is False: print(junos_indent(bp.get_stream(comments=args.comments))) else: print(bp.get_stream(comments=args.comments)) elif args.get_vars is True: print(bp.get_variables()) elif args.json_schema is True: schema = bp.get_json_schema()
def callback_client_handle(self, connection_object, data): #print("Server: Recieved data \""+str(data)+"\" from client \""+str(connection_object.address)+"\".") # use the data to determine what player is giving the command and if they are logged in yet. if (isinstance( data, Command)): # the data we recieved was a command. process it. if (data.command == 'login'): if (data.args[0] == 'password' ): # TODO: put an actual password system in. print('password accepted for ' + str(data.ident)) if (not data.ident in self.players ): # this player doesn't exist in the world yet. # check and see if the players has logged in before. tmp_player = self.worldmap.get_player( data.ident) # by 'name' if (tmp_player is not None): # player exists print('player exists. loading.') self.players[data.ident] = tmp_player self.players[ data.ident].position = tmp_player.position self.localmaps[ data. ident] = self.worldmap.get_chunks_near_position( self.players[data.ident].position) else: # new player print('new player joined.') self.players[data.ident] = Player(data.ident) self.players[data.ident].position = random.choice( self.starting_locations) self.worldmap.put_object_at_position( self.players[data.ident], self.players[data.ident].position) self.localmaps[ data. ident] = self.worldmap.get_chunks_near_position( self.players[data.ident].position) print('Player ' + str(data.ident) + ' entered the world at position ' + str(self.players[data.ident].position)) self.callback_client_send(connection_object, self.players[data.ident]) else: print('password not accepted.') connection_object.disconnect() if (data.command == 'request_player_update'): self.callback_client_send(connection_object, self.players[data.ident]) if (data.command == 'request_localmap_update'): self.localmaps[ data.ident] = self.worldmap.get_chunks_near_position( self.players[data.ident].position) self.callback_client_send(connection_object, self.localmaps[data.ident]) # all the commands that are actions need to be put into the command_queue then we will loop through the queue each turn and process the actions. if (data.command == 'move'): self.players[data.ident].command_queue.append( Action(self.players[data.ident], 'move', [data.args[0]])) if (data.command == 'bash'): self.players[data.ident].command_queue.append( Action(self.players[data.ident], 'bash', [data.args[0]])) if (data.command == 'create_blueprint'): # [result, direction]) # args 0 is ident args 1 is direction. print('creating blueprint ' + str(data.args[0]) + ' for player ' + str(self.players[data.ident])) # blueprint rules # * there should be blueprints for terrain, furniture, items, and anything else that takes a slot up in the Worldmap. # * they act as placeholders and then 'transform' into the type they are once completed. # Blueprint(type, recipe) position_to_create_at = None if (data.args[1] == 'south'): position_to_create_at = Position( self.players[data.ident].position.x, self.players[data.ident].position.y + 1, self.players[data.ident].position.z) elif (data.args[1] == 'north'): position_to_create_at = Position( self.players[data.ident].position.x, self.players[data.ident].position.y - 1, self.players[data.ident].position.z) elif (data.args[1] == 'east'): sposition_to_create_at = Position( self.players[data.ident].position.x + 1, self.players[data.ident].position.y, self.players[data.ident].position.z) elif (data.args[1] == 'west'): position_to_create_at = Position( self.players[data.ident].position.x - 1, self.players[data.ident].position.y, self.players[data.ident].position.z) _recipe = server.RecipeManager.RECIPE_TYPES[data.args[0]] type_of = _recipe['type_of'] bp_to_create = Blueprint(type_of, _recipe) self.worldmap.put_object_at_position(bp_to_create, position_to_create_at) if (data.command == 'calculated_move'): print( 'Recieved calculated_move action. let\'s build a path for ' + str(data.ident)) _position = Position(data.args[0], data.args[1], data.args[2]) _route = self.calculate_route( self.players[data.ident].position, _position ) # returns a route from point 0 to point 1 as a series of Position(s) # fill the queue with move commands to reach the tile. _x = self.players[data.ident].position.x _y = self.players[data.ident].position.y _z = self.players[data.ident].position.z action = None for step in _route: _next_x = step.x _next_y = step.y _next_z = step.z if (_x > _next_x): action = Action(self.players[data.ident], 'move', ['west']) elif (_x < _next_x): action = Action(self.players[data.ident], 'move', ['east']) elif (_y > _next_y): action = Action(self.players[data.ident], 'move', ['north']) elif (_y < _next_y): action = Action(self.players[data.ident], 'move', ['south']) elif (_z < _next_z): action = Action(self.players[data.ident], 'move', ['up']) elif (_z > _next_z): action = Action(self.players[data.ident], 'move', ['down']) self.players[data.ident].command_queue.append(action) # pretend as if we are in the next position. _x = _next_x _y = _next_y _z = _next_z if (data.command == 'move_item'): # client sends 'hey server. can you move this item from this to that?' _player_requesting = self.players[data.ident] _item = data.args[0] # the item we are moving. _from_type = data.args[ 1] # creature.held_item, creature.held_item.container, bodypart.equipped, bodypart.equipped.container, position, blueprint _from_list = [ ] # the object list that contains the item. parse the type and fill this properly. _to_list = data.args[ 2] # the list the item will end up. passed from command. _position = Position( data.args[3], data.args[4], data.args[5] ) # pass the position even if we may not need it. # need to parse where it's coming from and where it's going. if (_from_type == 'creature.held_item'): # item is coming from the _player_requesting.items_held list _from_list = _player_requesting.items_held if (_item in _from_list )[:]: # iterate a copy to remove correctly _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return elif (_from_type == 'creature.held_item.container'): for bodypart in _player_requesting.body_parts[:]: # iterate a copy to remove properly. for item in bodypart.equipped: #could be a container or not. if (isinstance(item, Container)): # if it's a container. for item2 in item.contained_items[:]: # check every item in the container. if (item2 is _item): from_list = item.contained_items _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return elif (_from_type == 'bodypart.equipped'): for bodypart in _player_requesting.body_parts[:]: # iterate a copy to remove properly. if (_item in bodypart.equipped): _from_list = bodypart.equipped _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return elif (_from_type == 'bodypart.equipped.container'): for bodypart in _player_requesting.body_parts[:]: # iterate a copy to remove properly. for item in bodypart.equipped: #could be a container or not. if (isinstance(item, Container)): # if it's a container. for item2 in item.contained_items[:]: # check every item in the container. if (item2 is _item): from_list = item.contained_items _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return elif (_from_type == 'position'): #how do we get the position? _from_list = self.worldmap.get_tile_by_position( _position)['items'] if (_item in _from_list): _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return elif ( _from_type == 'blueprint' ): # a blueprint is a type of container but can't be moved from it's world position. for item in self.worldmap.get_tile_by_position( _position)['items']: if (isinstance(item) == Blueprint ): # only one blueprint allowed per space. _from_list = item.contained_items _from_list.remove(_item) _to_list.append(_item) print('moved correctly.') return ### possible move types ### # creature(held) to creature(held) (give to another player) # creature(held) to position(ground) (drop) # creature(held) to bodypart (equip) # bodypart to creature(held) (unequip) # bodypart to position (drop) # position to creature(held) (pick up from ground) # position to bodypart (equip from ground) # position to position (move from here to there) # creature to blueprint (fill blueprint) # blueprint to position (empty blueprint on ground) # blueprint to creature (grab from blueprint) return super(Server, self).callback_client_handle(connection_object, data)
def blueprint(): return Blueprint(template_dir='tests/templates', base_template='parent.j2', template_suffix='.j2', values='values.yaml' )