~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/handlers/shell_script.py

  • Committer: Scott Moser
  • Date: 2016-08-10 15:06:15 UTC
  • Revision ID: smoser@ubuntu.com-20160810150615-ma2fv107w3suy1ma
README: Mention move of revision control to git.

cloud-init development has moved its revision control to git.
It is available at 
  https://code.launchpad.net/cloud-init

Clone with 
  git clone https://git.launchpad.net/cloud-init
or
  git clone git+ssh://git.launchpad.net/cloud-init

For more information see
  https://git.launchpad.net/cloud-init/tree/HACKING.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vi: ts=4 expandtab
2
 
#
3
 
#    Copyright (C) 2012 Canonical Ltd.
4
 
#    Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
5
 
#    Copyright (C) 2012 Yahoo! Inc.
6
 
#
7
 
#    Author: Scott Moser <scott.moser@canonical.com>
8
 
#    Author: Juerg Haefliger <juerg.haefliger@hp.com>
9
 
#    Author: Joshua Harlow <harlowja@yahoo-inc.com>
10
 
#
11
 
#    This program is free software: you can redistribute it and/or modify
12
 
#    it under the terms of the GNU General Public License version 3, as
13
 
#    published by the Free Software Foundation.
14
 
#
15
 
#    This program is distributed in the hope that it will be useful,
16
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
#    GNU General Public License for more details.
19
 
#
20
 
#    You should have received a copy of the GNU General Public License
21
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
 
23
 
import os
24
 
 
25
 
from cloudinit import handlers
26
 
from cloudinit import log as logging
27
 
from cloudinit import util
28
 
 
29
 
from cloudinit.settings import (PER_ALWAYS)
30
 
 
31
 
LOG = logging.getLogger(__name__)
32
 
SHELL_PREFIX = "#!"
33
 
 
34
 
 
35
 
class ShellScriptPartHandler(handlers.Handler):
36
 
    def __init__(self, paths, **_kwargs):
37
 
        handlers.Handler.__init__(self, PER_ALWAYS)
38
 
        self.script_dir = paths.get_ipath_cur('scripts')
39
 
        if 'script_path' in _kwargs:
40
 
            self.script_dir = paths.get_ipath_cur(_kwargs['script_path'])
41
 
 
42
 
    def list_types(self):
43
 
        return [
44
 
            handlers.type_from_starts_with(SHELL_PREFIX),
45
 
        ]
46
 
 
47
 
    def handle_part(self, data, ctype, filename, payload, frequency):
48
 
        if ctype in handlers.CONTENT_SIGNALS:
49
 
            # TODO(harlowja): maybe delete existing things here
50
 
            return
51
 
 
52
 
        filename = util.clean_filename(filename)
53
 
        payload = util.dos2unix(payload)
54
 
        path = os.path.join(self.script_dir, filename)
55
 
        util.write_file(path, payload, 0o700)