andrej@1680: #!/usr/bin/env python
andrej@1680: # -*- coding: utf-8 -*-
andrej@1680: 
andrej@1680: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1680: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
andrej@1680: #
andrej@1680: # Copyright (C) 2017: Andrey Skvortsov
andrej@1680: #
andrej@1680: # See COPYING file for copyrights details.
andrej@1680: #
andrej@1680: # This program is free software; you can redistribute it and/or
andrej@1680: # modify it under the terms of the GNU General Public License
andrej@1680: # as published by the Free Software Foundation; either version 2
andrej@1680: # of the License, or (at your option) any later version.
andrej@1680: #
andrej@1680: # This program is distributed in the hope that it will be useful,
andrej@1680: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1680: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1680: # GNU General Public License for more details.
andrej@1680: #
andrej@1680: # You should have received a copy of the GNU General Public License
andrej@1680: # along with this program; if not, write to the Free Software
andrej@1680: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
andrej@1680: 
andrej@1881: 
andrej@1732: import os
andrej@1732: import sys
andrej@1680: 
andrej@1680: def AbsFile(file):
andrej@1680:     if isinstance(file, str):
kinsamanka@3752:         file = str(file, sys.getfilesystemencoding())
andrej@1680:     return file
andrej@1680: 
andrej@1736: 
andrej@1680: def AbsDir(file):
andrej@1680:     return os.path.dirname(os.path.realpath(file))
andrej@1680: 
andrej@1736: 
andrej@1680: def AbsNeighbourFile(file, *args):
andrej@1680:     return os.path.join(AbsDir(file), *args)
andrej@1680: 
andrej@1680: 
andrej@1744: def AbsParentDir(file, level=1):
andrej@1680:     path = AbsDir(file)
andrej@1847:     for dummy in range(0, level):
andrej@1680:         path = os.path.dirname(path)
andrej@1680:     return path
Edouard@2736: 
Edouard@2736: def ThirdPartyPath(name):
Edouard@2736:     """
Edouard@2736:     Return folder where to find sibling projects like Modbus, CanFestival, BACnet
Edouard@2736:     """
Edouard@2736:     return os.path.join(AbsParentDir(__file__, 2), name)
Edouard@2736: 
edouard@3502: def Bpath(*names):
edouard@3501:     """
edouard@3501:     Return path of files in Beremiz project
edouard@3501:     """
edouard@3502:     return os.path.join(AbsParentDir(__file__, 1), *names)