#!/usr/bin/env python3
# -*-python-*-

import sys
import os
import string

# extend the search path
fsdp = os.popen('dueca-config --path-datafiles')
sys.path.append(fsdp.readline().strip())
fsdp.close()

from modules import *
from commobjects import *

# try to find the application name
abspath = os.path.abspath('.').split(os.sep)
if len(abspath) < 3:
    sys.stderr.write('Cannot find application directory')
    sys.exit(1)

appname = abspath[-3]

# expected location of the application directory
appdir = '..' + os.sep + '..' + os.sep + appname

if not os.path.exists(appdir):
    sys.stderr.write('Cannot find application directory')
    sys.exit(1)

# create a CommObjectsList object, this will answer all our queries
t = TempCd('..' + os.sep + '..' + os.sep + appname)

ml = ModulesList()
cl = CommObjectsList(ml, appname)
t.goBack()

print(cl.allFromProject(abspath[-2]))
