util/paths.py
changeset 1680 6db967480b7d
child 1732 94ffe74e6895
equal deleted inserted replaced
1679:2fcea15858a5 1680:6db967480b7d
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # This file is part of Beremiz, a Integrated Development Environment for
       
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
       
     6 #
       
     7 # Copyright (C) 2017: Andrey Skvortsov
       
     8 #
       
     9 # See COPYING file for copyrights details.
       
    10 #
       
    11 # This program is free software; you can redistribute it and/or
       
    12 # modify it under the terms of the GNU General Public License
       
    13 # as published by the Free Software Foundation; either version 2
       
    14 # of the License, or (at your option) any later version.
       
    15 #
       
    16 # This program is distributed in the hope that it will be useful,
       
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    19 # GNU General Public License for more details.
       
    20 #
       
    21 # You should have received a copy of the GNU General Public License
       
    22 # along with this program; if not, write to the Free Software
       
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
       
    24 
       
    25 import os, sys
       
    26 
       
    27 def AbsFile(file):
       
    28     if isinstance(file, str):
       
    29         file = unicode(file,sys.getfilesystemencoding())
       
    30     return file
       
    31 
       
    32 def AbsDir(file):
       
    33     file = AbsFile(file)
       
    34     return os.path.dirname(os.path.realpath(file))
       
    35 
       
    36 def AbsNeighbourFile(file, *args):
       
    37     return os.path.join(AbsDir(file), *args)
       
    38 
       
    39 
       
    40 def AbsParentDir(file, level = 1):
       
    41     path = AbsDir(file)
       
    42     for i in range(0, level):
       
    43         path = os.path.dirname(path)
       
    44     return path