def is_sgf_file(self, fn): ext = FileUtility.fileExt(fn) if ext == 'sgf': ret = 0 elif ext == 'sgf_': ret = 1 else: ret = None return ret
def create_db(self, dest_file, src_path, suffix = ["sgf", "sgf_"]): try: tar = None tar = tarfile.open(dest_file,"w:") ## path = os.path.normpath(src_path.strip()) for root, dir, files in os.walk(path): for fn in files: if FileUtility.fileExt(fn) not in suffix: continue fullpath = os.path.join(root, fn) tar.add(fullpath) except Exception, e: print e
def create_db(self, src_path, suffix = ["sgf", "sgf_"]): logdb_file = self.dbfile if os.path.exists(logdb_file): import FileUtility as fu dirname = os.path.dirname(logdb_file) if not fu.pathExists(dirname): fu.createPath(dirname) self.createTable() for p in FileUtility.listAll(src_path, just_directory = True, contain_file = True): norm_p = p.replace("\\", "/") if not norm_p.startswith("/"): norm_p = "/" + norm_p norm_p = UnicodeUtil.get_unicode_str(norm_p) xiti_set_saved = False fp = os.path.join(src_path, p.lstrip(os.path.sep)) fp = UnicodeUtil.get_unicode_str(fp) for fn in FileUtility.listfiles(fp): #print fn if FileUtility.fileExt(fn) not in suffix: continue if xiti_set_saved == False: fid = file_id(norm_p) self.add_xiti_set(norm_p, fid) xiti_set_saved = True fn = os.path.join(fp, fn) self.add_xiti(fid, fn)