b3e474999fd3b035b5eaf85b8a1ef24cd6a82d43
[tools/mic.git] / micng / imager / fs.py
1 #
2 # creator.py : ImageCreator and LoopImageCreator base classes
3 #
4 # Copyright 2007, Red Hat  Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Library General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 import os
20 import os.path
21 import stat
22 import sys
23 import tempfile
24 import shutil
25 import logging
26 import subprocess
27 import re
28 import tarfile
29 import glob
30
31 import rpm
32
33 from micng.utils.errors import *
34 from micng.utils.fs_related import *
35 from micng.utils import kickstart
36 from micng.utils.rpmmisc import *
37 from micng.utils.misc import *
38 from baseimager import BaseImageCreator
39
40
41 class FsImageCreator(BaseImageCreator):
42     def __init__(self, cfgmgr = None, pkgmgr = None):
43         BaseImageCreator.__init__(self, cfgmgr, pkgmgr)
44         self._fstype = None
45         self._fsopts = None
46
47     def _stage_final_image(self):
48         """ nothing to do"""
49         pass
50
51     def package(self, destdir = "."):
52         self._stage_final_image()
53
54         if not os.path.exists(destdir):
55             mkdirs(destdir)
56         destdir = os.path.abspath(os.path.expanduser(destdir))
57         if self._recording_pkgs:
58             self._save_recording_pkgs(destdir)
59
60         logging.info("Copying %s to %s, please be patient to wait" % (self._instroot, destdir + "/" + self.name))
61
62         copycmd = find_binary_path("cp")
63         args = [ copycmd, "-af", self._instroot, destdir + "/" + self.name ]
64         subprocess.call(args)
65
66         ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr", "/etc/mtab"]
67         for exclude in ignores:
68             if os.path.exists(destdir + "/" + self.name + exclude):
69                 os.unlink(destdir + "/" + self.name + exclude)
70
71         self.outimage.append(destdir + "/" + self.name)