andrej@1511: #!/usr/bin/env python andrej@1511: # -*- coding: utf-8 -*- andrej@1511: andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1511: # andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD andrej@1511: # andrej@1511: # See COPYING file for copyrights details. andrej@1511: # andrej@1511: # This program is free software; you can redistribute it and/or andrej@1511: # modify it under the terms of the GNU General Public License andrej@1511: # as published by the Free Software Foundation; either version 2 andrej@1511: # of the License, or (at your option) any later version. andrej@1511: # andrej@1511: # This program is distributed in the hope that it will be useful, andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1511: # GNU General Public License for more details. andrej@1511: # andrej@1511: # You should have received a copy of the GNU General Public License andrej@1511: # along with this program; if not, write to the Free Software andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1511: Edouard@725: """ Edouard@725: Misc definitions Edouard@725: """ Edouard@725: andrej@1853: andrej@1853: from __future__ import absolute_import andrej@1732: import os andrej@2456: from functools import reduce laurent@806: andrej@1853: from util.BitmapLibrary import AddBitmapFolder andrej@1853: from util.TranslationCatalogs import AddCatalog andrej@1853: andrej@1736: Edouard@725: def CheckPathPerm(path): andrej@1736: """ Helper func to check path write permission """ Edouard@725: if path is None or not os.path.isdir(path): Edouard@725: return False Edouard@725: for root, dirs, files in os.walk(path): andrej@1719: files = [f for f in files if not f[0] == '.'] andrej@1719: dirs[:] = [d for d in dirs if not d[0] == '.'] andrej@1719: for name in files: andrej@1719: if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True: andrej@1719: return False Edouard@725: return True Edouard@725: Edouard@1953: Edouard@1923: def GetClassImporter(param): Edouard@1920: """ Edouard@1920: is used to resolve library class names in features.py Edouard@1923: if param is a string, returns a callable that return the class pointed by param Edouard@1923: if a class is given, then returns a callable that returns the given class. Edouard@1920: """ andrej@1736: Edouard@1923: if isinstance(param, str): Edouard@1920: def factory(): Edouard@1920: # on-demand import, only when using class Edouard@1923: mod = __import__(param.rsplit('.', 1)[0]) Edouard@1923: return reduce(getattr, param.split('.')[1:], mod) Edouard@1920: return factory Edouard@1930: else: Edouard@1953: return lambda: param Edouard@1388: andrej@1736: Edouard@1388: def InstallLocalRessources(CWD): Edouard@1388: # Beremiz bitmaps Edouard@1388: AddBitmapFolder(os.path.join(CWD, "images")) Edouard@1388: Edouard@1388: # Internationalization Edouard@1388: AddCatalog(os.path.join(CWD, "locale"))