Пример #1
0
    def resolver_backlink(self, link, linkTgt, bad_links):
        linkTgt_abs = absTgtpath(link, linkTgt)

        if not os.path.exists(linkTgt_abs):
            # Quietly skip
            return

        path = os.path.dirname(link)
        if not os.path.isdir(path):
            return

        tmp = path.split(os.sep)
        if not isPerson(tmp[-1]):
            return

        tmp = linkTgt_abs.split(os.sep)
        if not isPerson(tmp[-1]):
            return

        # Go to the linkTgt_abs directory and look for a link which has
        # path as its target
        if not findLinkTo(path, linkTgt_abs):
            clan, name = extractPersonName(path)
            # We can't determine sex here hence the 'p.'
            newLink = os.path.join(
                linkTgt_abs,
                'p. %s %s' % (name.capitalize(), clan.capitalize()))

            # Make the new link relative if the original one was
            if not ntpath.isabs(linkTgt):
                path = os.path.relpath(path, os.path.dirname(newLink))

            bad_links.append(Backlink(link, linkTgt, newLink, path))
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
def bond(other_path,
         relationship=PartnerLink.REL_PARTNER,
         linkType=None,
         me_path=None,
         force=False,
         absLink=False,
         quiet=False):
    mklnk = getLinkMaker(linkType)

    if me_path is None:
        me_path = os.path.abspath('.')

    me_name = extractPersonName(me_path)
    if (not isClan(me_name[0])) or (not isPerson(me_name[1])):
        raise Exception("my path %s is not a valid person" % (me_path))

    other_name = extractPersonName(other_path)
    if (not isClan(other_name[0])) or (not isPerson(other_name[1])):
        raise Exception("spouse path %s is not a valid person" % (other_path))

    me_rel = PartnerLink.getMyRelationship(relationship)

    me_to_other_lnk = os.path.join(
        me_path, relationship + '. ' + other_name[1] + ' ' + other_name[0])
    other_to_me_lnk = os.path.join(
        other_path, me_rel + '. ' + me_name[1] + ' ' + me_name[0])

    if os.path.exists(me_to_other_lnk) and not force:
        raise Exception("Spouse link already exists @ %s" % (me_to_other_lnk))

    if os.path.exists(other_to_me_lnk) and not force:
        raise Exception("Spouse link already exists @ %s" % (other_to_me_lnk))

    if not quiet:
        print("create: '%s' -> '%s'" % (me_to_other_lnk, other_path))
        print("create: '%s' -> '%s'" % (other_to_me_lnk, me_path))

    if quiet or oktodo("OK to create links?"):
        if os.path.exists(me_to_other_lnk):
            os.remove(me_to_other_lnk)
        if os.path.exists(other_to_me_lnk):
            os.remove(other_to_me_lnk)

        _create_spouse_link(me_to_other_lnk, other_path, mklnk, absLink)
        _create_spouse_link(other_to_me_lnk, me_path, mklnk, absLink)
Пример #5
0
    def getPerson(self, path):
        path = os.path.abspath(path)
        splitpath = path.split(os.sep)

        if (len(splitpath) <= len(self.splitroot)) or (not isPerson(
                splitpath[-1])):
            return None

        p = self.people.get(path)

        if (p is None) and (not self.treeFrozen):
            p = Person(self.id, path, self)
            self.id += 1
            self.people[path] = p

        return p
Пример #6
0
    def scan(self):
        for root, dirs, files in os.walk(self.root):
            skip = []
            for d in dirs:
                if isPerson(d):
                    p = self.getPerson(os.path.join(root, d))
                    # Need to lookup spouses so that any links are scanned
                    p.spouses()
                    p.getVitalRecords()
                elif not isClan(d):
                    skip.append(d)

            for s in skip:
                dirs.remove(s)

        self.treeFrozen = True

        # 2nd pass try to resolve marriage VRs
        for p in self.people.values():
            if p.fake:
                continue
            p.crossSearchMarriageVrs()
Пример #7
0
    def children(self):
        if self.fake: return []

        withBD = []
        withoutBD = []

        for f in os.listdir(self.path):
            p = os.path.join(self.path, f)
            if os.path.isdir(p) and isPerson(f):
                c = self.peopleFact.getPerson(p)
                if c.isPrivate():
                    continue
                bd = c.getBirthDate()
                if bd is None:
                    withoutBD.append(c)
                else:
                    withBD.append((c, bd.date))

        withBD.sort(key=lambda c: c[1])
        children = [c[0] for c in withBD]
        children.extend(withoutBD)
        return children