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@1881: from __future__ import absolute_import andrej@1732: import os andrej@1732: import sys andrej@2434: from builtins import str as text andrej@1680: andrej@1736: andrej@1680: def AbsFile(file): andrej@1680: if isinstance(file, str): andrej@2434: file = text(file, sys.getfilesystemencoding()) andrej@1680: return file andrej@1680: andrej@1736: andrej@1680: def AbsDir(file): andrej@1680: file = AbsFile(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