Exemple #1
0
 def get_exp_from_conf(self, exp_name):
     try:
         with open(path.join(self.challenge_path, exp_name, "config.yaml"), 'r') as fp:
             conf = load_exp_config(fp)
     except Exception as e:
         Context.logger.error(traceback.format_exc())
         return None
     snapshot = dirsnapshot.DirectorySnapshot(path.join(self.challenge_path, exp_name))
     return Exp(exp_name, path.join(self.challenge_path, exp_name, conf['path']), conf['retry'], conf['timeout'],
                conf['weight'], snapshot)
Exemple #2
0
 def get_exp_default(self, exp_name):
     entry = None
     for f in os.listdir(path.join(self.challenge_path, exp_name)):
         if f[:3] == "exp":
             entry = f
             break
     if entry:
         snapshot = dirsnapshot.DirectorySnapshot(path.join(self.challenge_path, exp_name))
         return Exp(exp_name, path.join(self.challenge_path, exp_name, entry), 3, 30, 10, snapshot)
     else:
         return None
Exemple #3
0
    def check_exp_update(self):
        modify_exps = []

        old_exp_name = set()
        for exp in self.exps_o:
            old_exp_name.add(exp.name)

        new_exp_name = set()
        for f in os.listdir(self.challenge_path):
            if path.isdir(path.join(self.challenge_path, f)):
                new_exp_name.add(f)

        add_exp_name = new_exp_name.difference(old_exp_name)
        del_exp_name = old_exp_name.difference(new_exp_name)

        remain_exp = new_exp_name.intersection(old_exp_name)
        for exp_name in remain_exp:
            exp = None
            for e in self.exps_o:
                if e.name == exp_name:
                    exp = e
                    break
            # exp will not be None
            snapshot = dirsnapshot.DirectorySnapshot(path.join(
                self.challenge_path, exp_name),
                                                     recursive=True)
            if not self.is_modify(exp.snapshot, snapshot):
                continue
            exp_obj = self.get_exp(exp_name)
            if not exp_obj:
                # we deal this as exp is delete
                del_exp_name.add(exp_name)
            else:
                modify_exps.append(exp_obj)
        add_exps = []
        for name in add_exp_name:
            exp_obj = self.get_exp(name)
            if exp_obj:
                add_exps.append(exp_obj)

        self.resort_exp(add_exps, del_exp_name, modify_exps)
Exemple #4
0
    def on_any_event(self,event):
        logging.info('[*] Event catched!')
        self.__FileNewSnap = dirsnapshot.DirectorySnapshot(self.__DirPath)
        FileCmp =FileState(self.__FileOldSnap,self.__FileNewSnap)
        CmpState = 0
        CmpState = FileCmp.GetState()
        if CmpState & e_dirs_created :# 检测文件夹创建
            DirArray = FileCmp.dirs_created
            for element in DirArray:
                print '[*] Directory Created! ',element
        if CmpState & e_dirs_moved :# 检测文件夹重命名
            DirMovedArray = FileCmp.dirs_moved
            for element in DirMovedArray:
                print '[*] Directory :',element[0],'renamed as :',element[1]            
        if CmpState & e_files_created :# 检测文件的创建
            FileArray = FileCmp.files_created
            for element in FileArray:
                print '[*] File Created! ',element
                log = '[*] File Created! '+element
                logging.info(log)
                self.__FileCount += 1
        if CmpState & e_files_modified:# 检测文件是否进行了更改
            FileArray = FileCmp.files_modified
            for element in FileArray:
                print '[*] File modified! ',element
        if CmpState & e_files_moved:# 检测文件重命名事件
            FileMovedArray = FileCmp.files_moved
            for element in FileMovedArray:
                print '[*] File :',element[0],'renamed as :',element[1]

        self.__FileOldSnap = self.__FileNewSnap # 更新列表
        if self.__FileCount > 16:
            self.__FileCount = 0
            FileList = FileTree(self.__DirPath)
            FileList.SetNode()
            fFile = FileList.CheckFileExt('.txt')
            if self.__ComThread == None or self.__ComThread.IsRunning() == False:
                self.__ComThread = CompressThread(fFile)
                if not self.__ComThread.IsRunning():
                    self.__ComThread.start()
Exemple #5
0
 def __init__(self,path):
     #FileSystemEventHandler.__init__(self)
     super(MyFileHandler,self).__init__()
     self.__DirPath = path
     self.__FileOldSnap = dirsnapshot.DirectorySnapshot(self.__DirPath)
     self.__FileCount = 0