forked from IncapableFury/Final_Project_SW555
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
108 lines (98 loc) · 3.08 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from models.Gedcom import Gedcom
import click
SUPPORT_TAGS = {"INDI", "NAME", "SEX", "BIRT", "DEAT", "FAMC", "FAMS", "FAM", "MARR", "HUSB", "WIFE", "CHIL",
"DIV", "DATE", "HEAD", "TRLR", "NOTE"}
# class Main:
# def __init__(self):
# self.cache = dict()
#
# def add_file_to_cache(self, filename, gedcom) -> bool:
# self.cache[filename] = gedcom
#
# def peek_file(self, filename):
# try:
# self.cache[filename].peek()
# except KeyError:
# print("File not found.")
# else:
# print("File read successfully.")
# return
#
# def parse(self, gedcom):
# gedcom.parse()
#
# def pretty_print(self, data, mode):
# pass
#
# def validate(self, gedcom): # just a demo
# errors = [] # str
# tests_for_family = [
# Family.siblings_spacing,
# Family.multiple_births_lessOrEqual_than_5,
# Family.marriage_before_death,
# Family.birth_before_death_of_parents,
# Family.marriage_before_divorce,
# Family.marriage_after_14,
# Family.divorce_before_death,
# Family.birth_before_marriage_of_parents
# ]
# tests_for_individuals = [
# Individual.dates_before_current_date,
# Individual.birth_before_marriage,
# Individual.birth_before_death,
# Individual.less_then_150_years_old,
# Individual.no_bigamy,
# Individual.parents_not_too_old
# ]
# for fam_id in gedcom.get_families():
# fam = gedcom.get_families()[fam_id]
# for test in tests_for_family:
# try:
# test(fam)
# except Exception as e:
# errors.append(e)
# for indi_id in gedcom.get_individuals():
# indi = gedcom.get_individuals()[indi_id]
# for test in tests_for_individuals:
# try:
# test(indi)
# except Exception as e:
# errors.append((e, "indi"))
# print(len(errors))
# return errors
@click.group()
def cli():
pass
@click.command()
@click.argument('path')
@click.option('--save','-S',is_flag=True)
def parse(path,save):
g = Gedcom(path, SUPPORT_TAGS)
click.echo("parsing...")
g.parse()
g.run_check()
if save:
click.echo("saving to file")
return
@click.command()
@click.argument('path')
def peek(path):
g = Gedcom(path, SUPPORT_TAGS)
click.echo("peeking")
# g.peek()
return
cli.add_command(parse)
cli.add_command(peek)
if __name__ == "__main__":
# project = Main()
# g1 = Gedcom("testing_files/Jiashu_Wang.ged", SUPPORT_TAGS)
# project.add_file_to_cache("g1", g1)
# # project.peek_file("g1")
# project.parse(g1)
# errors = project.validate(g1)
# #project.pretty_print(g1.get_individuals(), g1.get_families(), errors)
# # pretty_print(g1.get_individuals(), g1.get_families(), errors)
#
# print(errors)
# --------------------testing--------------------
cli()