initial import code into git
[platform/upstream/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 import pkgmanagers
37 from micng.utils.rpmmisc import *
38 from micng.utils.misc import *
39 from BaseImageCreator import ImageCreator
40
41
42 class FsImageCreator(ImageCreator):
43     def __init__(self, ks, name):
44         """Initialize a LoopImageCreator instance.
45
46         This method takes the same arguments as ImageCreator.__init__()
47         """
48         ImageCreator.__init__(self, ks, name)
49
50         self._fstype = None
51         self._fsopts = None
52
53     def _stage_final_image(self):
54         """ nothing to do """
55         pass
56
57     def package(self, destdir = "."):
58         self._stage_final_image()
59
60         destdir = os.path.abspath(os.path.expanduser(destdir))
61         if self._recording_pkgs:
62             self._save_recording_pkgs(destdir)
63
64         print "Copying %s to %s, please be patient to wait (it is slow if they are on different file systems/partitons/disks)" \
65                % (self._instroot, destdir + "/" + self.name)
66
67         copycmd = find_binary_path("cp")
68         args = [ copycmd, "-af", self._instroot, destdir + "/" + self.name ]
69         subprocess.call(args)
70
71         ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr", "/etc/mtab"]
72         for exclude in ignores:
73             if os.path.exists(destdir + "/" + self.name + exclude):
74                 os.unlink(destdir + "/" + self.name + exclude)
75
76         self.outimage.append(destdir + "/" + self.name)