def exportDir(self, srcPath, expPath): print(srcPath, "->", expPath) os.makedirs(expPath, exist_ok=True) for root, dirs, files in os.walk(srcPath): skip = [] for d in dirs: if isPerson(d): skip.append(d) else: dst = os.path.join(root, d) dst = dst[len(srcPath) + 1:] dst = os.path.join(expPath, dst) os.makedirs(dst, exist_ok=True) for s in skip: dirs.remove(s) for f in files: if islink(f): continue dummy, ext = os.path.splitext(f) if ext in ['.tif']: continue src = os.path.join(root, f) dst = src[len(srcPath) + 1:] dst = os.path.join(expPath, dst) print(" ", src, "->", dst) self.copyFile(src, dst)
def scanTree(self, resolver): bad_links = [] for root, dirs, files in os.walk(self.treeRoot): files.extend(dirs) # linux ln to dir appear in dirs for f in files: if f.startswith(BCKf) or f.startswith(TMPf): continue link = os.path.join(root, f) if not islink(link): continue linkTgt = readLink(link) if linkTgt is None: bad_links.append(Link(link, None)) continue if linkTgt.endswith(NULL_LNK): continue resolver(link, linkTgt, bad_links) return bad_links
def cat(self, path, excludes=None): lclLinks = FindLocalLinks(path) if excludes is None: excludes = EXCLUDE htmlText = [ '<table style="border:0; margin-left: 40px;"><thead><tr><td><br></td><th>Name</th></tr></thead><tbody>' ] files = [] dirs = [] for i in os.listdir(path): i_fullpath = os.path.join(path, i) if exclude(i, excludes) or lclLinks.isFileReferenced( i) or isPerson(i) or islink(i_fullpath): continue if os.path.isdir(i_fullpath): dirs.append(i) else: files.append(i) for f in files: htmlText.extend(self.row(path, f, False)) for d in dirs: htmlText.extend(self.row(path, d, True)) htmlText.append('</tbody></table>') return (len(files) + len(dirs)), "".join(htmlText)
def find(d): spouses = [] for f in os.listdir(d): f_full = os.path.join(d, f) if not islink(f_full): continue match = PartnerLink.LINK_RE.match(f) if match is None: continue m = PartnerLink() m.relationship = match.groups()[0] num = match.groups()[1] if num == '': num = '1' lclName = match.groups()[2].split() m.forename = " ".join(lclName[0:-1]) m.surname = lclName[-1].upper() m.path = PartnerLink.getPath(f_full) spouses.append((num, m)) spouses.sort(key=lambda m: m[0]) return [m[1] for m in spouses]
def findLinkTo(path, inDir): '''Search <inDir> looking for a link that has <path> as its target''' for f in os.listdir(inDir): f = os.path.join(inDir, f) if not islink(f): continue try: linkTgt = readlink_f(os.path.join(inDir, f)) except ValueError: continue if linkTgt == path: return True return False