display all rpm debug messages in debug mode
[platform/upstream/mic.git] / mic / pluginbase.py
index 5d07848..ffdd993 100644 (file)
@@ -1,23 +1,24 @@
 #!/usr/bin/python -tt
 #
-# Copyright 2011 Intel, Inc.
+# Copyright (c) 2011 Intel, Inc.
 #
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2.  This program is distributed in the hope that it
-# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
-# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
+# 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
 #
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
-# trademarks that are incorporated in the source code or documentation are not
-# subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc.
+# 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.
 #
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+import os
+import shutil
 from mic import msger
+from mic.utils import errors
 
 class _Plugin(object):
     class __metaclass__(type):
@@ -26,11 +27,11 @@ class _Plugin(object):
                 cls.plugins = {}
 
             elif 'mic_plugin_type' in attrs:
-                    if attrs['mic_plugin_type'] not in cls.plugins:
-                        cls.plugins[attrs['mic_plugin_type']] = {}
+                if attrs['mic_plugin_type'] not in cls.plugins:
+                    cls.plugins[attrs['mic_plugin_type']] = {}
 
             elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs:
-                    cls.plugins[cls.mic_plugin_type][attrs['name']] = cls
+                cls.plugins[cls.mic_plugin_type][attrs['name']] = cls
 
         def show_plugins(cls):
             for cls in cls.plugins[cls.mic_plugin_type]:
@@ -42,26 +43,49 @@ class _Plugin(object):
 class ImagerPlugin(_Plugin):
     mic_plugin_type = "imager"
 
+    @classmethod
+    def check_image_exists(self, destdir, apacking=None,
+                                          images=(),
+                                          release=None):
+
+        # if it's a packing file, reset images
+        if apacking:
+            images = [apacking]
+
+        # release option will override images
+        if release is not None:
+            images = [os.path.basename(destdir.rstrip('/'))]
+            destdir = os.path.dirname(destdir.rstrip('/'))
+
+        for name in images:
+            if not name:
+                continue
+
+            image = os.path.join(destdir, name)
+            if not os.path.exists(image):
+                continue
+            if msger.ask("Target image/dir: %s already exists, "
+                         "clean up the old files and continue?" % image):
+                if os.path.isdir(image):
+                    for path, dirs, files in os.walk(os.path.abspath(image)):
+                        for fname in files:
+                            fpath = os.path.join(path, fname)
+                            if not fpath.endswith('.log'):
+                                os.remove(fpath)
+                else:
+                    os.unlink(image)
+            else:
+                raise errors.Abort("Canceled")
+
     def do_create(self):
         pass
 
     def do_chroot(self):
         pass
 
-    def do_pack(self):
-        pass
-
-    def do_unpack(self):
-        pass
-
 class BackendPlugin(_Plugin):
     mic_plugin_type="backend"
 
-    # suppress the verbose rpm warnings
-    if msger.get_loglevel() != 'debug':
-        import rpm
-        rpm.setVerbosity(rpm.RPMLOG_ERR)
-
     def addRepository(self):
         pass