def __init__(self, playerId, board, players, setup='random', discard='random', rob='random', trade='none', build='best'): self.Setup = Setup(setup, playerId, board, players) self.Discard = Discard(discard, playerId, board, players) self.Rob = Rob(rob, playerId, board, players) self.Trade = Trade(trade, playerId, board, players) self.Build = Build(build, playerId, board, players)
def zip_package(sent_message, package_name, app_set_list): if app_set_list is not None and app_set_list.__len__() > 0: file_name = package_name app_set_build_list = Build.build_from_directory(app_set_list) print("Exporting " + str(file_name)) if sent_message is not None: sent_message.edit_text("Exporting " + str(file_name)) z = Export(file_name) return z.zip(app_set_build_list, sent_message) else: print("Package List Empty!")
class Strategy: Setup = None # 'random' - randomly places initial settlements and roads Discard = None # 'random' - randomly discard floor(half) cards when over 8 cards when 7 rolls Rob = None # 'random' - randomly places robber and robs randomly from enemy if able Trade = None # 'none' - never trades with anyone Build = None # 'best' - builds something that leaves the players total points highest def __init__(self, playerId, board, players, setup='random', discard='random', rob='random', trade='none', build='best'): self.Setup = Setup(setup, playerId, board, players) self.Discard = Discard(discard, playerId, board, players) self.Rob = Rob(rob, playerId, board, players) self.Trade = Trade(trade, playerId, board, players) self.Build = Build(build, playerId, board, players) def play(self, do): do = do.lower() if do == 'setup': self.Setup.go() elif do == 'discard': self.Discard.go() elif do == 'rob': self.Rob.go() elif do == 'trade': self.Trade.go() elif do == 'build': self.Build.go()
def main(): """Run the benchmark per arguments""" sum = Summary() options, args = getopt(sys.argv[1:], 'a:c:n:', ['list-projects', 'actions=', 'help', 'compiler=']) opt_actions = actions.default_actions set_compilers = [] opt_repeats = 1 for opt, optarg in options: if opt == '--help': show_help() return elif opt == '--list-projects': list_projects() return elif opt == '--actions' or opt == '-a': opt_actions = actions.parse_opt_actions(optarg) elif opt == '--compiler' or opt == '-c': set_compilers.append(compiler.parse_opt(optarg)) elif opt == '-n': opt_repeats = int(optarg) if not set_compilers: set_compilers = compiler.default_compilers() # Find named projects, or run all by default if args: chosen_projects = [find_project(name) for name in args] else: chosen_projects = trees.values() for proj in chosen_projects: proj.pre_actions(opt_actions) for comp in set_compilers: build = Build(proj, comp, opt_repeats) build.build_actions(opt_actions, sum) sum.print_table()
def main(): """Run the benchmark per arguments""" sum = Summary() options, args = getopt(sys.argv[1:], "a:c:n:", ["list-projects", "actions=", "help", "compiler="]) opt_actions = actions.default_actions set_compilers = [] opt_repeats = 1 for opt, optarg in options: if opt == "--help": show_help() return elif opt == "--list-projects": list_projects() return elif opt == "--actions" or opt == "-a": opt_actions = actions.parse_opt_actions(optarg) elif opt == "--compiler" or opt == "-c": set_compilers.append(compiler.parse_opt(optarg)) elif opt == "-n": opt_repeats = int(optarg) if not set_compilers: set_compilers = compiler.default_compilers() # Find named projects, or run all by default if args: chosen_projects = [find_project(name) for name in args] else: chosen_projects = trees.values() for proj in chosen_projects: proj.pre_actions(opt_actions) for comp in set_compilers: build = Build(proj, comp, opt_repeats) build.build_actions(opt_actions, sum) sum.print_table()
def attemptToFindBuildMachine(self, con, item): username = item["username"] projectname = item["projectname"] secret = item["secret"] packagename = item["packagename"] branchname = item["branchname"] lxcdistro = item["distro"] lxcrelease = item["release"] lxcarch = item["arch"] DependsOnOtherProjects = item["dependsOnOtherProjects"] AvoidDocker = item["avoiddocker"] AvoidLXC = item["avoidlxc"] SpecificMachine = item["buildmachine"] # 1: check if there is a package building that this package depends on => return False if self.CanFindDependanciesBuilding(username, projectname, packagename, branchname, lxcdistro, lxcrelease, lxcarch): return False # 2: check if any project that this package depends on is still building or waiting => return False for DependantProjectName in DependsOnOtherProjects: if self.CanFindMachineBuildingProject(username, DependantProjectName): return False lbs = Build(self, Logger(item['id'])) lbsName = self.GetLbsName(username, projectname, packagename, branchname, lxcdistro, lxcrelease, lxcarch) # get name of available slot buildmachine = self.GetAvailableBuildMachine(con, username, projectname, secret, packagename, branchname, lxcdistro, lxcrelease, lxcarch, AvoidDocker, AvoidLXC, SpecificMachine) if buildmachine is not None: stmt = "UPDATE build SET status='BUILDING', started=?, buildmachine=? WHERE id = ?" cursor = con.execute( stmt, (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), buildmachine, item['id'])) con.commit() thread = Thread(target=lbs.buildpackage, args=(username, projectname, packagename, branchname, lxcdistro, lxcrelease, lxcarch, buildmachine, item['id'])) thread.start() return True return False
def zip_package(sent_message, package_name, app_set_list, config_obj: NikGappsConfig = None): if config_obj is not None: config_obj: NikGappsConfig if config_obj.config_package_list.__len__() > 0: app_set_list = config_obj.config_package_list else: config_obj = NikGappsConfig() if app_set_list is not None and app_set_list.__len__() > 0: file_name = package_name config_obj.config_package_list = Build.build_from_directory( app_set_list) print("Exporting " + str(file_name)) if sent_message is not None: sent_message.edit_text("Exporting " + str(file_name)) z = Export(file_name) return z.zip(config_obj, sent_message) else: print("Package List Empty!")
dsl_syntax_error.msg = syntax_error.msg dsl_syntax_error.filename = syntax_error.filename dsl_syntax_error.message = syntax_error.message dsl_syntax_error.text = syntax_error.text dsl_syntax_error.offset = syntax_error.offset dsl_syntax_error.print_file_and_line = syntax_error.print_file_and_line dsl_syntax_error.understood_expression = cleaned_expression_string raise dsl_syntax_error else: if check(expression): check_analysis_out = [] def analysis_out(*things): check_analysis_out.append("".join(map(str, things))) check_analysis(expression, analysis_out) raise DSLTypeError("\n".join(check_analysis_out)) else: Build(expression) return expression from Units import (Units, units, analysis, WhateverUnitsAreNeeded, MeaninglessUnitsException, DimensionError) from Check import check, check_analysis from Build import Build from CodeGeneration import (R_Code_for_values, init_R_interpreter) from GridSizing import grid_sizes import Stringification
def main(): """Run the benchmark per arguments""" # Ensure that stdout and stderr are line buffered, rather than # block buffered, as might be the default when running with # stdout/stderr redirected to a file; this ensures that the # output is prompt, even when the script takes a long time for # a single step, and it also avoids confusing intermingling of # stdout and stderr. sys.stdout = os.fdopen(1, "w", 1) sys.stderr = os.fdopen(2, "w", 1) sum = Summary() options, args = getopt(sys.argv[1:], 'a:c:n:f:', ['list-projects', 'actions=', 'help', 'compiler=', 'cc=', 'cxx=', 'output=', 'force=']) opt_actions = actions.default_actions opt_cc = 'cc' opt_cxx = 'c++' opt_output = None opt_compilers = [] opt_repeats = 1 opt_force = 1 for opt, optarg in options: if opt == '--help': show_help() return elif opt == '--list-projects': list_projects() return elif opt == '--actions' or opt == '-a': opt_actions = actions.parse_opt_actions(optarg) elif opt == '--cc': opt_cc = optarg elif opt == '--cxx': opt_cxx = optarg elif opt == '--output': opt_output = optarg elif opt == '--compiler' or opt == '-c': opt_compilers.append(optarg) elif opt == '-n': opt_repeats = int(optarg) elif opt == '-f' or opt == '--force': opt_force = int(optarg) if opt_compilers: set_compilers = [compiler.parse_compiler_opt(c, cc=opt_cc, cxx=opt_cxx) for c in opt_compilers] else: set_compilers = compiler.default_compilers(cc=opt_cc, cxx=opt_cxx) # Find named projects, or run all by default if args: chosen_projects = [find_project(name) for name in args] else: chosen_projects = trees.values() for proj in chosen_projects: # Ignore actions we did in a previous benchmark run, absent -f. # We only run the project's pre-actions if one of the builds # needs it because it hasn't successfully run 'configure' yet. project_actions, _ = actions.remove_unnecessary_actions( opt_actions, opt_force, proj.did_download(), 0) proj.pre_actions(project_actions) for comp in set_compilers: build = Build(proj, comp, opt_repeats) _, build_actions = actions.remove_unnecessary_actions( opt_actions, opt_force, proj.did_download(), build.did_configure()) build.build_actions(build_actions, sum) sum.print_table() # If --output was specified, print the table to the output-file too if opt_output: old_stdout = sys.stdout sys.stdout = open(opt_output, 'w') try: sum.print_table() finally: sys.stdout.close() sys.stdout = old_stdout
def parse(expression_string): import re tokens = [] out = tokens.append def out_all(*pieces): tokens.extend(pieces) def write_table_name(scanner, table_name): out(table_name) def allowed_identifier(scanner, token): out(token) def operator(scanner, token): if token == "^": out("**") else: out(token) def write_number(scanner, number): out(number) def number_with_units(scanner, token): number, units = token.split(None, 1) out_all("Number(", number, ",'", units, "')") def whitespace(scanner, token): out(token) def parenthesis(scanner, token): out(token) def comma(scanner, token): out(token) allowed_names = {} for name in ("Sum Average StandardDeviation Minimum Maximum Count " "Months FromDate ToDate Number".split()): allowed_names[name] = globals()[name] for month_name in Months.options.keys(): if not isinstance(month_name, int): allowed_names[month_name] = month_name scanner_spec = ( (r"#.*?\n", whitespace), (r'"(' + "|".join(SampleTable._SampleTable__names.keys()) + ')"', write_table_name), (r"(%s)(?=\W)" % "|".join(allowed_names.keys()), allowed_identifier), (r"\+|\-|\/|\*|\=|\^", operator), (r"\(|\)", parenthesis), (r",", comma), (r"\s+", whitespace), (r"-?[0-9]+(?:\.[0-9]+)?\s+(?:(?:delta|Δ)\s+)?(?: *(?:%(units)s)(?:\^[0-9])?)* *(?:\/(?: *(?:%(units)s)(?:\^[0-9])?)*)?" % dict(units="|".join(units_in_out.keys())), number_with_units), (r"-?[0-9]*(\.[0-9]+)?", write_number), ) scanner = re.Scanner(scanner_spec) #print scanner_spec #print expression_string _, remainder = scanner.scan(expression_string) if remainder: raise SyntaxError("Syntax error near: '" + ("".join(remainder)) + "'") else: cleaned_expression_string = "(" + ("".join(tokens)) + ")" #print cleaned_expression_string expression = eval(cleaned_expression_string, allowed_names) if check(expression): check_analysis_out = [] def analysis_out(*things): check_analysis_out.append("".join(map(str, things))) check_analysis(expression, analysis_out) raise TypeError("\n".join(check_analysis_out)) else: Build(expression) return expression
def __init__(self, username, password, start_url, debug=False): self.session = self.login(username, password) self.url = start_url self.build = Build(self.session, self.url, debug) self.hero = Hero(self.session, self.url, debug) self.army = Army(self.session, self.url, debug)