From: BenoƮt Fontaine Date: Mon, 24 Feb 2020 06:31:01 +0000 (+0100) Subject: Writes a partial gedcom file if an exception occur. X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=9af5e19372ab9c31ecdb138b31e0f36d28162f8b;p=gamesguru%2Fgetmyancestors.git Writes a partial gedcom file if an exception occur. --- diff --git a/getmyancestors.py b/getmyancestors.py index dbba201..f3dd737 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -1214,83 +1214,85 @@ def main(): if test["status"] != "OK": sys.exit(2) - # add list of starting individuals to the family tree - todo = args.individuals if args.individuals else [fs.fid] - print(_("Downloading starting individuals...")) - tree.add_indis(todo) - - # download ancestors - todo = set(todo) - done = set() - for i in range(args.ascend): - if not todo: - break - done |= todo - print(_("Downloading %s. of generations of ancestors...") % (i + 1)) - todo = tree.add_parents(todo) - done - - # download descendants - todo = set(tree.indi.keys()) - done = set() - for i in range(args.descend): - if not todo: - break - done |= todo - print(_("Downloading %s. of generations of descendants...") % (i + 1)) - todo = tree.add_children(todo) - done - - # download spouses - if args.marriage: - print(_("Downloading spouses and marriage information...")) + try: + # add list of starting individuals to the family tree + todo = args.individuals if args.individuals else [fs.fid] + print(_("Downloading starting individuals...")) + tree.add_indis(todo) + + # download ancestors + todo = set(todo) + done = set() + for i in range(args.ascend): + if not todo: + break + done |= todo + print(_("Downloading %s. of generations of ancestors...") % (i + 1)) + todo = tree.add_parents(todo) - done + + # download descendants todo = set(tree.indi.keys()) - tree.add_spouses(todo) - - # download ordinances, notes and contributors - async def download_stuff(loop): - futures = set() - for fid, indi in tree.indi.items(): - futures.add(loop.run_in_executor(None, indi.get_notes)) - if args.get_ordinances: - futures.add(loop.run_in_executor(None, tree.add_ordinances, fid)) - if args.get_contributors: - futures.add(loop.run_in_executor(None, indi.get_contributors)) - for fam in tree.fam.values(): - futures.add(loop.run_in_executor(None, fam.get_notes)) - if args.get_contributors: - futures.add(loop.run_in_executor(None, fam.get_contributors)) - for future in futures: - await future - - loop = asyncio.get_event_loop() - print( - _("Downloading notes") - + ( - (("," if args.get_contributors else _(" and")) + _(" ordinances")) - if args.get_ordinances - else "" - ) - + (_(" and contributors") if args.get_contributors else "") - + "..." - ) - loop.run_until_complete(download_stuff(loop)) - - # compute number for family relationships and print GEDCOM file - tree.reset_num() - tree.print(args.outfile) - print( - _( - "Downloaded %s individuals, %s families, %s sources and %s notes " - "in %s seconds with %s HTTP requests." + done = set() + for i in range(args.descend): + if not todo: + break + done |= todo + print(_("Downloading %s. of generations of descendants...") % (i + 1)) + todo = tree.add_children(todo) - done + + # download spouses + if args.marriage: + print(_("Downloading spouses and marriage information...")) + todo = set(tree.indi.keys()) + tree.add_spouses(todo) + + # download ordinances, notes and contributors + async def download_stuff(loop): + futures = set() + for fid, indi in tree.indi.items(): + futures.add(loop.run_in_executor(None, indi.get_notes)) + if args.get_ordinances: + futures.add(loop.run_in_executor(None, tree.add_ordinances, fid)) + if args.get_contributors: + futures.add(loop.run_in_executor(None, indi.get_contributors)) + for fam in tree.fam.values(): + futures.add(loop.run_in_executor(None, fam.get_notes)) + if args.get_contributors: + futures.add(loop.run_in_executor(None, fam.get_contributors)) + for future in futures: + await future + + loop = asyncio.get_event_loop() + print( + _("Downloading notes") + + ( + (("," if args.get_contributors else _(" and")) + _(" ordinances")) + if args.get_ordinances + else "" + ) + + (_(" and contributors") if args.get_contributors else "") + + "..." ) - % ( - str(len(tree.indi)), - str(len(tree.fam)), - str(len(tree.sources)), - str(len(tree.notes)), - str(round(time.time() - time_count)), - str(fs.counter), + loop.run_until_complete(download_stuff(loop)) + + finally: + # compute number for family relationships and print GEDCOM file + tree.reset_num() + tree.print(args.outfile) + print( + _( + "Downloaded %s individuals, %s families, %s sources and %s notes " + "in %s seconds with %s HTTP requests." + ) + % ( + str(len(tree.indi)), + str(len(tree.fam)), + str(len(tree.sources)), + str(len(tree.notes)), + str(round(time.time() - time_count)), + str(fs.counter), + ) ) - ) if __name__ == "__main__":