ognibuild/ognibuild/__init__.py
2021-02-23 03:23:58 +00:00

58 lines
1.7 KiB
Python

#!/usr/bin/python
# Copyright (C) 2019-2020 Jelmer Vernooij <jelmer@jelmer.uk>
# encoding: utf-8
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
import stat
import sys
DEFAULT_PYTHON = "python3"
class DetailedFailure(Exception):
def __init__(self, retcode, argv, error):
self.retcode = retcode
self.argv = argv
self.error = error
def shebang_binary(p):
if not (os.stat(p).st_mode & stat.S_IEXEC):
return None
with open(p, "rb") as f:
firstline = f.readline()
if not firstline.startswith(b"#!"):
return None
args = firstline[2:].split(b" ")
if args[0] in (b"/usr/bin/env", b"env"):
return os.path.basename(args[1].decode()).strip()
return os.path.basename(args[0].decode()).strip()
class UpstreamRequirement(object):
def __init__(self, family, name):
self.family = family
self.name = name
class UpstreamOutput(object):
def __init__(self, family, name):
self.family = family
self.name = name