Add the possibility to create temporary objects like a temporary
directory and a temporary DMS
This commit is contained in:
@ -8,3 +8,4 @@ from obitools3.dms.taxo.taxo cimport Taxonomy
|
||||
from obitools3.utils cimport tobytes, tostr
|
||||
from obitools3.files.universalopener cimport uopen
|
||||
|
||||
cdef open_dms(bytes path, bint create=?)
|
||||
|
@ -11,11 +11,12 @@ from obitools3.parsers.universal import entryIteratorFactory
|
||||
|
||||
from obitools3.dms.obiseq import Nuc_Seq
|
||||
from obitools3.apps.config import getConfiguration,logger
|
||||
from obitools3.apps.temp import get_temp_dms
|
||||
|
||||
class MalformedURIException(RuntimeError):
|
||||
pass
|
||||
|
||||
cdef open_dms(bytes path,create=False):
|
||||
cdef open_dms(bytes path, bint create=False):
|
||||
"""
|
||||
Opens a DMS from the path part of an URI
|
||||
"""
|
||||
@ -50,13 +51,15 @@ cdef open_dms(bytes path,create=False):
|
||||
pos=pos+1
|
||||
return None
|
||||
|
||||
def open_dms_element(DMS dms, bytes path):
|
||||
def open_dms_element(DMS dms, bytes path,
|
||||
bint create=False,
|
||||
type newviewtype=View):
|
||||
"""
|
||||
"""
|
||||
cdef list path_parts = path.split(b'/')
|
||||
|
||||
|
||||
# The URI is only composed of a DMS
|
||||
if not path_parts:
|
||||
if not path:
|
||||
return (dms,dms)
|
||||
|
||||
# The URI is target a taxonomy
|
||||
@ -74,7 +77,10 @@ def open_dms_element(DMS dms, bytes path):
|
||||
# The URI is target a view
|
||||
# dms:dmspath/viewname[/columnname|#line|*[/#line|columnname|*[/subcolumn]]]
|
||||
|
||||
view = View.open(dms,path_parts[0])
|
||||
if create:
|
||||
view = newviewtype.new(dms,path_parts[0])
|
||||
else:
|
||||
view = newviewtype.open(dms,path_parts[0])
|
||||
|
||||
if len(path_parts) > 1:
|
||||
if path_parts[1]==b'*':
|
||||
@ -128,7 +134,9 @@ def open_dms_element(DMS dms, bytes path):
|
||||
return (dms,subsubpart)
|
||||
|
||||
|
||||
def open_uri(uri,bint input=True):
|
||||
def open_uri(uri,
|
||||
bint input=True,
|
||||
type newviewtype=View):
|
||||
cdef bytes urib = tobytes(uri)
|
||||
cdef bytes scheme
|
||||
cdef tuple dms
|
||||
@ -146,19 +154,27 @@ def open_uri(uri,bint input=True):
|
||||
except KeyError:
|
||||
default_dms=None
|
||||
|
||||
try:
|
||||
create=(not input) and (not config["obi"]["nocreatedms"])
|
||||
except KeyError:
|
||||
create=not input
|
||||
|
||||
scheme = urip.scheme
|
||||
|
||||
error = None
|
||||
|
||||
if scheme==b"" :
|
||||
dms = open_dms(urip.path)
|
||||
if scheme==b"" or scheme==b"dms" :
|
||||
dms = open_dms(urip.path,create)
|
||||
if dms is None and default_dms is not None:
|
||||
dms=(default_dms,urip.path)
|
||||
|
||||
|
||||
if dms is not None:
|
||||
try:
|
||||
resource=open_dms_element(*dms)
|
||||
resource=open_dms_element(dms[0],dms[1],
|
||||
create,
|
||||
newviewtype
|
||||
)
|
||||
scheme=b"dms"
|
||||
urip = ParseResultBytes(scheme=b"dms",
|
||||
netloc=urip.netloc,
|
||||
@ -169,17 +185,24 @@ def open_uri(uri,bint input=True):
|
||||
|
||||
if default_dms is None:
|
||||
config["obi"]["defaultdms"]=resource[0]
|
||||
|
||||
return (resource[0],resource[1],urlunparse(urip))
|
||||
|
||||
return (resource[0],
|
||||
resource[1],
|
||||
type(resource[1]),
|
||||
urlunparse(urip))
|
||||
except Exception as e:
|
||||
error=e
|
||||
|
||||
if scheme==b"dms" :
|
||||
logger('error','cannot open DMS: %s', uri)
|
||||
raise FileNotFoundError('uri')
|
||||
|
||||
if not urip.scheme:
|
||||
urib=b"file:"+urib
|
||||
|
||||
try:
|
||||
logger('info','Trying to open file : %s', tostr(urib))
|
||||
file = uopen(tostr(urib))
|
||||
logger('info','Opened file : %s', tostr(urib))
|
||||
except Exception as e:
|
||||
file = None
|
||||
error=e
|
||||
@ -366,7 +389,10 @@ def open_uri(uri,bint input=True):
|
||||
blanklineskip,
|
||||
commentchar)
|
||||
|
||||
return (file,iseq,objclass)
|
||||
|
||||
tmpdms = get_temp_dms()
|
||||
|
||||
return (file,iseq,objclass,urib)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user