Skip to content

Instantly share code, notes, and snippets.

@y10h
Created July 18, 2009 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y10h/149451 to your computer and use it in GitHub Desktop.
Save y10h/149451 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# 2009 Yury Yurevich <anarresti@altlinux.org>, <the.pythy@gmail.com>
# 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.
"""
Try to rebuild list of ALT Linux packages
Written for test maintaing packages to rebuild with python-2.6
Usage: rebuild_packages.py <file_with_list_of_packages_to_rebuild>
for examples, contents of file_with_list_of_packages_to_rebuild for my own
packages looks like:
mercurial
python-module-cups
python-module-pyme
"""
import os
import sys
import subprocess
from sets import Set
GEAR_HASHER = ['gear-hsh', '--verbose', '--target=i586']
def out(msg):
sys.stdout.write(msg)
sys.stdout.flush()
def build_package(path_to_gear):
p = subprocess.Popen(GEAR_HASHER,cwd=path_to_gear,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
status = p.wait()
if status !=0:
return False, stdout
return True, stdout
def get_gear(package_name, source='gears'):
if os.path.isdir(package_name):
call = ['git', 'fetch']
cwd = package_name
url = None
else:
letter = package_name[0]
url = 'git://git.altlinux.org/%s/%s/%s.git' % (source, letter, package_name)
call = ['git', 'clone', url]
cwd = None
p = subprocess.Popen(call,cwd=cwd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
status = p.wait()
if status:
if url and source == 'gears':
return get_gear(package_name, 'srpms')
print stdout
raise RuntimeError("Unable to retrieve or update gear %s" % package_name)
def get(packages):
for package in packages:
out("Retrieving %s... " % package)
get_gear(package)
out("done\n")
def build(packages):
rebuilt_packages = []
failed_packages = []
for package in packages:
out("Rebuilding %s... " % package)
done, buildlog = build_package(package)
if done:
rebuilt_packages.append(package)
out("done\n")
else:
failed_packages.append(package)
out("failed\n")
open("%s.buildlog" % package, 'w').write(buildlog)
return rebuilt_packages, failed_packages
def rebuild(packages):
get(packages)
failed = packages
prev_failed = []
done_packages = Set()
i = 1
while failed and failed != prev_failed:
out("---- Iteration %d\n" % i)
prev_failed = failed
done, failed = build(failed)
done_packages = done_packages.union(Set(done))
i += 1
done_packages = sorted(done_packages)
failed_packages = sorted(failed)
out("==== Progress is stalled, the result follows:\n")
if done_packages:
out("---- Successfully rebuilt packages:\n")
else:
out("---- None of packages rebuilt successfully :-(\n")
for package in done_packages:
out("%s\n" % package)
if failed_packages:
out("---- Failed to rebuild:\n")
else:
out('---- Congrats, all your packages rebuilt successfully\n')
for package in failed_packages:
out("%s\n" % package)
def main(args):
list_of_packages_to_rebuild = args[0]
packages = [x.strip() for x in open(list_of_packages_to_rebuild) if x.strip()]
rebuild(packages)
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment