#!/usr/bin/python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
"""
BitBake Build System Python Library
Copyright (C) 2003 Holger Schurig
Copyright (C) 2003, 2004 Chris Larson
Based on Gentoo's portage.py.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA.
"""
__version__ = "1.3.2.1"
__all__ = [
"debug",
"note",
"error",
"fatal",
"mkdirhier",
"movefile",
"tokenize",
"evaluate",
"flatten",
"relparse",
"ververify",
"isjustname",
"isspecific",
"pkgsplit",
"catpkgsplit",
"vercmp",
"pkgcmp",
"dep_parenreduce",
"dep_opconvert",
"digraph",
# fetch
"decodeurl",
"encodeurl",
# modules
"parse",
"data",
"event",
"build",
"fetch",
"manifest"
]
whitespace = '\t\n\x0b\x0c\r '
lowercase = 'abcdefghijklmnopqrstuvwxyz'
import sys, os, types, re, string
#projectdir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
projectdir = os.getcwd()
debug_level = 0
if "BBDEBUG" in os.environ:
level = int(os.environ["BBDEBUG"])
if level:
debug_level = level
else:
debug_level = 0
class VarExpandError(Exception):
pass
class MalformedUrl(Exception):
"""Exception raised when encountering an invalid url"""
#######################################################################
#######################################################################
#
# SECTION: Debug
#
# PURPOSE: little functions to make yourself known
#
#######################################################################
#######################################################################
debug_prepend = ''
def debug(lvl, *args):
if debug_level >= lvl:
print debug_prepend + 'DEBUG:', ''.join(args)
def note(*args):
print debug_prepend + 'NOTE:', ''.join(args)
def error(*args):
print debug_prepend + 'ERROR:', ''.join(args)
def fatal(*args):
print debug_prepend + 'ERROR:', ''.join(args)
sys.exit(1)
#######################################################################
#######################################################################
#
# SECTION: File
#
# PURPOSE: Basic file and directory tree related functions
#
#######################################################################
#######################################################################
def mkdirhier(dir):
"""Create a directory like 'mkdir -p', but does not complain if
directory already exists like os.makedirs
"""
debug(3, "mkdirhier(%s)" % dir)
try:
os.makedirs(dir)
debug(2, "created " + dir)
except OSError, e:
if e.errno != 17: raise e
#######################################################################
import stat
def movefile(src,dest,newmtime=None,sstat=None):
"""Moves a file from src to dest, preserving all permissions and
attributes; mtime will be preserved even when moving across
filesystems. Returns true on success and false on failure. Move is
atomic.
"""
#print "movefile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")"
try:
if not sstat:
sstat=os.lstat(src)
except Exception, e:
print "!!! Stating source file failed... movefile()"
print "!!!",e
return None
destexists=1
try:
dstat=os.lstat(dest)
except:
dstat=os.lstat(os.path.dirname(dest))
destexists=0
if destexists:
if