Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing 5.5.1 tags and some of the common program defined ones. #49

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,92 @@ venv.bak/

# mypy
.mypy_cache/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.16.1
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Python Gedcom Parser: Contribution Guideline

1. Clone the repo
1. Make your changes
1. (Write appropriate tests within `tests/`)
1. Commit using [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
1. [Open a pull request](https://github.com/madprime/python-gedcom/compare)
1. When checks for the PR fail consider making changes so that the checks pass

## About Conventional Commits

Git committing is done using [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) with NPM.

Consider installing node packages with [NVM](https://github.com/nvm-sh/nvm) and start committing with `npm run commit`.
Git hooks installed via [Husky](https://github.com/typicode/husky) will do the rest.

How to install:

1. Use Node version `12.16.1` (or use [NVM](https://github.com/nvm-sh/nvm) and run `nvm use`)
1. Run `npm install` and then `npm run commit` to commit your changes
8 changes: 6 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ exclude logo.png
exclude docs
recursive-exclude docs *
recursive-exclude gedcom *.md
recursive-exclude tests *

# Include GEDCOM test files
include tests/files/*.ged
# Exclude Node related files
exclude .nvmrc
exclude commitlint.config.js
exclude package.json
exclude package-lock.json
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
};
92 changes: 72 additions & 20 deletions docs/gedcom/parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>
for family_member in family.get_child_elements():

if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
and family_member.get_value() == individual.get_pointer():
and family_member.get_value() == individual.get_pointer():

for child in family_member.get_child_elements():
if child.get_value() == &#34;Natural&#34;:
Expand Down Expand Up @@ -546,19 +546,32 @@ <h1 class="title">Module <code>gedcom.parser</code></h1>

# Other methods

def to_gedcom_string(self, recursive=False):
&#34;&#34;&#34;Formats all elements and optionally all of the sub-elements into a GEDCOM string
:type recursive: bool
&#34;&#34;&#34;
is_gte_python_3 = version_info[0] &gt;= 3
output = &#39;&#39; if is_gte_python_3 else b&#39;&#39;

for element in self.get_root_child_elements():
if is_gte_python_3:
output += element.to_gedcom_string(recursive)
else:
output += element.to_gedcom_string(recursive).encode(&#39;utf-8-sig&#39;)

return output

def print_gedcom(self):
&#34;&#34;&#34;Write GEDCOM data to stdout&#34;&#34;&#34;
from sys import stdout
self.save_gedcom(stdout)

def save_gedcom(self, open_file):
def save_gedcom(self, open_file, recursive=True):
&#34;&#34;&#34;Save GEDCOM data to a file
:type open_file: file
:type recursive: bool
&#34;&#34;&#34;
if version_info[0] &gt;= 3:
open_file.write(self.get_root_element().to_gedcom_string(True))
else:
open_file.write(self.get_root_element().to_gedcom_string(True).encode(&#39;utf-8-sig&#39;))</code></pre>
open_file.write(self.to_gedcom_string(recursive))</code></pre>
</details>
</section>
<section>
Expand Down Expand Up @@ -989,7 +1002,7 @@ <h3>Ancestors</h3>
for family_member in family.get_child_elements():

if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
and family_member.get_value() == individual.get_pointer():
and family_member.get_value() == individual.get_pointer():

for child in family_member.get_child_elements():
if child.get_value() == &#34;Natural&#34;:
Expand Down Expand Up @@ -1071,19 +1084,32 @@ <h3>Ancestors</h3>

# Other methods

def to_gedcom_string(self, recursive=False):
&#34;&#34;&#34;Formats all elements and optionally all of the sub-elements into a GEDCOM string
:type recursive: bool
&#34;&#34;&#34;
is_gte_python_3 = version_info[0] &gt;= 3
output = &#39;&#39; if is_gte_python_3 else b&#39;&#39;

for element in self.get_root_child_elements():
if is_gte_python_3:
output += element.to_gedcom_string(recursive)
else:
output += element.to_gedcom_string(recursive).encode(&#39;utf-8-sig&#39;)

return output

def print_gedcom(self):
&#34;&#34;&#34;Write GEDCOM data to stdout&#34;&#34;&#34;
from sys import stdout
self.save_gedcom(stdout)

def save_gedcom(self, open_file):
def save_gedcom(self, open_file, recursive=True):
&#34;&#34;&#34;Save GEDCOM data to a file
:type open_file: file
:type recursive: bool
&#34;&#34;&#34;
if version_info[0] &gt;= 3:
open_file.write(self.get_root_element().to_gedcom_string(True))
else:
open_file.write(self.get_root_element().to_gedcom_string(True).encode(&#39;utf-8-sig&#39;))</code></pre>
open_file.write(self.to_gedcom_string(recursive))</code></pre>
</details>
<h3>Methods</h3>
<dl>
Expand Down Expand Up @@ -1450,7 +1476,7 @@ <h3>Methods</h3>
for family_member in family.get_child_elements():

if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
and family_member.get_value() == individual.get_pointer():
and family_member.get_value() == individual.get_pointer():

for child in family_member.get_child_elements():
if child.get_value() == &#34;Natural&#34;:
Expand Down Expand Up @@ -1649,23 +1675,48 @@ <h3>Methods</h3>
</details>
</dd>
<dt id="gedcom.parser.Parser.save_gedcom"><code class="name flex">
<span>def <span class="ident">save_gedcom</span></span>(<span>self, open_file)</span>
<span>def <span class="ident">save_gedcom</span></span>(<span>self, open_file, recursive=True)</span>
</code></dt>
<dd>
<section class="desc"><p>Save GEDCOM data to a file
:type open_file: file</p></section>
:type open_file: file
:type recursive: bool</p></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def save_gedcom(self, open_file):
<pre><code class="python">def save_gedcom(self, open_file, recursive=True):
&#34;&#34;&#34;Save GEDCOM data to a file
:type open_file: file
:type recursive: bool
&#34;&#34;&#34;
if version_info[0] &gt;= 3:
open_file.write(self.get_root_element().to_gedcom_string(True))
else:
open_file.write(self.get_root_element().to_gedcom_string(True).encode(&#39;utf-8-sig&#39;))</code></pre>
open_file.write(self.to_gedcom_string(recursive))</code></pre>
</details>
</dd>
<dt id="gedcom.parser.Parser.to_gedcom_string"><code class="name flex">
<span>def <span class="ident">to_gedcom_string</span></span>(<span>self, recursive=False)</span>
</code></dt>
<dd>
<section class="desc"><p>Formats all elements and optionally all of the sub-elements into a GEDCOM string
:type recursive: bool</p></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def to_gedcom_string(self, recursive=False):
&#34;&#34;&#34;Formats all elements and optionally all of the sub-elements into a GEDCOM string
:type recursive: bool
&#34;&#34;&#34;
is_gte_python_3 = version_info[0] &gt;= 3
output = &#39;&#39; if is_gte_python_3 else b&#39;&#39;

for element in self.get_root_child_elements():
if is_gte_python_3:
output += element.to_gedcom_string(recursive)
else:
output += element.to_gedcom_string(recursive).encode(&#39;utf-8-sig&#39;)

return output</code></pre>
</details>
</dd>
</dl>
Expand Down Expand Up @@ -1710,6 +1761,7 @@ <h4><code><a title="gedcom.parser.Parser" href="#gedcom.parser.Parser">Parser</a
<li><code><a title="gedcom.parser.Parser.parse_file" href="#gedcom.parser.Parser.parse_file">parse_file</a></code></li>
<li><code><a title="gedcom.parser.Parser.print_gedcom" href="#gedcom.parser.Parser.print_gedcom">print_gedcom</a></code></li>
<li><code><a title="gedcom.parser.Parser.save_gedcom" href="#gedcom.parser.Parser.save_gedcom">save_gedcom</a></code></li>
<li><code><a title="gedcom.parser.Parser.to_gedcom_string" href="#gedcom.parser.Parser.to_gedcom_string">to_gedcom_string</a></code></li>
</ul>
</li>
</ul>
Expand Down
25 changes: 19 additions & 6 deletions gedcom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def get_parents(self, individual, parent_type="ALL"):
for family_member in family.get_child_elements():

if family_member.get_tag() == gedcom.tags.GEDCOM_TAG_CHILD \
and family_member.get_value() == individual.get_pointer():
and family_member.get_value() == individual.get_pointer():

for child in family_member.get_child_elements():
if child.get_value() == "Natural":
Expand Down Expand Up @@ -517,16 +517,29 @@ def get_family_members(self, family, members_type=FAMILY_MEMBERS_TYPE_ALL):

# Other methods

def to_gedcom_string(self, recursive=False):
"""Formats all elements and optionally all of the sub-elements into a GEDCOM string
:type recursive: bool
"""
is_gte_python_3 = version_info[0] >= 3
output = '' if is_gte_python_3 else b''

for element in self.get_root_child_elements():
if is_gte_python_3:
output += element.to_gedcom_string(recursive)
else:
output += element.to_gedcom_string(recursive).encode('utf-8-sig')

return output

def print_gedcom(self):
"""Write GEDCOM data to stdout"""
from sys import stdout
self.save_gedcom(stdout)

def save_gedcom(self, open_file):
def save_gedcom(self, open_file, recursive=True):
"""Save GEDCOM data to a file
:type open_file: file
:type recursive: bool
"""
if version_info[0] >= 3:
open_file.write(self.get_root_element().to_gedcom_string(True))
else:
open_file.write(self.get_root_element().to_gedcom_string(True).encode('utf-8-sig'))
open_file.write(self.to_gedcom_string(recursive))
Loading