import Queue class Publish: def removeOldTar(self): cmd='ls ' + self.oss_root_dir + " | awk '{print $5}'" self.debug(cmd) rs=commands.getoutput(cmd) arrList=rs.split(' ') keeplist=Queue.Queue(self.keepOldPackageNum) for tar in arrList: if len(tar) < 20: continue if keeplist.full(): deltar=keeplist.get() print deltar cmd_del_tar='del ' + tar self.debug(cmd_del_tar) os.system(cmd_del_tar) keeplist.put(tar) else: keeplist.put(tar) def execute(self): self.removeOldTar() obj=Publish() obj.execute()