def compardirs(path1, path2, iteration=1): #对比文件夹内容 result = True path_num_value = 1 #文件数量差异阈值 path_size_value = 1 #文件大小差异阈值 path_diff_value = 1 #文件内容差异阈值 path1_num = 0 path2_num = 0 path1_size = 0 path2_size = 0 files1_list = os.listdir(path1) #列出文件夹path下的文件列表 files2_list = os.listdir(path2) for i in range(len(files1_list)): #解压path1内的全部压缩文件 file = path1 + '/' + files1_list[i] if os.path.isfile(file): file_path = un_compress(file) for i in range(len(files2_list)): file = path2 + '/' + files2_list[i] if os.path.isfile(file): file_path = un_compress(file) try: commands("\\rm %s/*.tar*" % path1) commands("\\rm %s/*.tar*" % path2) except: pass path1_num = int( commands.getstatusoutput("ls %s -lR | grep '^-' | wc -l" % path1)[1]) #计算path1文件夹内所有文件数(包含子文件) path2_num = int( commands.getstatusoutput("ls %s -lR | grep '^-' | wc -l" % path2)[1]) path1_size = int( commands.getstatusoutput("du %s -s -k| awk '{print $1}'" % path1)[1]) #计算path1文件夹所占大小 path2_size = int( commands.getstatusoutput("du %s -s -k| awk '{print $1}'" % path2)[1]) path_diff = int( commands.getstatusoutput( "diff -rqH %s %s 2>/dev/null | wc -l" % (path1, path2))[1]) #计算path1与path2里面各级文件内容差异的数量 if abs(path1_size - path2_size) >= path_size_value: result = False print('文件大小差异%skb' % abs(path1_size - path2_size)) if abs(path1_num - path2_num) >= path_num_value: result = False print('文件数量差异%s个' % abs(path1_num - path2_num)) if path_diff >= path_diff_value: result = False print('文件内容差异%s个' % path_diff) return result
def main(): global p_eqArmor global p_eqWeapon runtime = 1 while runtime == 1: choice = input("Commands Test: >> ").lower() print("") commands(choice) if runtime == 2: battle()
def main(): #clear terminal window before starting game os.system('clear') # Prompt to show intro intro() # Set player's home point using setHome; access from getAllCitiesList player = Conductor(getAllCitiesList()[setHome()], 0) #First city_print (method from City object - print current city, state, options, and possibly destination.) player.location.printCity() # Game really starts. Overarching while loop begins. game_over = False while not game_over: # New cargo dropped_off = False # get random new destination city go_to_id = getRandomCity().city_id while go_to_id == player.location.city_id: # if the destination is the player's location go_to_id = getRandomCity().city_id #return city is current location, a.k.a. home from setHome(). original_id = player.location.city_id picked_up = False # First time with a new destination - quest printed in printCity() new_go_to = True # goTo(go_to_id, player, original_id, picked_up) while not dropped_off: # if first time with new pickup quest, print in printCity() and don't do it again if new_go_to: print(goTo(go_to_id, player, original_id, picked_up)) new_go_to = False # receive move input inputText = game_input( '> ', 'Whoops! Try again. For help, type \'help\' or \'h\'.', False, False, True) try: # If input is not an alternate command (look, map, etc). a.k.a. if input is a cardinal direction: if commands(inputText, player, go_to_id, original_id, picked_up) == 0: # move to input direction (1) if in directions possible (2) and set location to associated city (3) player.location = eval( move(inputText, player.location.directions_possible, player.location.cities_possible)) # print new city player.location.printCity() except TypeError: # print('Whoops! Try again. For help, type \'help\' or \'h\'.') if player.location.city_id == go_to_id and not picked_up: print(goTo(go_to_id, player, original_id, picked_up)) picked_up = True elif player.location.city_id == original_id and picked_up: dropped_off = True player.points += 1 print(goTo(go_to_id, player, original_id, picked_up))
def __init__(self, port, name, ip): self.cmdManager = commands(port, ip) print('command init') welcome = self.cmdManager.getWelcome(name) self.team = name self.nbClients = welcome[0] ai.__init__(self, *list(map(int, welcome[1].split()))) # play firsts moves optimized self.firstStep() # play the rest of the game self.play()
def run(file): #get prog with open(file) as prog: data = prog.read() #init vars part = 1 line = "" qu = 0 args = [] exe = [] stack = [] #split prog into the commands and the arguments for x in range(0,len(data)): if data[x] == "\"": if qu == 0: qu = 1 else: qu = 0 else: if (data[x] == " " or data[x] == "\n" or data[x] == ";") and qu != 1: if part == 1: if line != "": args.append(line) elif part == 2: if line != "": exe.append(line) line = "" else: line = line + data[x] if data[x] == ";": part = 2 if part == 1: args.append(line) elif part == 2: exe.append(line) #get dicts com = commands() cod = code() #run the commands arg = 0 prog = 0 while prog < len(exe): exist = com.get(exe[prog]) if not exist: error("line " + str(prog) + " " + exe[prog] ,1 + len("line " + str(prog) + " "),"command " + exe[prog] + " is not identified") else: exec(cod.get(exe[prog])) arg = int(arg) + int(com.get(exe[prog])) prog = int(prog) + 1
def download_latest_kernel(): html = urllib2.urlopen(kernelorg).read() soup = BeautifulSoup(html,'lxml') attr = soup.find('td',id="latest_link") download_link = attr.a['href'] status,result = commands('wget link_address') time.sleep(600) if status != 0: try: raise DownloadException("kernel download failed, please check network.") except DownloadException as e: print e.message sys.exit(0)
def stop_vservers(prefix = 'plc', exempt = []): # stop all running vservers vserver_stat = "vserver-stat | grep %(prefix)s | awk '{print$8}'" % locals() (stdin, stdout, stderr) = os.popen3(vserver_stat) vservers = [line.strip() for line in stdout.readlines()] vservers = filter(lambda x: x not in exempt, vservers) for vserver in vservers: try: utils.header("Stopping %(vserver)s " % locals()) stop_cmd = "vserver %(vserver)s stop" % locals() (status, output) = commands("vserver %(vserver)s stop" % locals()) except: print "Failed to stop %(vserver)s" % locals() utils.header("%s" % traceback.format_exc())
def handler(sig, frame): logging.info("Signal handler triggred.") commands("reload", conf_class)
cfile = parse(sys.argv[1]) logging.info("Config file is loaded sucessfully.") cfile = pre_execution(cfile) logging.info("Executing commands.") for cmd in cfile.config_class: execution(cmd, "execute") j = 1 for i in range(0, len(cfile.config_class)): cfile.config_class[i].name += "_" + str(j) if j == cfile.config_class[i].numprocs: j = 1 else: j += 1 thread = threading.Thread(target=deamon_loop, args=[cfile.config_class], name='Thread-1') thread.daemon = True thread.start() logging.info("Deamon started sucessfully.") signal.signal(signal.SIGHUP, handler) while (1): conf_class = cfile.config_class line = input(colors.bold + colors.cyan + "TaskMaster$ " + colors.endc) if line == "": continue commands(line.rstrip(), cfile.config_class) if line != "\n": logging.info("Userinput: {0}".format(line))