Re: How to know the set of (source?) packages having bytecode executables?
Hello,
David MENTRE <dmentre@linux-france.org> writes:
> I'll think I'll try a more brute-force approach: installing all
> OCaml-related packages and look for OCaml bytecode binaries in /usr/bin/
> (using the same pattern as proposed in the Ubuntu bug report).
[...]
> After looking at Stephane's gen-binNMU-request.py script, using rmadison
> I should be able to make such a script.
After using Stephane's script as template, I have my Python script to
list all binary packages. I have also some Python code to test if a
file is an OCaml bytecode (match Caml1999X[0-9][0-9][0-9] pattern at the
last 12 bytes of the file).
With "dpkg -S", I should be able to find the relevant binary packages
that contain a bytecode. Is it possible to do the same as "dpkg -S" from
Python code using, I suppose, python-debian code?
Here are my scripts, if it can help others.
Yours,
d.
PS : The ubuntu-hardy-ocaml-bin-pkg.py is Ubuntu Hardy specific but it
should be easy to adapt it to various Debian/Ubuntu releases.
--
GPG/PGP key: A3AD7A2A David MENTRE <dmentre@linux-france.org>
5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Extracted from gen-binNMU-request.py:
# * download()
# Use of rmadison also extracted from this script. Thanks Stephane Glondu!
import sys, os, re
from commands import getoutput, getstatusoutput
from httplib import HTTPConnection
reference_arch = "i386"
madison_split_regexp = re.compile("[ |,\n]+")
def download(site, file_path):
c = HTTPConnection(site)
c.request("GET", "/%s" % file_path)
r = c.getresponse().read()
c.close()
return r
def get_binary_packages(src_pkg):
if src_pkg == "":
return []
rmadison_raw = getoutput("rmadison -u ubuntu -s hardy -S %s" % src_pkg)
binary_packages = []
for line in filter(None, rmadison_raw.split("\n")):
splitted = madison_split_regexp.split(line.strip())
binary_package_name = splitted[0]
version = splitted[1]
available_archs = splitted[3:]
#print binary_package_name, version, available_archs
if "all" in available_archs:
binary_packages.append(binary_package_name)
elif reference_arch in available_archs:
binary_packages.append(binary_package_name)
#print "Kept: ", binary_packages
return binary_packages
def output_aptget_command(package_list):
print "## To install ##"
print "apt-get \\"
for pkg in package_list[:-1]:
print " ", pkg, "\\"
print " ", package_list[-1]
def main():
ocaml_sources_packages = download("pkg-ocaml-maint.alioth.debian.org",
"ocaml_src_pkgs.txt").split("\n")
all_binary_packages = []
for src_pkg in ocaml_sources_packages:
all_binary_packages.extend(get_binary_packages(src_pkg))
output_aptget_command(all_binary_packages)
main()
#!/usr/bin/python
import sys
import os
import re
def is_ocaml_bytecode(filename):
f = open(filename, "r")
f.seek(-12, 2) # go to 12 bytes before the end of file
bytes = f.read(12)
f.close()
if re.match('Caml1999X[0-9][0-9][0-9]', bytes):
return True
else:
return False
for filename in sys.argv[1:]:
print filename, is_ocaml_bytecode(filename)
Reply to: