Skip to content

Commit

Permalink
There are new files in the OCF Zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Regebro committed Feb 4, 2025
1 parent 159886e commit 456d513
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
35 changes: 24 additions & 11 deletions src/pyocf/captable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pathlib
import zipfile

from pyocf.files import documentsfile
from pyocf.files import financingsfile
from pyocf.files import ocfmanifestfile
from pyocf.files import stakeholdersfile
from pyocf.files import stockclassesfile
Expand All @@ -16,6 +18,8 @@
from pyocf.files import transactionsfile
from pyocf.files import valuationsfile
from pyocf.files import vestingtermsfile
from pyocf.objects.document import Document
from pyocf.objects.financing import Financing
from pyocf.objects.stakeholder import Stakeholder
from pyocf.objects.stockclass import StockClass
from pyocf.objects.stocklegendtemplate import StockLegendTemplate
Expand All @@ -26,25 +30,29 @@
from pyocf.types import file

FILEMAP = [
("stock_plans", stockplansfile.StockPlansFile),
("stock_legend_templates", stocklegendtemplatesfile.StockLegendTemplatesFile),
("documents", documentsfile.DocumentsFile),
("financings", financingsfile.FinancingsFile),
("stakeholders", stakeholdersfile.StakeholdersFile),
("stock_classes", stockclassesfile.StockClassesFile),
("vesting_terms", vestingtermsfile.VestingTermsFile),
("valuations", valuationsfile.ValuationsFile),
("stock_legend_templates", stocklegendtemplatesfile.StockLegendTemplatesFile),
("stock_plans", stockplansfile.StockPlansFile),
("transactions", transactionsfile.TransactionsFile),
("stakeholders", stakeholdersfile.StakeholdersFile),
("valuations", valuationsfile.ValuationsFile),
("vesting_terms", vestingtermsfile.VestingTermsFile),
]


class Captable:
manifest: ocfmanifestfile.OCFManifestFile = None
stock_plans: list[StockPlan] = []
stock_legend_templates: list[StockLegendTemplate] = []
documents: list[Document] = []
financings: list[Financing] = []
stakeholders: list[Stakeholder] = []
stock_classes: list[StockClass] = []
vesting_terms: list[VestingTerms] = []
valuations: list[Valuation] = []
stock_legend_templates: list[StockLegendTemplate] = []
stock_plans: list[StockPlan] = []
transactions: list[Transaction] = []
stakeholders: list[Stakeholder] = []
valuations: list[Valuation] = []
vesting_terms: list[VestingTerms] = []

@classmethod
def load(cls, location):
Expand Down Expand Up @@ -82,7 +90,10 @@ def file_factory(p):
return open(pathlib.Path(basedir, p))

for filetype, filecls in FILEMAP:
for fileob in getattr(captable.manifest, filetype + "_files"):
fileobjs = getattr(captable.manifest, filetype + "_files")
if fileobjs is None:
continue
for fileob in fileobjs:
infile = file_factory(fileob.filepath)
items = filecls(**json.load(infile)).items
getattr(captable, filetype).extend(items)
Expand All @@ -104,6 +115,8 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
if self.manifest:
# Check if there is a different filename in the manifest:
ocffilename = getattr(self.manifest, filetype + "_files", [])
if ocffilename is None:
continue
if len(ocffilename) >= 1:
ocffilename = ocffilename[0].filepath

Expand Down
Binary file modified tests/samples/Captable.ocf.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def test_save_zip():

captable.save(outpath, pretty=True)
with zipfile.ZipFile(outpath) as zipped:
assert len(zipped.filelist) == 8
assert len(zipped.filelist) == 9
# Make sure the manifest file is in there
assert zipped.filelist[7].filename == "Manifest.ocf.json"
assert zipped.filelist[-1].filename == "Manifest.ocf.json"

manifest = zipped.open("Manifest.ocf.json")
data = manifest.read()
Expand All @@ -49,7 +49,7 @@ def test_save_directory():

path = Path(outdir)
files = [x for x in path.iterdir()]
assert len(files) == 8
assert len(files) == 9
# Make sure the manifest file is in there
manifest = [x for x in files if x.name == "Manifest.ocf.json"][0]
data = manifest.open("rb").read()
Expand Down

0 comments on commit 456d513

Please sign in to comment.