Skip to content

Commit 76e3847

Browse files
committed
[odml] Refactor attribute id to oid
Closes #268
1 parent 10466d4 commit 76e3847

File tree

5 files changed

+60
-29
lines changed

5 files changed

+60
-29
lines changed

odml/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __eq__(self, obj):
2929
return False
3030

3131
for key in self._format:
32-
if key == "id":
32+
if key == "id" or key == "oid":
3333
continue
3434
elif getattr(self, key) != getattr(obj, key):
3535
return False

odml/doc.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class BaseDocument(base.Sectionable):
1919

2020
_format = format.Document
2121

22-
def __init__(self, author=None, date=None, version=None, repository=None, id=None):
22+
def __init__(self, author=None, date=None, version=None, repository=None, oid=None):
2323
super(BaseDocument, self).__init__()
2424
try:
25-
if id is not None:
26-
self._id = str(uuid.UUID(id))
25+
if oid is not None:
26+
self._id = str(uuid.UUID(oid))
2727
else:
2828
self._id = str(uuid.uuid4())
2929
except ValueError as e:
@@ -41,22 +41,30 @@ def __repr__(self):
4141
return "<Doc %s by %s (%d sections)>" % (self._version, self._author,
4242
len(self._sections))
4343

44+
@property
45+
def oid(self):
46+
"""
47+
The uuid for the document. Required for entity creation and comparison,
48+
saving and loading.
49+
"""
50+
return self.id
51+
4452
@property
4553
def id(self):
4654
"""
4755
The uuid for the document.
4856
"""
4957
return self._id
5058

51-
def new_id(self, id=None):
59+
def new_id(self, oid=None):
5260
"""
5361
new_id sets the id of the current object to a RFC 4122 compliant UUID.
5462
If an id was provided, it is assigned if it is RFC 4122 UUID format compliant.
5563
If no id was provided, a new UUID is generated and assigned.
56-
:param id: UUID string as specified in RFC 4122.
64+
:param oid: UUID string as specified in RFC 4122.
5765
"""
58-
if id is not None:
59-
self._id = str(uuid.UUID(id))
66+
if oid is not None:
67+
self._id = str(uuid.UUID(oid))
6068
else:
6169
self._id = str(uuid.uuid4())
6270

odml/format.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class Property(Format):
108108
}
109109
_map = {
110110
'dependencyvalue': 'dependency_value',
111-
'type': 'dtype'
111+
'type': 'dtype',
112+
'id': 'oid'
112113
}
113114
_rdf_map = {
114115
'id': _ns.hasId,
@@ -142,6 +143,7 @@ class Section(Format):
142143
_map = {
143144
'section': 'sections',
144145
'property': 'properties',
146+
'id': 'oid'
145147
}
146148
_rdf_map = {
147149
'id': _ns.hasId,
@@ -168,7 +170,8 @@ class Document(Format):
168170
'repository': 0,
169171
}
170172
_map = {
171-
'section': 'sections'
173+
'section': 'sections',
174+
'id': 'oid'
172175
}
173176
_rdf_map = {
174177
'id': _ns.hasId,

odml/property.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BaseProperty(base.BaseObject):
1616
def __init__(self, name=None, value=None, parent=None, unit=None,
1717
uncertainty=None, reference=None, definition=None,
1818
dependency=None, dependency_value=None, dtype=None,
19-
value_origin=None, id=None):
19+
value_origin=None, oid=None):
2020
"""
2121
Create a new Property. If a value without an explicitly stated dtype
2222
has been provided, the method will try to infer the value's dtype.
@@ -45,13 +45,13 @@ def __init__(self, name=None, value=None, parent=None, unit=None,
4545
if dtype is not given, the type is deduced from the values.
4646
Check odml.DType for supported data types.
4747
:param value_origin: Reference where the value originated from e.g. a file name.
48-
:param id: UUID string as specified in RFC 4122. If no id is provided,
48+
:param oid: object id, UUID string as specified in RFC 4122. If no id is provided,
4949
an id will be generated and assigned. An id has to be unique
5050
within an odML Document.
5151
"""
5252
try:
53-
if id is not None:
54-
self._id = str(uuid.UUID(id))
53+
if oid is not None:
54+
self._id = str(uuid.UUID(oid))
5555
else:
5656
self._id = str(uuid.uuid4())
5757
except ValueError as e:
@@ -101,19 +101,30 @@ def __setitem__(self, key, item):
101101
raise ValueError("odml.Property.__setitem__: passed value cannot be "
102102
"converted to data type \'%s\'!" % self._dtype)
103103

104+
@property
105+
def oid(self):
106+
"""
107+
The uuid for the property. Required for entity creation and comparison,
108+
saving and loading.
109+
"""
110+
return self.id
111+
104112
@property
105113
def id(self):
114+
"""
115+
The uuid for the property.
116+
"""
106117
return self._id
107118

108-
def new_id(self, id=None):
119+
def new_id(self, oid=None):
109120
"""
110-
new_id sets the id of the current object to an RFC 4122 compliant UUID.
121+
new_id sets the object id of the current object to an RFC 4122 compliant UUID.
111122
If an id was provided, it is assigned if it is RFC 4122 UUID format compliant.
112123
If no id was provided, a new UUID is generated and assigned.
113-
:param id: UUID string as specified in RFC 4122.
124+
:param oid: UUID string as specified in RFC 4122.
114125
"""
115-
if id is not None:
116-
self._id = str(uuid.UUID(id))
126+
if oid is not None:
127+
self._id = str(uuid.UUID(oid))
117128
else:
118129
self._id = str(uuid.uuid4())
119130

odml/section.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@
1616
class BaseSection(base.Sectionable):
1717
""" An odML Section """
1818
type = None
19-
# id = None
19+
reference = None # the *import* property
2020
_link = None
2121
_include = None
22-
reference = None # the *import* property
23-
2422
_merged = None
2523

2624
_format = format.Section
2725

2826
def __init__(self, name=None, type=None, parent=None,
2927
definition=None, reference=None,
30-
repository=None, link=None, include=None, id=None):
28+
repository=None, link=None, include=None, oid=None):
3129

3230
# Sets _sections Smartlist and _repository to None, so run first.
3331
super(BaseSection, self).__init__()
3432
self._props = base.SmartList(BaseProperty)
3533

3634
try:
37-
if id is not None:
38-
self._id = str(uuid.UUID(id))
35+
if oid is not None:
36+
self._id = str(uuid.UUID(oid))
3937
else:
4038
self._id = str(uuid.uuid4())
4139
except ValueError as e:
@@ -76,19 +74,30 @@ def __len__(self):
7674
"""
7775
return len(self._sections) + len(self._props)
7876

77+
@property
78+
def oid(self):
79+
"""
80+
The uuid for the section. Required for entity creation and comparison,
81+
saving and loading.
82+
"""
83+
return self.id
84+
7985
@property
8086
def id(self):
87+
"""
88+
The uuid for the section.
89+
"""
8190
return self._id
8291

83-
def new_id(self, id=None):
92+
def new_id(self, oid=None):
8493
"""
8594
new_id sets the id of the current object to a RFC 4122 compliant UUID.
8695
If an id was provided, it is assigned if it is RFC 4122 UUID format compliant.
8796
If no id was provided, a new UUID is generated and assigned.
88-
:param id: UUID string as specified in RFC 4122.
97+
:param oid: UUID string as specified in RFC 4122.
8998
"""
90-
if id is not None:
91-
self._id = str(uuid.UUID(id))
99+
if oid is not None:
100+
self._id = str(uuid.UUID(oid))
92101
else:
93102
self._id = str(uuid.uuid4())
94103

0 commit comments

Comments
 (0)