diff --git a/pisi/api.py b/pisi/api.py index db10fee4..cf4015f9 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -343,12 +343,12 @@ def index(dirs=None, output='pisi-index.xml', skip_sources=False, skip_signing=F index.write(output, sha1sum=True, compress=File.bz2, sign=File.detached) ctx.ui.info(_('* Index file written')) -def add_repo(name, indexuri): +def add_repo(name, indexuri, at = None): if ctx.repodb.has_repo(name): raise Error(_('Repo %s already present.') % name) else: repo = pisi.repodb.Repo(URI(indexuri)) - ctx.repodb.add_repo(name, repo) + ctx.repodb.add_repo(name, repo, at = at) ctx.ui.info(_('Repo %s added to system.') % name) def remove_repo(name): diff --git a/pisi/repodb.py b/pisi/repodb.py index 58994be1..70492b26 100644 --- a/pisi/repodb.py +++ b/pisi/repodb.py @@ -73,7 +73,8 @@ class RepoDB(object): name = str(name) return self.d["repo-" + name] - def add_repo(self, name, repo_info, txn = None): + def add_repo(self, name, repo_info, txn = None, at = None): + """add repository with name and repo_info at a given optional position""" name = str(name) assert (isinstance(repo_info,Repo)) def proc(txn): @@ -81,7 +82,13 @@ class RepoDB(object): raise Error(_('Repository %s already exists') % name) self.d.put("repo-" + name, repo_info, txn) order = self.d.get("order", txn) - order.append(name) + if at: + if at<0 or at>len(order): + raise Error(_("Cannot add repository at position %s" % at)) + order.insert(name, at) + else: + order.append(name) + self.d.put("order", order, txn) self.d.txn_proc(proc, txn) diff --git a/scripts/pisimedia.py b/scripts/pisimedia.py new file mode 100755 index 00000000..292609bf --- /dev/null +++ b/scripts/pisimedia.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# +# Copyright (C) 2005, TUBITAK/UEKAE +# +# 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. +# +# Please read the COPYING file. +# +# Author: Eray Ozkural + +import sys +import os + +import pisi +import pisi.context as ctx + +usage = "Usage: pisimedia " + +if len(sys.argv)!=2: + print usage + sys.exit(1) + +#op = sys.argv[1] +#if not op in ['install', 'upgrade']: +# print usage +# sys.exit(2) + +idx = sys.argv[1] +if not os.path.exists(idx): + print "pisi index %s cannot be found" % idx + +pisi.api.init() + +try: + tmpid = 0 + tmprepo = 'pisimedia%d' % tmpid + while ctx.repodb.has_repo(tmprepo): + tmpid += 1 + tmprepo = 'pisimedia%d' % tmpid + pisi.api.add_repo(tmprepo, idx, at = 0) + pisi.api.update_repo(tmprepo) + packages = ctx.packagedb.list_packages(repo=tmprepo) + pisi.api.install(packages, reinstall=True) +except Exception, e: + ctx.ui.error(e) + if ctx.repodb.has_repo(tmprepo): + pisi.api.remove_repo(tmprepo) +pisi.api.finalize()