import pwd
import re
-from gitbuildsys import utils, runner
+from gitbuildsys.utils import Temp, RepoParser
from gitbuildsys.errors import GbsError, Usage
from gitbuildsys.conf import configmgr
from gitbuildsys.safe_url import SafeURL
'''generate repos and build conf options for depanneur'''
cmd_opts = []
- cache = utils.Temp(prefix=os.path.join(TMPDIR, 'gbscache'),
+ cache = Temp(prefix=os.path.join(TMPDIR, 'gbscache'),
directory=True)
cachedir = cache.path
if not os.path.exists(cachedir):
if not repos:
raise GbsError('No package repository specified.')
- repoparser = utils.RepoParser(repos, cachedir)
+ repoparser = RepoParser(repos, cachedir)
repourls = repoparser.get_repos_by_arch(arch)
if not repourls:
raise GbsError('no available repositories found for arch %s under the '
return cmd_opts
-def get_processors():
- """
- get number of processors (online) based on
- SC_NPROCESSORS_ONLN (returns 1 if config name does not exist).
- """
- try:
- return os.sysconf('SC_NPROCESSORS_ONLN')
- except ValueError:
- return 1
-
-def find_binary_path(binary):
- """
- return full path of specified binary file
- """
- if os.environ.has_key("PATH"):
- paths = os.environ["PATH"].split(":")
- else:
- paths = []
- if os.environ.has_key("HOME"):
- paths += [os.environ["HOME"] + "/bin"]
- paths += ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin",
- "/usr/bin", "/sbin", "/bin"]
-
- for path in paths:
- bin_path = "%s/%s" % (path, binary)
- if os.path.exists(bin_path):
- return bin_path
- return None
-
-def is_statically_linked(binary):
- """
- check if binary is statically linked
- """
- return ", statically linked, " in runner.outs(['file', binary])
-
def get_profile(args):
"""
Get the build profile to be used
from __future__ import with_statement
import os
-import ast
import base64
import shutil
from collections import namedtuple
return base64.b64encode(passwd.encode('bz2'))
-def evalute_string(string):
- '''safely evaluate string'''
- if string.startswith('"') or string.startswith("'"):
- return ast.literal_eval(string)
- return string
-
-
-def split_and_evaluate_string(string, sep=None, maxsplit=-1):
- '''split a string and evaluate each of them'''
- return [ evalute_string(i.strip()) for i in string.split(sep, maxsplit) ]
-
-
class BrainConfigParser(SafeConfigParser):
"""Standard ConfigParser derived class which can reserve most of the
comments, indents, and other user customized stuff inside the ini file.
+++ /dev/null
-#!/usr/bin/python -tt
-# vim: ai ts=4 sts=4 et sw=4
-#
-# Copyright (c) 2011 Intel, Inc.
-#
-# 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; version 2 of the License
-#
-# 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.
-
-"""
-API to call external programs using subprocess.
-NOTE!!! Called only once in cmd_buld
-Most probably can be easily replaced by subprocess.check_output there.
-"""
-
-import os
-import subprocess
-
-from gitbuildsys.errors import GbsError
-
-def runtool(cmdln_or_args, catch=1):
- """Handy wrapper of Popen
- Parameters:
- cmdln_or_args: can be both args and cmdln str (shell=True)
- catch: 0, quitely run
- 1, only STDOUT
- 2, only STDERR
- 3, both STDOUT and STDERR
- Returns:
- tuple (rc, output)
- (rc, None) if catch is 0
- """
-
- if catch not in (0, 1, 2, 3):
- # invalid catch selection, will cause exception, that's good
- return None
-
- if isinstance(cmdln_or_args, list):
- cmd = cmdln_or_args[0]
- shell = False
- else:
- import shlex
- cmd = shlex.split(cmdln_or_args)[0]
- shell = True
-
- dev_null = os.open("/dev/null", os.O_WRONLY)
- sout = [dev_null, subprocess.PIPE, dev_null, subprocess.PIPE][catch]
- serr = [dev_null, dev_null, subprocess.PIPE, subprocess.STDOUT][catch]
-
- try:
- process = subprocess.Popen(cmdln_or_args, stdout=sout,
- stderr=serr, shell=shell)
- out = process.communicate()[0]
- if out is None:
- out = ''
- except OSError, exc:
- if exc.errno == 2:
- # [Errno 2] No such file or directory
- raise GbsError('Cannot run command: %s, lost dependency?' % cmd)
- else:
- raise # relay
- finally:
- os.close(dev_null)
-
- return (process.returncode, out)
-
-def outs(cmdln_or_args, catch=1):
- """Get stripped output."""
- return runtool(cmdln_or_args, catch)[1].strip()
self.stat = os.stat(self.name)
- def update_stat(self):
- """Updates stat info."""
- self.stat = os.stat(self.name)
-
def is_changed(self):
"""Check if temporary file has been changed."""
return os.stat(self.name) != self.stat