forked from OpenFAST/python-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_formats.py
More file actions
31 lines (26 loc) · 997 Bytes
/
file_formats.py
File metadata and controls
31 lines (26 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from .file import WrongFormatError
def isRightFormat(fileformat, filename, **kwargs):
""" Tries to open a file, return true and the file if it succeeds """
#raise NotImplementedError("Method must be implemented in the subclass")
try:
F=fileformat.constructor(filename=filename, **kwargs)
return True,F
except MemoryError:
raise
except WrongFormatError:
return False,None
except:
# We Raise the Exception.
# It's the responsability of all the file classes to Return a WrongFormatError
raise
class FileFormat():
def __init__(self,fileclass=None):
self.constructor = fileclass
if fileclass is None:
self.extensions = []
self.name = ''
else:
self.extensions = fileclass.defaultExtensions()
self.name = fileclass.formatName()
def __repr__(self):
return 'FileFormat object: {} ({})'.format(self.name,self.extensions[0])