| Total Complexity | 8 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| 1 | from niprov.dependencies import Dependencies |
||
| 5 | class BaseFile(object): |
||
| 6 | |||
| 7 | def __init__(self, location, provenance=None, dependencies=Dependencies()): |
||
| 8 | self.dependencies = dependencies |
||
| 9 | self.listener = dependencies.getListener() |
||
| 10 | self.filesystem = dependencies.getFilesystem() |
||
| 11 | self.hasher = dependencies.getHasher() |
||
| 12 | self.location = dependencies.getLocationFactory().fromString(location) |
||
| 13 | self.formats = dependencies.getFormatFactory() |
||
| 14 | if provenance: |
||
| 15 | self.provenance = provenance |
||
| 16 | else: |
||
| 17 | self.provenance = {} |
||
| 18 | self.provenance.update(self.location.toDictionary()) |
||
| 19 | self.path = self.provenance['path'] |
||
| 20 | |||
| 21 | def inspect(self): |
||
| 22 | self.provenance['size'] = self.filesystem.getsize(self.path) |
||
| 23 | self.provenance['created'] = self.filesystem.getctime(self.path) |
||
| 24 | self.provenance['hash'] = self.hasher.digest(self.path) |
||
| 25 | return self.provenance |
||
| 26 | |||
| 27 | def attach(self, form='json'): |
||
| 28 | """ |
||
| 29 | Not implemented for BaseFile parent class. |
||
| 30 | |||
| 31 | Args: |
||
| 32 | form (str): Data format in which to serialize provenance. Defaults |
||
| 33 | to 'json'. |
||
| 34 | """ |
||
| 35 | pass |
||
| 36 | |||
| 37 | def getProvenance(self, form): |
||
| 38 | return self.formats.create(form).serialize(self) |
||
| 39 | |||
| 40 | def getSeriesId(self): |
||
| 41 | pass |
||
| 42 | |||
| 43 | @property |
||
| 44 | def parents(self): |
||
| 45 | return self.provenance.get('parents', []) |
||
| 46 | |||
| 47 | def compare(self, other): |
||
| 48 | return niprov.comparing.compare(self, other, self.dependencies) |
||
| 49 |