add docstring for functions
authorGui Chen <gui.chen@intel.com>
Fri, 9 Aug 2013 06:29:35 +0000 (02:29 -0400)
committerGui Chen <gui.chen@intel.com>
Tue, 13 Aug 2013 09:23:53 +0000 (05:23 -0400)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/chroot.py

index 8792cad..a84eb2a 100644 (file)
@@ -48,6 +48,7 @@ BIND_MOUNTS = (
 #####################################################################
 
 def ELF_arch(chrootdir):
+    """ detect the architecture of an ELF file """
     #FIXME: if chkfiles are symlink, it will be complex
     chkfiles = ('/bin/bash', '/sbin/init')
     # regular expression to arch mapping
@@ -71,6 +72,7 @@ def ELF_arch(chrootdir):
                               chrootdir)
 
 def get_bindmounts(chrootdir, bindmounts = None):
+    """ calculate all bind mount entries for global usage """
     # bindmounts should be a string like '/dev:/dev'
     # FIXME: refine the bindmounts from string to dict
     global chroot_bindmounts
@@ -124,23 +126,27 @@ def get_bindmounts(chrootdir, bindmounts = None):
 #####################################################################
 
 def bind_mount(chrootmounts):
+    """ perform bind mounting """
     for b in chrootmounts:
         msger.verbose("bind_mount: %s -> %s" % (b.src, b.dest))
         b.mount()
 
 def setup_resolv(chrootdir):
+    """ resolve network """
     try:
         shutil.copyfile("/etc/resolv.conf", chrootdir + "/etc/resolv.conf")
     except:
         pass
 
 def setup_mtab(chrootdir):
+    """ adjust mount table """
     mtab = "/etc/mtab"
     dstmtab = chrootdir + mtab
     if not os.path.islink(dstmtab):
         shutil.copyfile(mtab, dstmtab)
 
 def setup_chrootenv(chrootdir, bindmounts = None):
+    """ setup chroot environment """
     global chroot_lock
 
     # acquire the lock
@@ -166,11 +172,13 @@ def setup_chrootenv(chrootdir, bindmounts = None):
 ######################################################################
 
 def bind_unmount(chrootmounts):
+    """ perform bind unmounting """
     for b in reversed(chrootmounts):
         msger.verbose("bind_unmount: %s -> %s" % (b.src, b.dest))
         b.unmount()
 
 def cleanup_resolv(chrootdir):
+    """ clear resolv.conf """
     try:
         fd = open(chrootdir + "/etc/resolv.conf", "w")
         fd.truncate(0)
@@ -179,6 +187,7 @@ def cleanup_resolv(chrootdir):
         pass
 
 def kill_proc_inchroot(chrootdir):
+    """ kill all processes running inside chrootdir """
     import glob
     for fp in glob.glob("/proc/*/root"):
         try:
@@ -189,10 +198,12 @@ def kill_proc_inchroot(chrootdir):
             pass
 
 def cleanup_mtab(chrootdir):
+    """ remove mtab file """
     if os.path.exists(chrootdir + "/etc/mtab"):
         os.unlink(chrootdir + "/etc/mtab")
 
 def cleanup_mounts(chrootdir):
+    """ clean up all mount entries owned by chrootdir """
     umountcmd = misc.find_binary_path("umount")
     mounts = open('/proc/mounts').readlines()
     for line in reversed(mounts):
@@ -213,6 +224,7 @@ def cleanup_mounts(chrootdir):
                 msger.warning("%s is not directory or is not empty" % point)
 
 def cleanup_chrootenv(chrootdir, bindmounts=None, globalmounts=()):
+    """ clean up chroot environment """
     # kill processes
     kill_proc_inchroot(chrootdir)
     # clean mtab
@@ -233,6 +245,7 @@ def cleanup_chrootenv(chrootdir, bindmounts=None, globalmounts=()):
 #####################################################################
 
 def savefs_before_chroot(chrootdir, saveto = None):
+    """ backup chrootdir to another directory before chrooting in """
     if configmgr.chroot['saveto']:
         savefs = True
         saveto = configmgr.chroot['saveto']
@@ -263,6 +276,7 @@ def savefs_before_chroot(chrootdir, saveto = None):
             msger.warning(wrnmsg)
 
 def cleanup_after_chroot(targettype, imgmount, tmpdir, tmpmnt):
+    """ clean up all temporary directories after chrooting """
     if imgmount and targettype == "img":
         imgmount.cleanup()
 
@@ -273,6 +287,7 @@ def cleanup_after_chroot(targettype, imgmount, tmpdir, tmpmnt):
         shutil.rmtree(tmpmnt, ignore_errors = True)
 
 def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"):
+    """ chroot the chrootdir and execute the command """
     def mychroot():
         os.chroot(chrootdir)
         os.chdir("/")