~ubuntu-branches/ubuntu/precise/vm-builder/precise

« back to all changes in this revision

Viewing changes to VMBuilder/plugins/postinst/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2010-02-22 13:56:18 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100222135618-la13e3mu397rg0m1
Tags: 0.12.0-0ubuntu1
* New upstream release. (FFe: LP: #525741)
  - All patches incorporated upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    You should have received a copy of the GNU General Public License
17
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
#
19
 
from VMBuilder import register_plugin, Plugin, VMBuilderUserError
 
19
from VMBuilder import register_distro_plugin, Plugin, VMBuilderUserError
20
20
from VMBuilder.util import run_cmd
21
21
 
22
22
import logging
32
32
    name ='Post install plugin'
33
33
 
34
34
    def register_options(self):
35
 
        group = self.vm.setting_group('Post install actions')
 
35
        group = self.context.setting_group('Post install actions')
36
36
        group.add_option('--copy', metavar='FILE', help="Read 'source dest' lines from FILE, copying source files from host to dest in the guest's file system.")
37
37
        group.add_option('--execscript', '--exec', metavar='SCRIPT', help="Run SCRIPT after distro installation finishes. Script will be called with the guest's chroot as first argument, so you can use 'chroot $1 <cmd>' to run code in the virtual machine.")
38
 
        self.vm.register_setting_group(group)
 
38
        self.context.register_setting_group(group)
39
39
 
40
40
    def preflight_check(self):
41
 
        if self.vm.copy:
42
 
            logging.debug("Checking if --copy PATH exists: %s" % self.vm.copy)
43
 
            if not(os.path.isfile(self.vm.copy)):
44
 
                raise VMBuilderUserError('The path to the --copy directives is invalid: %s. Make sure you are providing a full path.' % self.vm.copy)
 
41
        if self.context.copy:
 
42
            logging.debug("Checking if --copy PATH exists: %s" % self.context.copy)
 
43
            if not(os.path.isfile(self.context.copy)):
 
44
                raise VMBuilderUserError('The path to the --copy directives is invalid: %s. Make sure you are providing a full path.' % self.context.copy)
45
45
                
46
 
        if self.vm.execscript:
47
 
            logging.debug("Checking if --exec PATH exists: %s" % self.vm.execscript)
48
 
            if not(os.path.isfile(self.vm.execscript)):
49
 
                raise VMBuilderUserError('The path to the --execscript file is invalid: %s. Make sure you are providing a full path.' % self.vm.execscript) 
 
46
        if self.context.execscript:
 
47
            logging.debug("Checking if --exec PATH exists: %s" % self.context.execscript)
 
48
            if not(os.path.isfile(self.context.execscript)):
 
49
                raise VMBuilderUserError('The path to the --execscript file is invalid: %s. Make sure you are providing a full path.' % self.context.execscript) 
50
50
 
51
 
            logging.debug("Checking permissions of --exec PATH: %s" % self.vm.execscript)
52
 
            if not os.access(self.vm.execscript, os.X_OK|os.R_OK):
53
 
                raise VMBuilderUserError('The path to the --execscript file has invalid permissions: %s. Make sure the path is readable and executable.' % self.vm.execscript)
 
51
            logging.debug("Checking permissions of --exec PATH: %s" % self.context.execscript)
 
52
            if not os.access(self.context.execscript, os.X_OK|os.R_OK):
 
53
                raise VMBuilderUserError('The path to the --execscript file has invalid permissions: %s. Make sure the path is readable and executable.' % self.context.execscript)
54
54
 
55
55
    def post_install(self):
56
 
        if self.vm.copy:
57
 
            logging.info("Copying files specified by --copy in: %s" % self.vm.copy)
 
56
        if self.context.copy:
 
57
            logging.info("Copying files specified by --copy in: %s" % self.context.copy)
58
58
            try:
59
 
                for line in file(self.vm.copy):
 
59
                for line in file(self.context.copy):
60
60
                    pair = line.strip().split(' ')
61
61
                    if len(pair) < 2: # skip blank and incomplete lines
62
62
                        continue
63
 
                    util.run_cmd('cp', '-LpR', pair[0], '%s%s' % (self.vm.installdir, pair[1]))
 
63
                    util.run_cmd('cp', '-LpR', pair[0], '%s%s' % (self.context.installdir, pair[1]))
64
64
 
65
65
            except IOError, (errno, strerror):
66
66
                raise VMBuilderUserError("%s executing --copy directives: %s" % (errno, strerror))
67
67
 
68
 
        if self.vm.execscript:
69
 
            logging.info("Executing script: %s" % self.vm.execscript)
70
 
            util.run_cmd(self.vm.execscript, self.vm.installdir)
 
68
        if self.context.execscript:
 
69
            logging.info("Executing script: %s" % self.context.execscript)
 
70
            util.run_cmd(self.context.execscript, self.vm.installdir)
71
71
 
72
72
        return True
73
73
 
74
 
register_plugin(postinst)
 
74
#register_plugin(postinst)