Skip to content

Commit

Permalink
Merge "fixed wrong usage of rstrip in loop.py"
Browse files Browse the repository at this point in the history
  • Loading branch information
jfding authored and Gerrit Code Review committed Jul 27, 2012
2 parents f971fb4 + bf35b84 commit 1f3e63e
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 29 deletions.
24 changes: 15 additions & 9 deletions mic/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _setRootdir(self, name):

def _getRootdir(self):
if not os.path.exists(self._rootdir):
raise errors.BootstrapError("Root dir: %s not exist" % self._rootdir)
raise errors.BootstrapError("dir: %s not exist" % self._rootdir)
return self._rootdir

rootdir = property(fget = lambda self: self._getRootdir(),
Expand All @@ -95,7 +95,8 @@ def _setPkgmgr(self, name):
if key == name:
self._pkgmgr = cls
if not self._pkgmgr:
raise errors.BootstrapError("Backend: %s can't be loaded correctly" % name)
raise errors.BootstrapError("Backend: %s can't be loaded correctly"\
% name)

pkgmgr = property(fget = lambda self: self._pkgmgr,
fset = lambda self, name: self._setPkgmgr(name),
Expand Down Expand Up @@ -190,8 +191,9 @@ def create(self, name, repolist, **kwargs):
pkg_manager.setup()

for repo in repolist:
if 'proxy' in repo.keys():
pkg_manager.addRepository(repo['name'], repo['baseurl'], proxy = repo['proxy'])
if 'proxy' in repo:
pkg_manager.addRepository(repo['name'], repo['baseurl'],
proxy=repo['proxy'])
else:
pkg_manager.addRepository(repo['name'], repo['baseurl'])

Expand Down Expand Up @@ -225,8 +227,9 @@ def create(self, name, repolist, **kwargs):
shutil.rmtree(destdir, ignore_errors = True)
shutil.copytree(srcdir, destdir)
# create '/tmp' in chroot
if not os.path.exists(os.path.join(os.path.abspath(self.rootdir), "tmp")):
os.makedirs(os.path.join(os.path.abspath(self.rootdir), "tmp"))
_tmpdir = os.path.join(os.path.abspath(self.rootdir), "tmp")
if not os.path.exists(_tmpdir):
os.makedirs(_tmpdir)

msger.info("Bootstrap created.")

Expand All @@ -242,14 +245,17 @@ def mychroot():

shutil.copyfile("/etc/resolv.conf", chrootdir + "/etc/resolv.conf")
try:
subprocess.call("zypper -n --no-gpg-checks update", preexec_fn=mychroot, shell=True)
subprocess.call("zypper -n --no-gpg-checks update",
preexec_fn=mychroot, shell=True)
except OSError, err:
raise errors.BootstrapError("Bootstrap: %s Update fail" % chrootdir)
raise errors.BootstrapError("Bootstrap: %s update failed" %\
chrootdir)

def cleanup(self, name):
self.rootdir = name
try:
chroot.cleanup_mounts(self.rootdir)
shutil.rmtree(self.rootdir, ignore_errors=True)
except:
raise errors.BootstrapError("Bootstrap: %s clean up fail " % self.rootdir)
raise errors.BootstrapError("Bootstrap: %s clean up failed" %\
self.rootdir)
13 changes: 8 additions & 5 deletions mic/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ def get_bind_mounts(chrootdir, bindmounts):

"""Default bind mounts"""
for pt in BIND_MOUNTS:
chrootmounts.append(fs_related.BindChrootMount(pt, chrootdir, None))
chrootmounts.append(fs_related.BindChrootMount(pt,
chrootdir,
None))

chrootmounts.append(fs_related.BindChrootMount("/",
chrootdir,
"/parentroot",
"ro"))

for kernel in os.listdir("/lib/modules"):
chrootmounts.append(fs_related.BindChrootMount("/lib/modules/"+kernel,
chrootdir,
None,
"ro"))
chrootmounts.append(fs_related.BindChrootMount(
"/lib/modules/"+kernel,
chrootdir,
None,
"ro"))

return chrootmounts

Expand Down
6 changes: 4 additions & 2 deletions mic/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ def _parse_siteconf(self, siteconf):

if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
if repostr.has_key(option):
repostr[option] += "name:%s,baseurl:%s," % (option, val)
repostr[option] += "name:%s,baseurl:%s," % \
(option, val)
else:
repostr[option] = "name:%s,baseurl:%s," % (option, val)
repostr[option] = "name:%s,baseurl:%s," % \
(option, val)
continue

self.bootstraps[name] = repostr
Expand Down
6 changes: 4 additions & 2 deletions mic/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def __init__(self, *args, **kwargs):

def get_optparser(self):
optparser = cmdln.CmdlnOptionParser(self)
optparser.add_option('-d', '--debug', action='store_true', dest='debug',
optparser.add_option('-d', '--debug', action='store_true',
dest='debug',
help=SUPPRESS_HELP)
optparser.add_option('-v', '--verbose', action='store_true',
dest='verbose',
Expand Down Expand Up @@ -127,7 +128,7 @@ def preoptparse(self, argv):
try:
largs.append(argv.pop(0))
except IndexError:
raise errors.Usage("%s option requires an argument" % arg)
raise errors.Usage("option %s requires arguments" % arg)

else:
if arg.startswith("--"):
Expand Down Expand Up @@ -169,6 +170,7 @@ def postoptparse(self):
if self.options.cachedir is not None:
configmgr.create['cachedir'] = abspath(self.options.cachedir)
os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']

if self.options.local_pkgs_path is not None:
if not os.path.exists(self.options.local_pkgs_path):
msger.error('Local pkgs directory: \'%s\' not exist' \
Expand Down
3 changes: 1 addition & 2 deletions mic/imager/baseimager.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, createopts = None, pkgmgr = None):

# No ks provided when called by convertor, so skip the dependency check
if self.ks:
# If we have btrfs partition we need to check that we have toosl for those
# If we have btrfs partition we need to check necessary tools
for part in self.ks.handler.partition.partitions:
if part.fstype and part.fstype == "btrfs":
self._dep_checks.append("mkfs.btrfs")
Expand Down Expand Up @@ -1232,7 +1232,6 @@ def copy_kernel(self):

def copy_attachment(self):
""" Subclass implement it to handle attachment files
NOTE: This needs to be called before unmounting the instroot.
"""
pass
Expand Down
4 changes: 2 additions & 2 deletions mic/imager/livecd.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(self, creatoropts = None, pkgmgr = None):

#The default kernel type from kickstart.
if self.ks:
self._default_kernel = kickstart.get_default_kernel(self.ks, "kernel")
self._default_kernel = kickstart.get_default_kernel(self.ks,
"kernel")
else:
self._default_kernel = None

Expand Down Expand Up @@ -717,6 +718,5 @@ def _configure_bootloader(self, isodir):
LiveCDImageCreator = x86LiveImageCreator
elif arch.startswith("arm"):
LiveCDImageCreator = LiveImageCreatorBase

else:
raise CreatorError("Architecture not supported!")
3 changes: 2 additions & 1 deletion mic/imager/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ def _stage_final_image(self):
misc.packing(dstfile, self.__imgdir)

if self.pack_to:
mountfp_xml = os.path.splitext(self.pack_to)[0].rstrip('.tar') + ".xml"
mountfp_xml = os.path.splitext(self.pack_to)[0]
mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
else:
mountfp_xml = self.name + ".xml"
# save mount points mapping file to xml
Expand Down
4 changes: 2 additions & 2 deletions mic/imager/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _get_fstab(self):
return s

def _create_mkinitrd_config(self):
#write to tell which modules to be included in initrd
"""write to tell which modules to be included in initrd"""

mkinitrd = ""
mkinitrd += "PROBE=\"no\"\n"
Expand Down Expand Up @@ -442,7 +442,7 @@ def _write_image_xml(self):
% (self.name,
name,
self.__disk_format))
xml += " <disk file='%s-%s.%s' use='system' format='%s'>\n" \
xml += " <disk file='%s-%s.%s' use='system' format='%s'>\n"\
% (self.name,
name,
self.__disk_format,
Expand Down
5 changes: 4 additions & 1 deletion mic/pluginbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class ImagerPlugin(_Plugin):
mic_plugin_type = "imager"

@classmethod
def check_image_exists(self, destdir, apacking=None, images=[], release=None):
def check_image_exists(self, destdir, apacking=None,
images=[],
release=None):

# if it's a packing file, reset images
if apacking:
images = [apacking]
Expand Down
8 changes: 5 additions & 3 deletions mic/rt_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def runmic_in_runtime(runmode, opts, ksfile, argv=None):
#repostrs = misc.get_repostrs_from_ks(opts['ks'])
#for item in repostrs:
# repolist.append(convert_repostr(item))
msger.info("Failed to find propery bootstrap, please check config file")
msger.info("cannot find valid bootstrap, please check the config")
msger.info("Back to native running")
return
else:
Expand Down Expand Up @@ -129,7 +129,8 @@ def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
bootstrap_lst = bootstrap_env.bootstraps
setattr(bootstrap_env, 'rootdir', name)
if not bootstrap_lst or not name in bootstrap_lst:
msger.info("Creating bootstrap %s under %s" % (name, bootstrap_env.homedir))
msger.info("Creating bootstrap %s under %s" % \
(name, bootstrap_env.homedir))
bootstrap_env.create(name, repolist)

msger.info("Use bootstrap: %s" % bootstrap_env.rootdir)
Expand All @@ -155,7 +156,8 @@ def runmic_in_bootstrap(name, argv, opts, ksfile, repolist):
# make unique and remain the original order
lst = sorted(set(lst), key=lst.index)

bindmounts = ';'.join(map(lambda p: os.path.abspath(os.path.expanduser(p)), lst))
bindmounts = ';'.join(map(lambda p: os.path.abspath(os.path.expanduser(p)),
lst))

msger.info("Start mic command in bootstrap")
bootstrap_env.run(name, argv, cwd, bindmounts)
Expand Down

0 comments on commit 1f3e63e

Please sign in to comment.