import os
import sys
import shutil
+import subprocess
import rpm
from mic import msger
-from mic.utils import errors, runner
-from mic.utils.misc import get_package
+from mic.utils import errors, proxy, misc
from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
+from mic.chroot import setup_chrootenv, cleanup_chrootenv
RPMTRANS_FLAGS = [rpm.RPMTRANS_FLAG_ALLFILES,
rpm.RPMTRANS_FLAG_NOSCRIPTS,
nonexist = []
for pkg in self.dlpkgs:
try:
- localpth = get_package(pkg, self.repomd, None)
+ localpth = misc.get_package(pkg, self.repomd, None)
if not localpth:
# skip non-existent rpm
nonexist.append(pkg)
tzdist = self._path('/etc/%s-release' % self.distro)
if not os.path.exists(tzdist):
with open(tzdist, 'w') as wf:
- wf.wrtie("bootstrap")
- except:
- raise errors.BootstrapError("Failed to create bootstrap")
+ wf.write("bootstrap")
+
+ except (OSError, IOError, errors.CreatorError), err:
+ raise errors.BootstrapError("%s" % err)
+
+ def run(self, cmd, chdir, bindmounts=None):
+ def mychroot():
+ os.chroot(self.rootdir)
+ os.chdir(chdir)
+
+ if isinstance(cmd, list):
+ shell = False
+ else:
+ shell = True
+
+ gloablmounts = None
+ try:
+ proxy.set_proxy_environ()
+ gloablmounts = setup_chrootenv(self.rootdir, bindmounts)
+ subprocess.call(cmd, preexec_fn = mychroot, shell=shell)
+ except (OSError, IOError), err:
+ raise RuntimeError(err)
+ finally:
+ cleanup_chrootenv(self.rootdir, bindmounts, gloablmounts)
+ proxy.unset_proxy_environ()
def cleanup(self):
try:
pkglist = bsopts[distro]
cwd = os.getcwd()
- # create bootstrap
- bsenv = bootstrap.Bootstrap(rootdir)
+ # create bootstrap and run mic in bootstrap
+ bsenv = bootstrap.Bootstrap(rootdir, distro)
try:
+ msger.info("Creating %s bootstrap ..." % distro)
bsenv.create(cropts['repomd'], pkglist)
sync_mic(rootdir)
+
+ msger.info("Start mic in bootstrap: %s\n" % rootdir)
+ bindmounts = get_bindmounts(cropts)
+ bsenv.run(argv, cwd, bindmounts)
+
except errors.BootstrapError, err:
- bsenv.cleanup()
msger.warning('\n%s' % err)
- msger.info("Use native running for failure to create bootstrap")
- return
-
- # run mic in bootstrap
- globalmounts = None
- bindmounts = get_bindmounts(cropts)
- msger.info("Start mic in bootstrap: %s\n" % rootdir)
- try:
- proxy.set_proxy_environ()
- globalmounts = setup_chrootenv(rootdir, bindmounts)
- subprocess.call(argv, preexec_fn=mychroot)
- except (OSError, IOError), err:
- raise errors.BootstrapError("Failed to run mic in bootstrap: %s" % err)
+ if msger.ask("Switch to native mode and continue?"):
+ return
+ else:
+ raise errors.BootstrapError("Failed to create bootstrap: %s" % err)
+ except RuntimeError, err:
+ raise errors.BootstrapError("Failed to create bootstrap: %s" % err)
finally:
- cleanup_chrootenv(rootdir, bindmounts, globalmounts)
- proxy.unset_proxy_environ()
+ bsenv.cleanup()
sys.exit(0)