# Path: skema/utils.py
# def log_api(line):
#     log_line ()
#     logging.info("")
#     log_line ()
#     logging.info("")
#     l = "[" + line  +"]"
#     logging.info(l)
#     lansi = "[skema] " + bcolors.BOLD + l + bcolors.ENDC
#     printit (lansi)
# 
# Path: skema/utils.py
# def log_result(tag, err):
#     log_line ()
#     if (err == "OMX_ErrorNone"):
#         l = "[" + tag + " -> '" + err + "']"
#         lansi = "[skema] " + bcolors.OKGREEN + l + bcolors.ENDC
#         logging.info(l)
#     else:
#         l = "[" + tag + " -> '" + err + "']"
#         lansi = "[skema] " + bcolors.FAIL + l + bcolors.ENDC
#         logging.error(l)
# 
#     printit (lansi)


import os
import re
import pwd
import skema.tag
from skema.utils import log_api
from skema.utils import log_result
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.




class tag_OMX_BaseProfilePort(skema.tag.SkemaTag):
    """

    """
    def run(self, element, context):
        alias        = element.get('alias')
        name         = context.cnames[alias]
        portstr      = element.get('port')
        allocatorstr = element.get('allocator')
        modestr      = element.get('mode')
        uristr       = element.get('uri')

        # Replace '$USER' and '$HOME' strings wih the actual representations
        uristr = re.sub("\$USER", pwd.getpwuid(os.getuid())[0], uristr, 1)
        uristr = re.sub("\$HOME", pwd.getpwuid(os.getuid())[5], uristr, 1)

        log_api ("%s %s:Port-%d' 'Allocator:%s' 'Mode:%s' 'Uri:%s'" \
                     % (element.tag, name, int(portstr),           \
                            allocatorstr, modestr, uristr))

        context.base_profile_mgr.manage_port(alias, portstr, allocatorstr,
                                             modestr, uristr)


# Path: skema/utils.py
# def log_api(line):
#     log_line ()
#     logging.info("")
#     log_line ()
#     logging.info("")
#     l = "[" + line  +"]"
#     logging.info(l)
#     lansi = "[skema] " + bcolors.BOLD + l + bcolors.ENDC
#     printit (lansi)
# 
# Path: skema/utils.py
# def log_result(tag, err):
#     log_line ()
#     if (err == "OMX_ErrorNone"):
#         l = "[" + tag + " -> '" + err + "']"
#         lansi = "[skema] " + bcolors.OKGREEN + l + bcolors.ENDC
#         logging.info(l)
#     else:
#         l = "[" + tag + " -> '" + err + "']"
#         lansi = "[skema] " + bcolors.FAIL + l + bcolors.ENDC
#         logging.error(l)
# 
#     printit (lansi)


# Path: skema/tags/OMX_BaseProfilePort.py
import os
import re
import pwd
import skema.tag
from skema.utils import log_api
from skema.utils import log_result

#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.




class tag_OMX_BaseProfilePort(skema.tag.SkemaTag):
    """

    """
    def run(self, element, context):
        alias        = element.get('alias')
        name         = context.cnames[alias]
        portstr      = element.get('port')
        allocatorstr = element.get('allocator')
        modestr      = element.get('mode')
        uristr       = element.get('uri')

        # Replace '$USER' and '$HOME' strings wih the actual representations
        uristr = re.sub("\$USER", pwd.getpwuid(os.getuid())[0], uristr, 1)
        uristr = re.sub("\$HOME", pwd.getpwuid(os.getuid())[5], uristr, 1)

        log_api ("%s %s:Port-%d' 'Allocator:%s' 'Mode:%s' 'Uri:%s'" \
                     % (element.tag, name, int(portstr),           \
                            allocatorstr, modestr, uristr))

        context.base_profile_mgr.manage_port(alias, portstr, allocatorstr,
                                             modestr, uristr)


        log_result (element.tag, "OMX_ErrorNone")