def get_all_webkitdom_symbol_files(): static_symbol_files_path = common.top_level_path('Source', 'WebCore', 'bindings', 'gobject') generated_symbol_files_path = common.build_path('DerivedSources', 'webkitdom') symbol_files = [] for header_name in header_name_list_from_gtkdoc_config_file(): # webkitdomdefines.h doesn't have a corresponding symbols file and webkitdom.symbols is a # file containing the expected symbols results. if header_name in ("webkitdom.h", "webkitdomdefines.h"): continue symbol_file = header_name.replace(".h", ".symbols") path = os.path.join(static_symbol_files_path, symbol_file) if os.path.exists(path): symbol_files.append(path) continue path = os.path.join(generated_symbol_files_path, symbol_file) if os.path.exists(path): symbol_files.append(path) continue sys.stderr.write("Could not find symbol file for header: %s\n" % header_name) sys.exit(1) return symbol_files
def write_doc_files(): doc_dir = common.build_path('DerivedSources', 'webkitdom', 'docs') try: os.mkdir(doc_dir) except OSError, e: if e.errno != errno.EEXIST or not os.path.isdir(doc_dir): sys.stderr.write("Could not create doc dir at %s: %s\n" % (doc_dir, str(e))) sys.exit(1)
def write_doc_files(module_name): doc_dir = common.build_path('DerivedSources', 'webkitdom', 'docs') try: os.mkdir(doc_dir) except OSError, e: if e.errno != errno.EEXIST or not os.path.isdir(doc_dir): sys.stderr.write("Could not create doc dir at %s: %s\n" % (doc_dir, str(e))) sys.exit(1)
def header_name_list_from_gtkdoc_config_file(): config_file = common.build_path('gtkdoc-webkitdom.cfg') if not os.path.isfile(config_file): sys.stderr.write("Could not find config file at %s\n" % config_file) return sys.exit(1) config = SafeConfigParser() config.read(config_file) module_name = config.sections()[0] return [os.path.basename(f) for f in str(config.get(module_name, 'headers')).replace(';', ' ').split()]
def header_name_list_from_gtkdoc_config_file(): config_file = common.build_path('gtkdoc-webkitdom.cfg') if not os.path.isfile(config_file): sys.stderr.write("Could not find config file at %s\n" % config_file) return sys.exit(1) config = SafeConfigParser() config.read(config_file) module_name = config.sections()[0] return [ os.path.basename(f) for f in str(config.get( module_name, 'headers')).replace(';', ' ').split() ]
def write_doc_files(): doc_dir = common.build_path('DerivedSources', 'webkitdom', 'docs') try: os.mkdir(doc_dir) except: pass # Commonly happens if the directory already exists. with open(os.path.join(doc_dir, 'webkitdomgtk-sections.txt'), 'w') as sections_file: generator = WebKitDOMDocGeneratorSections(get_all_webkitdom_symbol_files(), sections_file) generator.generate() with open(os.path.join(doc_dir, 'webkitdomgtk-docs.sgml'), 'w') as sgml_file: generator = WebKitDOMDocGeneratorSGML(get_all_webkitdom_symbol_files(), sgml_file) generator.generate()
def build_part(part): install_dir = part.install_path() source_dir = part.source_path() build_dir = part.build_path() if part.gconfig.clean_build: remove_dir(build_dir) # copy tree: source -> build if not os.path.exists(build_dir): shutil.copytree(source_dir, build_dir) part.set_build_state("CLEAN") else: print_warn("Part '{}' has ever been built,".format(part.name), "in order to perform a clean build, use --clean-build") remove_dir(install_dir) # get module parameters and put them in 'module_params' var_name_prefix = part.build + "-" prefix_len = len(var_name_prefix) module_params = dict( (k[prefix_len:], v) for k, v in part.doc.iteritems() if len(k) > prefix_len and k[:prefix_len] == var_name_prefix) env = { "BUILD_ROOT": build_path(part.gconfig), "INSTALL_ROOT": install_path(part.gconfig), "BUILD_DIR": build_dir, "INSTALL_DIR": install_dir } # do the build prepare os.chdir(build_dir) build_prepare(part, env) # do the make main os.chdir(build_dir) if build_override(part, env) is False: part.build_module.build(part, module_params, env.copy()) part.set_build_state("BUILT") # do the make install os.chdir(build_dir) create_dir(install_dir) if install_override(part, env) is False: part.build_module.install(part, module_params, env.copy()) part.set_build_state("INSTALLED")
def write_doc_files(): doc_dir = common.build_path('DerivedSources', 'webkitdom', 'docs') try: os.mkdir(doc_dir) except: pass # Commonly happens if the directory already exists. with open(os.path.join(doc_dir, 'webkitdomgtk-sections.txt'), 'w') as sections_file: generator = WebKitDOMDocGeneratorSections( get_all_webkitdom_symbol_files(), sections_file) generator.generate() with open(os.path.join(doc_dir, 'webkitdomgtk-docs.sgml'), 'w') as sgml_file: generator = WebKitDOMDocGeneratorSGML(get_all_webkitdom_symbol_files(), sgml_file) generator.generate()
def get_all_webkitdom_symbol_files(): static_symbol_files_path = common.top_level_path('Source', 'WebCore', 'bindings', 'gobject') generated_symbol_files_path = common.build_path('DerivedSources', 'webkitdom') symbol_files = [] for header_name in header_name_list_from_gtkdoc_config_file(): # webkitdomdefines.h doesn't have a corresponding symbols file and webkitdom.symbols is a # file containing the expected symbols results. if header_name in ("webkitdom.h", "webkitdomdefines.h"): continue symbol_file = header_name.replace(".h", ".symbols") path = os.path.join(static_symbol_files_path, symbol_file) if os.path.exists(path): symbol_files.append(path) continue path = os.path.join(generated_symbol_files_path, symbol_file) if os.path.exists(path): symbol_files.append(path) continue return symbol_files
def iddfs(level, n, testall): initial_time = datetime.now() smap = level.smap first_node = Node(level.start, None, [], 0) deque = [] #metemos al nodo inicial en la cola deque.append(first_node) known_nodes = HashTable() known_nodes.put(first_node.config, first_node) nodes_processed = 0 # curr_n = n # mientras que la cola tenga elementos y no gane won = False limit_nodes_per_n = [] limit_nodes_per_n_size = 0 while deque and not won: # saco el primer nodo del stack node = deque.pop() # if node in processed: # l = list(processed) # idx = l.index(node) # if idx >= 0 and idx < len(l): # proc_node = l[idx] # if node.depth >= proc_node.depth: # pase = True # continue # else: # continue # primero me fijo si gane if (finished(node.config.boxes, level)): # si gane listo won = True else: nodes_processed += 1 # si no gane pido mis movimientos legales possible_configs = next_configs(node.config, level.smap) children = node.children if (node.depth + 1) % n == 0: children_at_limit = True else: children_at_limit = False for config in possible_configs: proc_node = known_nodes.get(config) if proc_node and node.depth + 1 >= proc_node.depth: continue new_node = Node(copy.copy(config), node, [], node.depth + 1) known_nodes.put(config, new_node) children.append(new_node) if children_at_limit: limit_idx = int(new_node.depth / n) - 1 if len(limit_nodes_per_n) < limit_idx + 1: limit_nodes_per_n.append(0) limit_nodes_per_n[limit_idx] += 1 deque.insert(0, new_node) else: deque.append(new_node) # print("Added move: ", new_node.config) # print("Used configs: ", processed) # print("deque is: ", deque) finish_time = datetime.now() elapsed_time = finish_time - initial_time #print(limit_nodes_per_n) if won: path = build_path(node) return process_results(won, testall, elapsed_time, smap, node, path, f"{ALGORITHM_NAME} (n='{n}')", nodes_processed - 1, len(deque)) else: return process_results(won, testall, elapsed_time, smap, None, [], f"{ALGORITHM_NAME} (n='{n}')", nodes_processed - 1, len(deque))
def idastar(level, heu, testall): h=heu["func"] initial_time = datetime.now() smap = level.smap first_node = Node(level.start, None, [], 0, {'g': 0, 'h': h(smap, level.goals, level.start)}) lim = first_node.meta['g'] + first_node.meta['h'] # f(n0) min_exceeded_lim = -1 def cp(e1, e2): g1 = e1.meta['g'] g2 = e2.meta['g'] h1 = e1.meta['h'] h2 = e2.meta['h'] f1 = g1 + h1 f2 = g2 + h2 if f1 == f2: return h1 - h2 else: return f1 - f2 q1 = [] q2 = [] out_of_frontier = OrderedList(cp) q1.append(first_node) known_nodes = HashTable() known_nodes.put(first_node.config, first_node) nodes_processed = 0 won = False first_found = False while (q1 or q2) and not won: if not q1: q1 = q2 q2 = [] lim = min_exceeded_lim min_exceeded_lim = -1 node = q1.pop() f = node.meta['g'] + node.meta['h'] if f > lim: q2.append(node) continue if(finished(node.config.boxes, level)): won = True else: nodes_processed += 1 possible_configs = next_configs(node.config, level.smap) children = node.children for config in possible_configs: proc_node = known_nodes.get(config) if proc_node and node.depth + 1 >= proc_node.depth: continue new_node = Node(copy.copy(config), node, [], node.depth + 1, {'g': node.depth + 1, 'h': h(smap, level.goals, config)}) known_nodes.put(config, new_node) children.append(new_node) f = new_node.meta['g'] + new_node.meta['h'] if f > lim: q2.append(new_node) if min_exceeded_lim == -1 or f < min_exceeded_lim: min_exceeded_lim = f else: q1.append(new_node) finish_time = datetime.now() elapsed_time = finish_time - initial_time if won: path = build_path(node) return process_results(won, testall, elapsed_time, smap, node, path, f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, len(q1) + len(q2)) else: return process_results(won, testall, elapsed_time, smap, None, [], f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, len(q1) + len(q2))
def dfs(level, testall): initial_time = datetime.now() smap = level.smap first_node = Node(level.start, None, []) stack = [] #metemos al nodo inicial en la cola stack.append(first_node) known_cfgs = set() known_cfgs.add(first_node.config) nodes_processed = 0 # mientras que la cola tenga elementos y no gane won = False while stack and not won: # saco el primer nodo del stack node = stack.pop() # print('ITERATION: ', nodes_processed, ' --------------------------------------------------------------') # print("Current node: ", node.config) # primero me fijo si gane if (finished(node.config.boxes, level)): # si gane listo # print("Found solution!") won = True else: nodes_processed += 1 # si no gane pido mis movimientos legales possible_configs = next_configs(node.config, level.smap) # print("Possible configs: ", possible_configs) children = node.children #por cada movimiento legal me fijo si ya tube esta config antes y si no la apendeo a la cola # print("Procesed: ===>", processed) for config in possible_configs: if config in known_cfgs: continue known_cfgs.add(config) new_node = Node(copy.copy(config), node, []) children.append(new_node) stack.append(new_node) # print("Added move: ", new_node.config) # print("Used configs: ", processed) # print("Stack is: ", stack) finish_time = datetime.now() elapsed_time = finish_time - initial_time if won: path = build_path(node) return process_results(won, testall, elapsed_time, smap, node, path, ALGORITHM_NAME, nodes_processed - 1, len(stack)) else: return process_results(won, testall, elapsed_time, smap, None, [], ALGORITHM_NAME, nodes_processed - 1, len(stack))
def build_state_path(self): return os.path.join(build_path(self.gconfig), ".state." + self.name)
def build_path(self): return os.path.join(build_path(self.gconfig), self.name)
def astar(level, heu, testall): h = heu["func"] initial_time = datetime.now() smap = level.smap first_node = Node(level.start, None, [], 0, { 'g': 0, 'h': h(smap, level.goals, level.start) }) def cp(e1, e2): g1 = e1.meta['g'] g2 = e2.meta['g'] h1 = e1.meta['h'] h2 = e2.meta['h'] f1 = g1 + h1 f2 = g2 + h2 if f1 == f2: return h1 - h2 else: return f1 - f2 nodes_list = OrderedList(cp) nodes_list.add(first_node) #known_cfgs = set() known_nodes = HashTable() #known_cfgs.add(first_node.config) known_nodes.put(first_node.config, first_node) nodes_processed = 0 won = False while nodes_list.length() > 0 and not won: node = nodes_list.pop() if (finished(node.config.boxes, level)): won = True else: nodes_processed += 1 possible_configs = next_configs(node.config, level.smap) children = node.children for config in possible_configs: proc_node = known_nodes.get(config) new_node = Node(copy.copy(config), node, [], node.depth + 1, { 'g': node.depth + 1, 'h': h(smap, level.goals, config) }) if proc_node: new_node_f = new_node.meta['g'] + new_node.meta['h'] proc_node_f = proc_node.meta['g'] + proc_node.meta['h'] if (new_node_f >= proc_node_f): continue # if config in known_cfgs: # continue #known_cfgs.add(config) known_nodes.put(config, new_node) children.append(new_node) nodes_list.add(new_node) finish_time = datetime.now() elapsed_time = finish_time - initial_time if won: path = build_path(node) return process_results(won, testall, elapsed_time, smap, node, path, f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, nodes_list.length()) else: return process_results(won, testall, elapsed_time, smap, None, [], f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, nodes_list.length())
def ggs(level, heu, testall): h = heu["func"] initial_time = datetime.now() smap = level.smap first_node = Node(level.start, None, [], 0, {'h': h(smap, level.goals, level.start)}) def cp(e1, e2): return e1.meta['h'] - e2.meta['h'] nodes_list = OrderedList(cp) #metemos al nodo inicial en la cola ( ͡° ͜ʖ ͡°) nodes_list.add(first_node) known_cfgs = set() known_cfgs.add(first_node.config) nodes_processed = 0 # mientras que la cola tenga elementos y no gane won = False while nodes_list.length() > 0 and not won: # saco el primer nodo del nodes_list node = nodes_list.pop() # print('ITERATION: ', nodes_processed, ' --------------------------------------------------------------') # print("Current node: ", node.config) # primero me fijo si gane if (finished(node.config.boxes, level)): # si gane listo # print("Found solution!") won = True else: nodes_processed += 1 # si no gane pido mis movimientos legales possible_configs = next_configs(node.config, level.smap) # print("Possible configs: ", possible_configs) children = node.children #por cada movimiento legal me fijo si ya tube esta config antes y si no la apendeo a la cola # print("Procesed: ===>", processed) for config in possible_configs: if config in known_cfgs: continue known_cfgs.add(config) new_node = Node(copy.copy(config), node, [], node.depth + 1, {'h': h(smap, level.goals, config)}) children.append(new_node) nodes_list.add(new_node) # print("Added move: ", new_node.config) # print("Used configs: ", processed) # print("Stack is: ", stack) finish_time = datetime.now() elapsed_time = finish_time - initial_time if won: path = build_path(node) return process_results(won, testall, elapsed_time, smap, node, path, f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, nodes_list.length()) else: return process_results(won, testall, elapsed_time, smap, None, [], f"{ALGORITHM_NAME} ({heu['name']})", nodes_processed - 1, nodes_list.length())