def __clean_before_after(self, stateBefore, stateAfter, keepNoneEmptyDirectory=True):
<EOL>errors    = []<EOL>afterDict = {}<EOL>[afterDict.setdefault(list(aitem)[<NUM_LIT:0>],[]).append(aitem) for aitem in stateAfter]<EOL>for bitem in reversed(stateBefore):<EOL><INDENT>relaPath = list(bitem)[<NUM_LIT:0>]<EOL>basename = os.path.basename(relaPath)<EOL>btype    = bitem[relaPath]['<STR_LIT:type>']<EOL>alist    = afterDict.get(relaPath, [])<EOL>aitem    = [a for a in alist if a[relaPath]['<STR_LIT:type>']==btype]<EOL>if len(aitem)><NUM_LIT:1>:<EOL><INDENT>errors.append("<STR_LIT>"%(basename,btype,relaPath))<EOL>continue<EOL><DEDENT>if not len(aitem):<EOL><INDENT>removeDirs  = []<EOL>removeFiles = []<EOL>if btype == '<STR_LIT>':<EOL><INDENT>if not len(relaPath):<EOL><INDENT>errors.append("<STR_LIT>")<EOL>continue<EOL><DEDENT>removeDirs.append(os.path.join(self.__path,relaPath))<EOL>removeFiles.append(os.path.join(self.__path,relaPath,self.__dirInfo))<EOL>removeFiles.append(os.path.join(self.__path,relaPath,self.__dirLock))<EOL><DEDENT>elif btype == '<STR_LIT:file>':<EOL><INDENT>removeFiles.append(os.path.join(self.__path,relaPath))<EOL>removeFiles.append(os.path.join(self.__path,relaPath,self.__fileInfo%basename))<EOL>removeFiles.append(os.path.join(self.__path,relaPath,self.__fileLock%basename))<EOL><DEDENT>else:<EOL><INDENT>removeDirs.append(os.path.join(self.__path,relaPath))<EOL>removeFiles.append(os.path.join(self.__path,relaPath,self.__fileInfo%basename))<EOL><DEDENT>for fpath in removeFiles:<EOL><INDENT>if os.path.isfile(fpath):<EOL><INDENT>try:<EOL><INDENT>os.remove(fpath)<EOL><DEDENT>except Exception as err:<EOL><INDENT>errors.append("<STR_LIT>"%(fpath, str(err)))<EOL><DEDENT><DEDENT><DEDENT>for dpath in removeDirs:<EOL><INDENT>if os.path.isdir(dpath):<EOL><INDENT>if keepNoneEmptyDirectory or not len(os.listdir(dpath)):<EOL><INDENT>try:<EOL><INDENT>shutil.rmtree(dpath)<EOL><DEDENT>except Exception as err:<EOL><INDENT>errors.append("<STR_LIT>"%(fpath, str(err)))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return len(errors)==<NUM_LIT:0>, errors<EOL>
clean repository given before and after states