# -*- coding: utf-8 -*-
from .CpyLib import brukerPAR
__all__ = ['TSpy', 'brukerPAR', 'fullpath', 'get_cpython_path', 'CpyBin_path_to' ]

# special treatment for topspin<3
def fullpath(dataset):
    """
    return absolute path to dataset
    dataset is an array as returned by CURDATA()
    """
    dat = dataset[:] # make a copy because I don't want to modify the original array
    if len(dat) ==5: # for topspin 2-
            dat[3] = "%s/data/%s/nmr" % (dat[3], dat[4])
    fulldata = "%s/%s/%s/pdata/%s/" % (dat[3], dat[0], dat[1], dat[2])
    return fulldata

def get_cpython_path():
    """ Return absolute path to external C python interpreter 
    as read from CPYTHON environment variable
    """
    from  os import getenv
    CPYTHON = getenv('CPYTHON', "NotDefined")
    if CPYTHON == "NotDefined":
        raise ValueError("CPYTHON variable environment not found")
        pass
    return CPYTHON

def CpyBin_path_to(name):
    """
    return absolute path to "name" script found in current module JTutils/CpyBin 
    """
    from os.path import dirname, abspath
    return dirname(abspath(__file__)) + "/CpyBin/" + name

@@ -46,16 +46,17 @@
 rukerPAR
+ 
 %0A__all__
@@ -128,16 +128,37 @@
 path_to'
+, 'CPYTHON', 'CpyBin'
  %5D%0A%0A# sp
@@ -307,24 +307,38 @@
 A()%0A    %22%22%22%0A
+    import os%0A
     dat = da
@@ -428,16 +428,17 @@
 (dat) ==
+ 
 5: # for
@@ -474,82 +474,79 @@
 %5D = 
-%22%25s/data/%25s/nmr%22 %25 (dat%5B3%5D, dat%5B4%5D)%0A    fulldata = %22%25s/%25s/%25s/pdata/%25s/%22 %25 
+os.path.join(dat%5B3%5D, 'data', dat%5B4%5D, 'nmr')%0A    fulldata = os.path.join
 (dat
@@ -565,16 +565,25 @@
  dat%5B1%5D,
+ 'pdata',
  dat%5B2%5D)
@@ -635,16 +635,20 @@
 %0A    %22%22%22
+%0A   
  Return 
@@ -1177,8 +1177,66 @@
  + name%0A
+%0ACPYTHON = get_cpython_path()%0ACpyBin = CpyBin_path_to('')%0A

define and expose utility functions to get cpython and CpyLib variables