def unlock(self, game, action, method="key"): # location = game.get_location() if (action): items = action.split(" with ") if (not (type(items) == list and len(items) == 2)): items = action.split(" w ") # alias if (type(items) == list and len(items) == 2): location = game.get_location() context = self._get_context(items[0], [location, game.player]) if (not context): utils.print_message("I cannot see a '{}'".format( colour.red(items[0]))) return ##TODO we could index target and use alias target = context.get_inventory_item(items[0]) if (not game.player.has_inventory_item(items[1])): utils.print_message("You dont have a {}".format( colour.red(items[1]))) return ##TODO we could index tools and use alias tool = game.player.get_inventory_item(items[1]) target.unlock(location, tool, method) else: method_display = method if (method == "key"): method_display = "unlock" utils.print_message( "I dont understand: '{}' - Try {} <item> with <item>.". format( colour.red(action), colour.red(method_display), )) else: utils.print_message( "I dont understand - Try: unlock <item> with <item>")
def on_message(client, userdata, msg): # triggers on an update print('topic is: ' + str(msg.topic)) print('message is: ' + str(msg.payload).replace("b'",'').replace("'",'')) command = str(msg.payload).replace("b'", '').replace("'", '').lower() if command == str('1'): # runs dummy file dummy.run() elif command == str('2'): # copy this statement and adjust for each script dummy2.run() elif "blue" in command: colour.blue() elif "red" in command: colour.red() print('')
def switch(self): if(utils.has_attribute(self._config, "switchable")): if("event" not in self._config): utils.print_message("Config Error: switch '{}' has no event in config.".format( colour.red(location_name) )) event = self._config["event"] if(self.game.locations.is_valid_location_name(event[0])): location = self.game.locations.get_location(event[0]) location.handle_event(event) if("switched" in self._config): utils.print_messages(self._config["switched"]) else: utils.print_message("Config Error: switch '{}' has bad event location in config.".format( colour.red(location_name) )) else: utils.print_message("You cannot switch this item.")
def take(self, game, item_name): location = game.get_location() if (item_name): if (location.has_inventory_item(item_name)): if (game.carrying_count >= game.max_carry): utils.print_message("{}".format( colour.red( "You cannot carry any more items - Try: drop <item>" ))) return item = location.get_inventory_item(item_name) item.take(location, game.player) else: utils.print_message( "I cant see a '{}' - Try: take <item>".format( colour.red(item_name))) else: utils.print_message("I dont understand - Try: take item")
def open(self, context): if (utils.has_attribute(self._config, "openable")): if (utils.has_attribute(self._config, "locked")): utils.print_message("Item '{}' is locked.".format( colour.red(self.name))) return if ("inside" in self._config): items = self._config.pop("inside", None) self._config["revealed"] = items item_name = sorted(items)[ 0] # only allow 1 item - inside stuff self.add_inventory_items(items) if (len(items) > 0): #if(utils.has_attribute(self._config, "door")): if ("opened" in self._config): utils.print_messages(self._config["opened"]) ## remove doors after open if (utils.has_attribute(self._config, "door")): context.remove_inventory_item(self.name) if (utils.has_attribute(self._config, "door")): utils.print_message( "You see the '{}' through the '{}'".format( colour.green(item_name), colour.green(self.name))) else: utils.print_message( "You see the '{}' in the '{}'".format( colour.green(item_name), colour.green(self.name))) if (self.has_inventory()): context.add_inventory_items(self.get_inventory_items()) else: if ("taken" in self._config and "inside" in self._config["taken"]): utils.print_message("{}".format( colour.red( "You cannot open this item until it has been taken."))) utils.print_message("Hint: {}".format( colour.green( "Taking items show more details - You may see more detail when examined, and be able to open it!" ))) return utils.print_message("{}".format( colour.red("You cannot open this item.")))
def _invoke(self, action): if (self._registry.has_command(action.action)): cmd = self._registry.get_command(action.action) if (cmd.pass_args): cmd.command(self._game, action.args) else: cmd.command(self._game) else: utils.print_message("I dont know how to '{}'".format( colour.red(action.action)))
def _go(self, game, location_name, location): if (not location.has_inventory_item(location_name)): utils.print_message( "I dont know how to get to '{}' - Try: go <place>".format( colour.red(location_name))) return location_item = location.get_inventory_item(location_name) if (not game.locations.is_valid_location_name(location_name)): if ("attributes" in location_item._config and "room" in location_item._config["attributes"]): utils.print_message( "Config Error: room '{}' not in config.".format( colour.red(location_name))) utils.print_message( "I dont know how to get to '{}' - Try: go <place>".format( colour.red(location_name))) return game.player.set_location_name(location_name) new_location = game.get_location() new_location.add_inventory_item(location.name, location_item) game.auto_examine()
def createTestSuite(engine): # Run all tests results = engine.run() #Posting Results to Server #params = { # "email": os.environ["APP_EMAIL"], # "podId": os.environ["POD_ID"], # "results" : json.dumps(results) #} #result = requests.post( # "https://3000-ab155182-05d4-4bf5-b47e-2b757b153877.ws-eu01.gitpod.io/api/test-result", # # "https://python-code-test-server.herokuapp.com/api/test-result", # data=params # ) print(f"Running tests for {engine.label}") for result in results: print("") if (result["status"] == "passed"): textGreen() print(u'\u2714', end=" ") textReset() print("{0}......{1}".format(result["name"], green("Passed"))) else: textRed() print(u'\u2718', end=" ") textReset() print("{0}.....{1}".format(result["name"], red("Failed"))) print("\tExpected") print("\t========") print("\t", result['expected']) print("") print("\tActual") print("\t========") print("\t", result['actual']) textReset() success, fail = agg(results) progress = (float(success) / len(engine.getTests()) * 100.0) print(f"{success} Successes") print(f"{fail} Fails") print(f"{engine.label} is {progress:.2f} % complete.") print("") print("") return results, success, fail, progress
def move(self, game, item_name): location = game.get_location() if (item_name): context = self._get_context(item_name, [location, game.player]) if (context): item = context.get_inventory_item(item_name) item.move(context) else: utils.print_message( "I cant see a '{}' - Try open <item>".format( colour.red(item_name))) else: utils.print_message("I dont know what to move - Try open <item>")
def handle_event(self, event): if ("on" not in self._config): utils.print_message( "Config Error: location '{}' has no event handlers in config.". format(colour.red(self.name))) on = self._config["on"] if (event[1] not in on): utils.print_message( "Config Error: location '{}' has no event target {} in config." .format(colour.red(self.name), colour.red(event[1]))) target = on[event[1]] if (event[2] not in target): utils.print_message( "Config Error: location '{}' has no event action {} in config." .format(colour.red(self.name), colour.red(event[2]))) details = target[event[2]] for key in details: self._config[key] = details[key]
def take(self, location, player): if ("attributes" in self._config and "takeable" in self._config["attributes"]): config = self.get_config() player.add_inventory_item(self.name, config) location.remove_inventory_item(self.name) if ("taken" in config): taken = config.pop("taken") for key in taken: config[key] = taken[key] utils.print_message("You take the '{}'".format( colour.green(self.name))) else: utils.print_message("You cannot take '{}'.".format( colour.red(self.name)))
def examine(self, game, item_name): location = game.get_location() if (item_name): if (location.has_inventory_item(item_name)): item = location.get_inventory_item(item_name) item.describe() item.reveal() if (item.has_inventory()): location.add_inventory_items(item.get_inventory_items()) elif (game.player.has_inventory_item(item_name)): item = game.player.get_inventory_item(item_name) item.describe() item.reveal() if (item.has_inventory()): game.player.add_inventory_items(item.get_inventory_items()) else: utils.print_message("Examine what '{}'?".format( colour.red(item_name))) else: location.describe() location.reveal()
def vermodCheck(filePath, versions, testNum): import colour exPrefix = colour.red('FAILURE') + ', Test #' + str(testNum) + ': ' if len(versions) != 4: raise Exception(exPrefix + 'Versions list is of the wrong size!') vMajor = str(versions[0]) vMinor = str(versions[1]) vRelease = str(versions[2]) vBuild = str(versions[3]) vString = vMajor + '.' + vMinor + '.' + vRelease + '.' + vBuild f = open(filePath, 'r') text = f.read() from re import search if(search('_VERSION_STRING "' + vString + '"', text) == None or search('_VERSION_MAJOR\\s+' + vMajor, text) == None or search('_VERSION_MINOR\\s+' + vMinor, text) == None or search('_VERSION_RELEASE\\s+' + vRelease, text) == None or search('_VERSION_BUILD\\s+' + vBuild, text) == None): raise Exception(exPrefix + 'One or more definitions were missing ' + 'or invalid.') print(colour.green('SUCCESS') + ', Test #' + str(testNum))
def unlock(self, context, tool, method): if (utils.has_attribute(self._config, "locked")): if (self._config["unlock"] == tool.name): if (method == "pick"): if (self._config["unlock-method"] == "key"): utils.print_message( "You cannot pick '{}' with a key '{}'.".format( colour.red(self.name), colour.red(tool.name), )) return if (utils.has_attribute(tool.get_config(), "damaged")): utils.print_message( "You cannot pick '{}' with a '{}'.".format( colour.red(self.name), colour.red(tool.name), )) return tool.damage() else: if (self._config["unlock-method"] == "pick"): utils.print_message( "You cannot unlock '{}' with a '{}'.".format( colour.red(self.name), colour.red(tool.name), )) return utils.remove_attribute(self._config, "locked") self.open(context) else: utils.print_message("You cannot {} '{}' with a '{}'.".format( method, colour.red(self.name), colour.red(tool.name), )) else: utils.print_message("You cannot unlock this item.")
def move(self, context): if (utils.has_attribute(self._config, "moveable")): if ("inside" in self._config): items = self._config.pop("inside", None) self._config["revealed"] = items item_name = sorted(items)[ 0] # only allow 1 item - inside stuff self.add_inventory_items(items) if (len(items) > 0): if ("moved" in self._config): utils.print_messages(self._config["moved"]) utils.print_message( "You see a '{}' after moving the '{}'".format( colour.green(item_name), colour.green(self.name))) if (self.has_inventory()): context.add_inventory_items(self.get_inventory_items()) else: utils.print_message("You moved the '{}'".format( colour.green(self.name))) else: utils.print_message("{}".format( colour.red("You cannot move this item.")))
def get_inventory_display(items): visible = [] for item_name in sorted(items): item = items[item_name] config = item if (not type(item) == dict): config = item.get_config() if (has_attribute(config, "room")): visible.append("'{}'".format(colour.yellow(item_name))) elif (has_attribute(config, "locked")): visible.append("'{}'".format(colour.red(item_name))) elif (has_attribute(config, "switchable")): visible.append("'{}'".format(colour.cyan(item_name))) # elif(has_attribute(config, "takeable")): # visible.append("'{}'".format(colour.cyan(item_name))) elif (has_attribute(config, "container")): visible.append("'{}'".format(colour.cyan(item_name))) elif (has_attribute(config, "openable")): visible.append("'{}'".format(colour.cyan(item_name))) else: visible.append("'{}'".format(colour.green(item_name))) #visible.append("'{}'".format(item_name)) formatted = [] part = [] max_per_line = 5 count = 1 for display in visible: if (count % max_per_line == 0): part.append(display) formatted.append(", ".join(part)) part = [] else: part.append(display) count += 1 formatted.append(", ".join(part)) return "\n ".join(formatted)
def open(self, game, item_name): location = game.get_location() if (item_name): context = self._get_context(item_name, [location, game.player]) if (context): item = context.get_inventory_item(item_name) item.open(context) else: utils.print_message( "I cant see a '{}' - Try open <item>".format( colour.red(item_name))) else: items = location.find_item_by_attribute("openable") item_names = sorted(items) if (len(item_names) > 1): utils.print_message( "I dont understand what to open - Try: open <item>") return if (len(item_names) < 1): utils.print_message( "There doesn't appear to be anything to open in the room.") return items[item_name].open(item_names[0])
def switch(self, game, item_name): location = game.get_location() if (item_name): if (location.has_inventory_item(item_name)): item = location.get_inventory_item(item_name) item.switch() else: utils.print_message( "I cant see a '{}' - Try switch <switch>".format( colour.red(item_name))) else: items = location.find_item_by_attribute("switchable") item_names = sorted(items) if (len(item_names) > 1): utils.print_message( "I dont understand which switch - Try: switch <switch>") return if (len(item_names) < 1): utils.print_message( "There doesn't appear to be a switch in the room.") return item = location.get_inventory_item(item_names[0]) item.switch()
import colour colour.blue() print("---") colour.yellow() x = input() import importlib importlib.reload(colour) colour.red() print("---")
import requests import json import os import sys from colour import red, green if __name__ == "__main__": if os.path.isfile('main.py'): cont = input( f'{red("main.py")} already exists. This command will overwrite the file. Continue (y)? ' ) if not (cont == 'y'): print(red("Stopping")) sys.exit(0) id = os.environ.get('CHALLENGE_ID') title = os.environ.get("CHALLENGE_TITLE") email = os.environ.get("EMAIL") print(f"Getting Files for Challenge ID {id} from DB.") print("") r = requests.get( f"https://cs-revise.leroysalih.vercel.app/api/challenge/{id}") obj = json.loads(r.text) f = open("./main.py", "w") f.write(obj['main'])
def main(args): # Define our test suite source files from os import mkdir, path sampleSrcPath = path.join('test', 'sample.h') testDirPath = path.join('build', 'test') sampleDstPath = path.join(testDirPath, 'sample.h') # Make our test suite's directories from shutil import copy2, rmtree try: rmtree('build') except: pass mkdir('build', 0o755) mkdir(testDirPath, 0o755) # Copy over our test suite sources copy2(sampleSrcPath, testDirPath) # Execute the tests! # Suite A: VersionMod script vermodCheck(sampleDstPath, [1, 1, 1, 1], 1) import versionmod versionmod.main(['versionmod.py', 'increment', 'major', sampleDstPath]) vermodCheck(sampleDstPath, [2, 0, 0, 0], 2) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) vermodCheck(sampleDstPath, [2, 0, 0, 3], 3) versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) vermodCheck(sampleDstPath, [2, 0, 1, 2], 4) versionmod.main(['versionmod.py', 'increment', 'minor', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath]) versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath]) vermodCheck(sampleDstPath, [2, 1, 3, 1], 5) versionmod.main(['versionmod.py', 'increment', 'major', sampleDstPath]) vermodCheck(sampleDstPath, [3, 0, 0, 0], 6) import colour print(colour.green('versionmod.py has passed testing.')) # Suite B: CopyDeps script exprefix = colour.red('FAILURE') + ', Test #7: ' from os import getcwd, listdir, path srcDir = path.join(getcwd(), 'test', 'deps') dstDir = path.join(getcwd(), 'build', 'test') import copydeps if(copydeps.main(['copydeps.py', srcDir, dstDir, '64', 'release']) != 0): raise Exception(exprefix + 'CopyDeps program failed testing.') assets = listdir(path.join(srcDir, 'assets', 'release')) for asset in assets: if path.isfile(asset) == False: continue bname = path.basename(asset) if path.isfile(path.join(dstDir, bname)) == False: raise Exception(exprefix + 'Asset file "' + bname + '" was ' + 'not copied into the destination directory.') libs = listdir(path.join(srcDir, 'lib64', 'release')) for lib in libs: if path.isfile(lib) == False: continue bname = path.basename(lib) if path.isfile(path.join(dstDir, bname)) == False: raise Exception(exprefix + 'Library file "' + bname + '" was' + ' not copied into the destination directory.') print(colour.green('copydeps.py has passed testing.') + '\n...') print(colour.green('All tests have passed.') + ' Exiting...')