remove full path from `constants` and fix directory resolution
parent
63c22aba99
commit
f1490a98c8
|
@ -211,16 +211,20 @@ class MemorySink(DataSink):
|
|||
else:
|
||||
bundle = v20.Bundle(all_objs, allow_custom=self.allow_custom)
|
||||
|
||||
if path.endswith(".json"):
|
||||
if not os.path.exists(os.path.dirname(path)):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
else:
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
# if the user only provided a directory, use the bundle id for filename
|
||||
if os.path.isdir(path):
|
||||
path = os.path.join(path, bundle["id"] + ".json")
|
||||
|
||||
with io.open(path, "w", encoding=encoding) as f:
|
||||
bundle = bundle.serialize(pretty=True, encoding=encoding, ensure_ascii=False)
|
||||
f.write(bundle)
|
||||
|
||||
return path
|
||||
save_to_file.__doc__ = MemoryStore.save_to_file.__doc__
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from stix2.datastore import (
|
|||
CompositeDataSource, DataSink, DataSource, DataStoreMixin,
|
||||
)
|
||||
from stix2.datastore.filters import Filter
|
||||
from stix2.test.v20.constants import CAMPAIGN_MORE_KWARGS
|
||||
from .constants import CAMPAIGN_MORE_KWARGS
|
||||
|
||||
|
||||
def test_datasource_abstract_class_raises_error():
|
||||
|
|
|
@ -5,7 +5,7 @@ import shutil
|
|||
import pytest
|
||||
|
||||
import stix2
|
||||
from stix2.test.v20.constants import (
|
||||
from .constants import (
|
||||
CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID,
|
||||
INDICATOR_KWARGS, MALWARE_ID, MALWARE_KWARGS, RELATIONSHIP_IDS,
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ from stix2.datastore import (
|
|||
CompositeDataSource, DataSink, DataSource, DataStoreMixin,
|
||||
)
|
||||
from stix2.datastore.filters import Filter
|
||||
from stix2.test.v21.constants import CAMPAIGN_MORE_KWARGS
|
||||
from .constants import CAMPAIGN_MORE_KWARGS
|
||||
|
||||
|
||||
def test_datasource_abstract_class_raises_error():
|
||||
|
|
|
@ -5,7 +5,7 @@ import shutil
|
|||
import pytest
|
||||
|
||||
import stix2
|
||||
from stix2.test.v21.constants import (
|
||||
from .constants import (
|
||||
CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID,
|
||||
INDICATOR_KWARGS, MALWARE_ID, MALWARE_KWARGS, RELATIONSHIP_IDS,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue