def main(): # Check that at least one file was passed to the script if len(sys.argv) < 2: print("Run: python undark.py <file1> <file2> <etc>") print("Ex: python undark.py UNDARK.ZZT") print("\nThis script will set all boards from the provided ZZT " + "files to not be dark.") sys.exit() # Iterate over the files provided for file_name in sys.argv[1:]: # Create a Zookeeper object zoo = Zookeeper() # Load the file zoo.load_file(file_name) # Parse the file's world information zoo.parse_world() # Parse the file's board information zoo.parse_boards() print("Loaded world:", zoo.meta.file_name) # Remove darkness from any boards where the room is dark. modified = False for board in zoo.boards: if board.is_dark: if not modified: print("Dark board found. Let there be light!") modified = True board.is_dark = False # If any dark rooms were found, the file needs to be saved if modified: print("World has been modified. Saving world... ", end="") zoo.save() print("Saved!") else: print("World is already lit. No changes made.") print("-" * 40) print("\nAll worlds processed.")
class ConfigEngine(object): def __init__(self): self.zookeeper = Zookeeper() self.hadoop = Hadoop() self.hbase = HBase() self.hive = Hive() self.ignite = Ignite() def waiting(self): while True: print('Waiting...') time.sleep(5) def configure(self): self.zookeeper.configure() self.hadoop.configure() # self.hbase.configure() self.hive.configure() self.ignite.configure()
def lions_tigers_and_bears(zzts): lines = [] filler_line = "+----------+-------+-------+-------+-------+-------+-------+-------+" lines.append('\n' + filler_line) lines.append( "| FILENAME | LIONS | TIGRS | BEARS | AMMO | TRCHS | BRDS | DkRms |") lines.append(filler_line) for zzt in zzts: z = Zookeeper(zzt) dark_boards, lion_count, tiger_count, bear_count, torch_count, ammo_count = 0, 0, 0, 0, 0, 0 working_line = "| " + pad_to( textwrap.shorten(zzt, len(zzt) - 4, placeholder=''), 9) for board in z.boards: if board.is_dark: dark_boards += 1 for element in board.elements: if element.id == 41: lion_count += 1 elif element.id == 42: tiger_count += 1 elif element.id == 34: bear_count += 1 elif element.id == 5: ammo_count += 1 elif element.id == 6: torch_count += 1 working_line += str(lion_count) working_line = pad_to(working_line, 19) working_line += str(tiger_count) working_line = pad_to(working_line, 27) working_line += str(bear_count) working_line = pad_to(working_line, 35) working_line += str(ammo_count) working_line = pad_to(working_line, 43) working_line += str(torch_count) working_line = pad_to(working_line, 51) working_line += str(len(z.boards)) working_line = pad_to(working_line, 59) working_line += str(dark_boards) working_line = pad_to(working_line, 67) lines.append(working_line) lines.append(filler_line) for line in lines: print(line) return
def codesize(path, summary_only): z = Zookeeper(path) lines = [] filler_line = "+----------+---------------------------------------------------+-------+-------+-------+------+" lines.append('\n' + filler_line) lines.append( "| FILENAME | BOARD | BYTES | RLE | OOP | OOP% |" ) lines.append(filler_line) size_total = 0 oop_total = 0 disp_path = "| " + pad_to( textwrap.shorten(path, len(path) - 4, placeholder=''), 9) for board in z.boards: size_total += board.size board_line = disp_path + board.title board_oop = 0 for stat in board.stats: if stat.oop_length: board_oop += stat.oop_length oop_total += board_oop board_rle = 3 * len(board.rle_elements) board_line = pad_to(board_line, 63) + str(board.size) board_line = pad_to(board_line, 71) + str(board_rle) board_line = pad_to(board_line, 79) + str(board_oop) board_line = pad_to(board_line, 87) + sdec( (board_oop / board.size) * 100) board_line = pad_to(board_line, 94) lines.append(board_line) board_line = "\n" + path + " size is " + str( size_total) + "b and total ZZT-OOP size is " + str( oop_total) + "b for a total of " + sdec( (oop_total / size_total) * 100) + " percent ZZT-OOP." lines.append(filler_line + "\n" + board_line) if summary_only == False: for line in lines: print(line) else: print(board_line) return
def main(): #path = input("ZZT file path:") path = "/mnt/ez/486/ZZT/201X/ZOMBINAT.ZZT" z = Zookeeper(path) for board in z.boards: print(board.title) for stat in board.stats: if stat.oop: code = stat.oop.split("\n") for line in code: if line.startswith("#give score"): print("\t", code[0]) print("\t\t", line)
def __init__(self): self.zookeeper = Zookeeper() self.hadoop = Hadoop() self.hbase = HBase() self.hive = Hive() self.ignite = Ignite()
"| startStorm : " "| reboot : ") options, args = parser.parse_args() if len(sys.argv) == 1: print "Type python %s -h or --help for options help." % sys.argv[0] else: if options.command == "": print "Must given -c option\"s value" else: if options.command == "requireInstall": Infra.install(ClusterOptions(True)) if options.command == "deployAll": cluster_options = ClusterOptions(True) Zookeeper.install(cluster_options) Hadoop.install(cluster_options) Storm.install(cluster_options) Hive.install(cluster_options) HBase.install(cluster_options) if options.command == "startZookeeper": Zookeeper.start(ClusterOptions()) if options.command == "stopZookeeper": Zookeeper.stop(ClusterOptions()) if options.command == "startStorm": Storm.start(ClusterOptions()) if options.command == "initCluster":
def main(): # Check that at least one file was passed to the script if len(sys.argv) < 2: print("Run: python unlocker.py <file1> <file2> <etc>") print("Ex: python unlocker.py LOCK-LCK.ZZT LOCK-UNL.ZZT " + "LOCK-SPR.ZZT LOCK-SAV.ZZT") print("\nThis script will remove all locks (normal, super, save) " + "from the provided ZZT files.") sys.exit() # Iterate over the files provided for file_name in sys.argv[1:]: # Create a Zookeeper object zoo = Zookeeper() # Load the file zoo.load_file(file_name) # Parse the file's world information zoo.parse_world() # Parse the file's board information zoo.parse_boards() print("Loaded world:", zoo.meta.file_name) ######################################## # Regular Lock ######################################## # Check for a regular lock -- This lock is performed by having a flag # named SECRET set in the world header. print("Checking for regular lock... ", end="") locked = False new_flags = [] for flag in zoo.world.flags: if flag.name.upper() == "SECRET": locked = True new_flags.append("") else: new_flags.append(flag.name) if locked: print("Found!") print("Removing lock... ", end="") # Erase the current flag list zoo.world.flags = [] # Set flags matching the list generated earlier (identical to the # old list, but with SECRET removed) for x in range(0, 10): flag = Flag(new_flags[x]) zoo.world.flags.append(flag) print("Complete!") else: print("No lock found.") ######################################## # Super Lock ######################################## # Check for a super lock -- This lock is performed by renaming boards # to hyperlinks. # The board's number is put in the name to make editing easier than # searching through a dozen !c;LOCKED FILE boards. print("Checking for super lock... ", end="") super_locked = False board_idx = 0 for board in zoo.boards: if board.title[0] == "!" or board.title[0] == ":": if not super_locked: super_locked = True print("Found!") print("Removing super lock...", end="") board.title = str(board_idx).zfill(3) + board.title.encode("utf-8").decode("utf-8") + " " + board.title.split(";", 1)[-1] board_idx += 1 if super_locked: print("Complete!") else: print("No super lock found.") ######################################## # Save Lock ######################################## # Check for a save lock -- This lock is performed by saving a game, # then renaming the file extension of the save to .ZZT. # If the save byte is set, simply set it back to 0 to mark the world # as a ZZT world and not a ZZT save. print("Checking for save lock... ", end="") save_locked = False if zoo.world.saved_game: save_locked = True print("Found!") print("Removing save lock... ", end="") zoo.world.saved_game = False if save_locked: print("Complete!") else: print("No save lock found.") # If any locks were found, the file needs to be saved if locked or super_locked or save_locked: print("World has been modified. Saving unlocked world... ", end="") zoo.save() print("Saved!") else: print("World is already unlocked. No changes made.") print("-"*40) print("\nAll worlds processed.")
def __init__(self, name : str, keeper : str) -> None: self.name = name self.keeper = Zookeeper(keeper)
def how_impressive_are(zzts): # define element_colors: array of arrays element_colors, text_elements, text_chars = stk_prep() # policy: decided NOT to count cyan, brown or purple "on" dark other colors for the time being. # will consider evidence of a multi-iteration loop of running, editing, savelock+debug etc. lines = [("")] max_impressiveness = 0 for zzt in zzts: stk_found = 0 non_stk_found = 0 name = zzt[0] path = zzt[1] size_total = os.path.getsize(path) oop_total = 0 z = Zookeeper(zzt[1]) for board in z.boards: # super-tool-kit analysis for element in board.elements: try: if len(element_colors[element.id]) > 0: if element.color_id not in element_colors[element.id]: stk_found += 1 element_x, element_y = (element.tile % 60), (element.tile // 60) else: non_stk_found += 1 elif element.id in text_elements: if element.character not in text_chars: stk_found += 1 element_x, element_y = (element.tile % 60), (element.tile // 60) else: non_stk_found += 1 except IndexError: print("Warning: " + zzt[0] + " board " + board.title + " may be corrupted.") break #board oop analysis board_oop = 0 for stat in board.stats: if stat.oop_length: board_oop += stat.oop_length oop_total += board_oop oop_percent = sdec((oop_total / size_total) * 100) rle_found = non_stk_found + stk_found stk_percent = sdec((stk_found / rle_found) * 100) impressiveness = sdec((((stk_found / rle_found) * 10) + ((oop_total / size_total) * 10)) / 2) impressiveness_val = ((((stk_found / rle_found) * 10) + ((oop_total / size_total) * 10)) / 2) max_impressiveness = max(max_impressiveness, impressiveness_val) oop_line = str(size_total) + " | " + str( oop_total) + " OOP | " + oop_percent + "% OOP" stk_line = str(rle_found) + " rle | " + str( stk_found) + " stk | " + stk_percent + "% STK" lines.append(zzt[0] + " | " + oop_line + " | " + stk_line + " | I = " + impressiveness) lines.append("Max I-value in group: I = " + sdec(max_impressiveness)) return lines
def stk_check(zzts, details=False): # define element_colors: array of arrays # policy: decided NOT to count cyan, brown or purple "on" dark other colors for the time being. # will consider evidence of a multi-iteration loop of running, editing, savelock+debug etc. element_colors = [] std_hacks = [ 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 20, 31, 47, 63, 79, 95, 111, 127, 143, 191, 223, 239, 159, 149, 32, 112, 249 ] std_waterhacks = [121, 122, 123, 124, 125, 126] std_doors = [ 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 20, 31, 47, 63, 79, 95, 111, 127, 143, 175, 191, 207, 223, 239 ] # thx to dr dos for pointing out the color 15 white on black isn't a valid passage color obtainable outside of hex codes, but rather blinking white on black 143 std_passages = [143, 31, 47, 63, 79, 95, 111, 127] text_chars = [] for x in range(32, 127): text_chars.append(x) for x in range(0, 54): element_colors.append([]) element_colors[7] = std_hacks.copy() #gem element_colors[7].append(112) element_colors[8] = std_hacks.copy() #Key element_colors[9] = std_doors.copy() #door element_colors[11] = std_passages.copy() #Passage" element_colors[12] = [15, 31, 127] #duplicator element_colors[13] = std_hacks.copy() + std_waterhacks.copy() #Bomb" element_colors[16] = std_hacks.copy() #Clockwise Conveyor" element_colors[17] = std_hacks.copy() #Counter Clockwise Conveyor" element_colors[19] = std_hacks.copy() #water element_colors[21] = std_hacks.copy() #Solid Wall" element_colors[22] = std_hacks.copy() #Normal Wall" element_colors[23] = std_hacks.copy() #Breakable Wall" element_colors[24] = std_hacks.copy() #Boulder" element_colors[25] = std_hacks.copy() #Slider (NS)" element_colors[26] = std_hacks.copy() #Slider (EW)" element_colors[27] = std_hacks.copy() #Fake Wall" element_colors[28] = std_hacks.copy() #Invisible Wall" element_colors[29] = std_hacks.copy() + std_waterhacks.copy() #Blinkwall element_colors[30] = std_hacks.copy() + std_waterhacks.copy( ) #Transporter" element_colors[31] = std_hacks.copy() #Line Wall" element_colors[33] = std_hacks.copy() #H-Blinkray" element_colors[36] = std_hacks.copy() + std_waterhacks.copy() #Object" element_colors[37] = std_hacks.copy() + std_waterhacks.copy() #Slime element_colors[39] = std_hacks.copy() + std_waterhacks.copy( ) #spinning gun element_colors[40] = std_hacks.copy() + std_waterhacks.copy() #Pusher element_colors[43] = std_hacks.copy() #V-Blinkray" element_colors[44] = std_hacks.copy() + std_waterhacks.copy() + [0] #head element_colors[45] = std_hacks.copy() + std_waterhacks.copy() + [ 0 ] #segment element_colors[5] = [3] #ammo element_colors[6] = [6] #torch element_colors[14] = [5] #Energizer element_colors[19] = std_hacks.copy() #water element_colors[19].append(159) element_colors[19].append(249) element_colors[20] = [32] #Forest" element_colors[32] = [] #Ricochet" element_colors[32].append(10) #Ricochet" element_colors[34] = [6, 118] #Bear element_colors[35] = [13, 125] #Ruffian element_colors[38] = [7, 23, 39, 55, 71, 87, 103, 119] #shark element_colors[41] = [12, 124] #Lion element_colors[42] = [11, 123] #Tiger text_elements = [47, 48, 49, 50, 51, 52, 53] lines = [("")] print("") for zzt in zzts: stk_found = 0 non_stk_found = 0 name = zzt[0] path = zzt[1] z = Zookeeper(zzt[1]) print("Checking " + zzt[0] + "...") for board in z.boards: for element in board.elements: try: if len(element_colors[element.id]) > 0: if element.color_id not in element_colors[element.id]: stk_found += 1 element_x, element_y = (element.tile % 60), (element.tile // 60) if details: print(zzt[0] + " STK element on " + board.title + " " + str(element_x) + "," + str(element_y) + ": " + str(element.color_id)) else: non_stk_found += 1 elif element.id in text_elements: if element.character not in text_chars: stk_found += 1 element_x, element_y = (element.tile % 60), (element.tile // 60) if details: print(zzt[0] + " STK element on " + board.title + " " + str(element_x) + "," + str(element_y) + ": " + str(element.color_id)) else: non_stk_found += 1 except IndexError: print("Warning: " + zzt[0] + " board " + board.title + " may be corrupted.") break lines.append(zzt[0] + " | non-STK: " + str(non_stk_found) + " | STK: " + str(stk_found) + " | % STK: " + sdec(stk_found / (non_stk_found + stk_found) * 100)) return lines
@desc: """ import os import sys import subprocess from zookeeper import Zookeeper zk_nodelist = "10.12.1.174:2181,10.12.1.171:2181,10.12.1.234:2181" zk_process_id_path = "/nonzc/mms/pick" zk_config_node = "/nonzc/mms/pick/mms_pick.ini" local_config_path = "f:/test_config" # zk_nodelist = os.environ("zk_node_list") # zk_process_id_path = os.environ("zk_process_id_path") # zk_config_node = os.environ("zk_config_node") # local_config_path = os.environ("local_config_path") zoo = Zookeeper(zk_nodelist, None) process_id = zoo.get_node(zk_process_id_path) process_id = ''.join(process_id.split('_')[1:]) config_file_name = process_id + "_" + os.path.basename(zk_config_node) local_config_name = local_config_path + "/" + config_file_name flag = zoo.get_config(zk_config_node, local_config_name) if flag is False: sys.exit() out = subprocess.Popen( ["python", "./complex_pick.py ", "-c", local_config_name])
if process_path == "": print("process path is null, please check the config file,exit") sys.exit() if zk_filenamepool == "": print("zk filenamepool is null, please check the config file,exit") sys.exit() MAX_MERGE_FILE_SEQUENCE = 86400 / merge_interval - 1 zk_host_list = cfg["zookeeper"]["zklist"].strip() if zk_host_list == "": print("zk host list is null! please check the config file") sys.exit() # 创建zookeeper实例 zoo = Zookeeper(zk_host_list, MAX_MERGE_FILE_SEQUENCE) zoo.connect() # work_node = zoo.get_node(process_path) work_node = "process_" + process_id # process_id = ''.join(work_node.split('_')[1:]) pl.set_log(log_path, process_id) # ------------------------------------ line_limit = cfg["common"]["line_limit"].strip() input_path = cfg["common"]["inputdir"].strip() output_path = cfg["common"]["destdir"].strip() batch_size = cfg["common"]["batchsize"].strip() bak_path = cfg["common"]["bakpath"].strip() filename_part = cfg["rule"]["filenamepart"].strip() # ------------------------------------ if line_limit == "": line_limit = 2000000
#Instantiate all animals with the specific wakeup strategy we want them to have animalsInZoo.append(animals.cat.Cat("Carl", angryWakeup)) animalsInZoo.append(animals.dog.Dog("Dan", niceWakeup)) animalsInZoo.append(animals.elephant.Elephant("Earl", reluctantWakeup)) animalsInZoo.append(animals.hippo.Hippo("Henry", reluctantWakeup)) animalsInZoo.append(animals.lion.Lion("Loid", angryWakeup)) animalsInZoo.append(animals.rhino.Rhino("Rick", niceWakeup)) animalsInZoo.append(animals.tiger.Tiger("Timmy", reluctantWakeup)) animalsInZoo.append(animals.wolf.Wolf("Walt", niceWakeup)) return animalsInZoo if __name__ == "__main__": zooPopulation = populateZoo() #Just listing all the animals in the zoo for sanity check print("Animals in zoo:") for animal in zooPopulation: print(animal.getName() + " the " + animal.getAnimalType()) #Instantiate the announcer for the observer patern alex = ZooAnnouncer('Alex') zeus = Zookeeper() #Make the zookeeper observable by our observer zeus.registerobserver(alex) zeus.doDuties(zooPopulation) zeus.shutdownZoo()
def main(): global all_boards global visited_board_index_list # Check that at least three arguments were passed to the script if len(sys.argv) < 4: print( "Run: python atlas.py <zztworld> <outputfilename> <startingboardindex>" ) print("Ex: python atlas.py WORLD.ZZT ATLAS.PNG 8") print( "\nThis script will save a PNG of the world map starting from the specified board." ) sys.exit() #Define screen height and width here so we don't have to repeat them screen_height = 350 screen_width = 480 # Iterate over the files provided file_name = sys.argv[1] output_file_name = sys.argv[2] starting_board = sys.argv[3] # Create a Zookeeper object zoo = Zookeeper(file_name) all_boards = zoo.boards #Now explore the world starting from the given board number. #We pass in the starting board index and say that it's at coordinate 0, 0 print("Loaded world:", zoo.meta.file_name) print("-" * 40) print("Exploring...") board_coordinate_map = explore_world(int(starting_board), {}, 0, 0) #Print the board coordinate map that we generated print("-" * 40) print("Generated board coordinate map") print(board_coordinate_map) #To find the dimensions of our image, get the maximum and minimum X/Y coordinates #in the map. The total width or height is the difference between the two, plus one. min_x = None min_y = None max_x = None max_y = None for board_index in board_coordinate_map: x = board_coordinate_map[board_index]['x'] y = board_coordinate_map[board_index]['y'] if (min_x == None or x < min_x): min_x = x if (min_y == None or y < min_y): min_y = y if (max_x == None or x > max_x): max_x = x if (max_y == None or y > max_y): max_y = y atlas_width = (max_x - min_x) + 1 atlas_height = (max_y - min_y) + 1 print("Board coordinate map is " + str(atlas_width) + " by " + str(atlas_height) + " screens") print("-" * 40) #Now we want to create a black image of the size we worked out so we can start pasting screenshots in atlas_image = Image.new( "RGB", (screen_width * atlas_width, screen_height * atlas_height), "black") print("Rendering included boards...") #Render only the images that we need from the list of all boards images = {} for idx, board in enumerate(all_boards): if (idx in list(board_coordinate_map.keys())): images[idx] = board.render() print("Rendered board " + str(idx)) print("-" * 40) print("Assembling...") #Now paste the images into our canvas according to their coordinates in the map. #Offset them with our minimum X/Y coordinates so that the minimum comes out as 0, 0 for board_index in board_coordinate_map: x = board_coordinate_map[board_index]['x'] y = board_coordinate_map[board_index]['y'] x -= min_x y -= min_y print("Pasting board " + str(board_index) + " \"" + all_boards[board_index].title + "\" at " + str(x) + ", " + str(y)) atlas_image.paste(images[board_index], (screen_width * x, screen_height * y)) #Finally, save the large image and declare that we're finished! atlas_image.save(output_file_name) print("-" * 40) print("\nSaved " + output_file_name + ".")
if zk_host_list == "": print("zk host list is null! please check the config file") sys.exit() if not os.path.exists(log_path): print("logpath:%s not exist, please check the config file" % log_path) sys.exit() if not os.path.exists(bak_path): print("bak_path:%s not exist, please check the config file" % log_path) sys.exit() if not os.path.exists(bak_path): print("bak_path:%s not exist, please check the config file" % log_path) sys.exit() # 创建zookeeper实例 zoo = Zookeeper(zk_host_list, None) zoo.connect() # work_node = zoo.get_node(zk_process_path) # process_id = ''.join(work_node.split('_')[1:]) work_node = "process_" + process_id pl.set_log(log_path, process_id) flow = config.create_flow(process_id) redo_node = zk_process_path + "/" + work_node + "/" + "redo" redo_node_flag = zoo.check_exists(redo_node) if redo_node_flag is not None: redo_info, stat = zoo.get_node_value(redo_node) redo_info = bytes.decode(redo_info) if redo_info is not None: output_dirs = config.output_dirs logging.info("redo info %s" % redo_info) zk_redo = ZkRedo(redo_info, process_id, input_dir, output_dirs,
def main(): zoo = [] #Cats Carmen = Cat("Carmen") zoo.append(Carmen) Chloe = Cat("Chloe") zoo.append(Chloe) Caidy = Cat("Caidy") zoo.append(Caidy) #Lions Leeroy = Lion("Leeroy") Leeroy.setAnimalEat(AnimalEatMeat()) zoo.append(Leeroy) Leon = Lion("Leon") Leon.setAnimalEat(AnimalEatMeat()) zoo.append(Leon) #Tigers Tony = Tiger("Tony") Tony.setAnimalEat(AnimalEatMeat()) zoo.append(Tony) Tom = Tiger("Tom") Tom.setAnimalEat(AnimalEatMeat()) zoo.append(Tom) Timmy = Tiger("Timmy") Timmy.setAnimalEat(AnimalEatMeat()) zoo.append(Timmy) #Elephants Edith = Elephant("Edith") Edith.setAnimalEat(AnimalEatVegetarian()) zoo.append(Edith) Erin = Elephant("Erin") Erin.setAnimalEat(AnimalEatVegetarian()) zoo.append(Erin) #Rhinos Ryan = Rhino("Ryan") Ryan.setAnimalEat(AnimalEatVegetarian()) zoo.append(Ryan) Robert = Rhino("Robert") Robert.setAnimalEat(AnimalEatVegetarian()) zoo.append(Robert) Ronan = Rhino("Ronan") Ronan.setAnimalEat(AnimalEatVegetarian()) zoo.append(Ronan) #Hippos Harper = Hippo("Harper") Harper.setAnimalEat(AnimalEatVegetarian()) zoo.append(Harper) Hector = Hippo("Hector") Hector.setAnimalEat(AnimalEatVegetarian()) zoo.append(Hector) #Dogs Douglas = Dog("Douglas") Douglas.setAnimalEat(AnimalEatMeat()) zoo.append(Douglas) Damian = Dog("Damian") Damian.setAnimalEat(AnimalEatMeat()) zoo.append(Damian) Dominic = Dog("Dominic") Dominic.setAnimalEat(AnimalEatMeat()) zoo.append(Dominic) Daisy = Dog("Daisy") Daisy.setAnimalEat(AnimalEatMeat()) zoo.append(Daisy) #Wolves Wilson = Wolf("Wilson") Wilson.setAnimalEat(AnimalEatMeat()) zoo.append(Wilson) Wendy = Wolf("Wendy") Wendy.setAnimalEat(AnimalEatMeat()) zoo.append(Wendy) #PROOF OF DYNAMIC BEHAIVOR AT RUN TIME #(All other eat behaivor set at object instatiation above) Carmen.setAnimalEat(AnimalEatPreMixedFood()) Caidy.setAnimalEat(AnimalEatPreMixedFood()) Chloe.setAnimalEat(AnimalEatPreMixedFood()) Kanye = Zookeeper(zoo) #Subject Kim = ZooAnnouncer(Kanye) #Observer Kanye.registerObserver(Kim) Kanye.beAZookeeper() del Kim del Kanye for animal in zoo: del animal
''' @author: lipd @file: test_zk.py @time: 2018/4/26 10:17 @desc: ''' import sys sys.path.append("..") from zookeeper import Zookeeper list_redo = ["step:begin", "filename:test4,test2"] zoo = Zookeeper("10.12.1.174:2181,10.12.1.171:2181,10.12.1.234:2181", None) zk_node = "/nonzc/test" zoo.test_transaction() # node = zoo.get_node(zk_node) # process_id = ''.join(node.split('_')[1:]) # print(process_id) # # flag1 = zoo.create_node(zk_node + "/" + node + "/" + "redo") # # print(flag1) # flag2 = zoo.set_node_value(zk_node + "/" + node + "/" + "redo", ";".join(list_redo).encode('utf-8')) # print(flag2) # data, stat = zoo.get_node_value(zk_node + "/" + node + "/" + "redo") # # print("data:", data) # print("stat", stat)