This will lay the ground for the next patch, as this function is useful for more than just the depends module. Signed-off-by: Dan McGee <dan@archlinux.org> --- Namcap/depends.py | 17 +---------------- Namcap/util.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 Namcap/util.py diff --git a/Namcap/depends.py b/Namcap/depends.py index 4a3f733..f6cc9b2 100644 --- a/Namcap/depends.py +++ b/Namcap/depends.py @@ -18,6 +18,7 @@ # import re, os, os.path, pacman, subprocess +from Namcap.util import is_elf supported_scripts = ['python', 'perl', 'ruby', 'wish', 'expect', 'tk', 'bash', 'sh', 'dash', 'tcsh', 'pdksh' ] @@ -60,22 +61,6 @@ def figurebitsize(line): else: return 'i686' -def is_elf(path): - """ - Given a file path, ensure it exists and peek at the first few bytes - to determine if it is an ELF file. - """ - if not os.path.isfile(path): - return False - fd = open(path) - bytes = fd.read(4) - fd.close() - # magic elf header, present in binaries and libraries - if bytes == "\x7FELF": - return True - else: - return False - def scanlibs(data, dirname, names): """ Walk over all the files in the package and run "readelf -d" on them. diff --git a/Namcap/util.py b/Namcap/util.py new file mode 100644 index 0000000..6089a4b --- /dev/null +++ b/Namcap/util.py @@ -0,0 +1,38 @@ +# +# namcap rules - utility functions +# Copyright (C) 2009 Dan McGee <dan@archlinux.org> +# +# 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 +# + +import os + +def is_elf(path): + """ + Given a file path, ensure it exists and peek at the first few bytes + to determine if it is an ELF file. + """ + if not os.path.isfile(path): + return False + fd = open(path) + bytes = fd.read(4) + fd.close() + # magic elf header, present in binaries and libraries + if bytes == "\x7FELF": + return True + else: + return False + +# vim: set ts=4 sw=4 noet: -- 1.6.4.4