Beispiel #1
0
def _stdout_write(msg):
    if not isinstance(msg, get_stringtype()):
        msg = repr(msg)
    try:
        sys.stdout.write(msg)
    except UnicodeEncodeError:
        msg = msg.encode('utf-8')
        if sys.hexversion >= 0x3000000:
            sys.stdout.buffer.write(msg)
        else:
            sys.stdout.write(msg)
Beispiel #2
0
def _stdout_write(msg):
    if not isinstance(msg, get_stringtype()):
        msg = repr(msg)
    try:
        sys.stdout.write(msg)
    except UnicodeEncodeError:
        msg = msg.encode('utf-8')
        if sys.hexversion >= 0x3000000:
            sys.stdout.buffer.write(msg)
        else:
            sys.stdout.write(msg)
Beispiel #3
0
 def parse(self):
     mydict = {}
     data = self._generic_parser()
     # compact lines properly
     old_key = None
     for line in data:
         key = None
         value = None
         v_key, v_value = self.parse_line_statement(line)
         check_dict = self.parameters.get(v_key)
         if check_dict is not None:
             key, value = v_key, v_value
             old_key = key
         elif isinstance(old_key, get_stringtype()):
             key = old_key
             value = line.strip()
             if not value:
                 continue
         # gather again... key is changed
         check_dict = self.parameters.get(key)
         if not isinstance(check_dict, dict):
             continue
         value = check_dict['parser'](value)
         if not check_dict['verifier'](value):
             continue
         if key in mydict:
             if isinstance(value, get_stringtype()):
                 mydict[key] += " %s" % (value,)
             elif isinstance(value, list):
                 mydict[key] += value
             else:
                 continue
         else:
             mydict[key] = value
     mydict['__plugin__'] = self.__plugin
     self.validate_parse(mydict)
     return mydict.copy()
Beispiel #4
0
 def parse(self):
     mydict = {}
     data = self._generic_parser()
     # compact lines properly
     old_key = None
     for line in data:
         key = None
         value = None
         v_key, v_value = self.parse_line_statement(line)
         check_dict = self.parameters.get(v_key)
         if check_dict is not None:
             key, value = v_key, v_value
             old_key = key
         elif isinstance(old_key, get_stringtype()):
             key = old_key
             value = line.strip()
             if not value:
                 continue
         # gather again... key is changed
         check_dict = self.parameters.get(key)
         if not isinstance(check_dict, dict):
             continue
         value = check_dict['parser'](value)
         if not check_dict['verifier'](value):
             continue
         if key in mydict:
             if isinstance(value, get_stringtype()):
                 mydict[key] += " %s" % (value, )
             elif isinstance(value, list):
                 mydict[key] += value
             else:
                 continue
         else:
             mydict[key] = value
     mydict['__plugin__'] = self.__plugin
     self.validate_parse(mydict)
     return mydict.copy()
Beispiel #5
0
    def load(self, mysettings = None):
        if mysettings is None:
            mysettings = {}

        settings = {
            'version': VERSION,
            'tmp_dir': self._constants['tmp_dir'],
        }

        # convert everything to unicode in one pass
        for k, v in settings.items():
            if isinstance(v, get_stringtype()):
                settings[k] = convert_to_unicode(v)
            elif isinstance(v, (list, tuple)):
                settings[k] = [convert_to_unicode(x) for x in v]

        self.clear()
        self.update(settings)
        self.update(mysettings)
Beispiel #6
0
    def load(self, mysettings=None):
        if mysettings is None:
            mysettings = {}

        settings = {
            'version': VERSION,
            'tmp_dir': self._constants['tmp_dir'],
        }

        # convert everything to unicode in one pass
        for k, v in settings.items():
            if isinstance(v, get_stringtype()):
                settings[k] = convert_to_unicode(v)
            elif isinstance(v, (list, tuple)):
                settings[k] = [convert_to_unicode(x) for x in v]

        self.clear()
        self.update(settings)
        self.update(mysettings)
Beispiel #7
0
 def __str__(self):
     if isinstance(self.value, get_stringtype()):
         return self.value
     else:
         return repr(self.value)
    def post_run(self):
        self._output.output("[%s|%s] %s" % (
                blue("ChrootHandler"), darkred(self.spec_name),
                _("executing post_run"),
            )
        )

        # now remove paths to empty
        empty_paths = self.metadata.get('paths_to_empty', [])
        for mypath in empty_paths:
            mypath = self.dest_dir+mypath
            self._output.output("[%s|%s] %s: %s" % (
                    blue("ChrootHandler"), darkred(self.spec_name),
                    _("emptying dir"), mypath,
                )
            )
            if os.path.isdir(mypath):
                molecule.utils.empty_dir(mypath)

        # now remove paths to remove (...)
        remove_paths = self.metadata.get('paths_to_remove', [])

        # setup sandbox
        sb_dirs = [self.dest_dir]
        sb_env = {
            'SANDBOX_WRITE': ':'.join(sb_dirs),
        }
        myenv = os.environ.copy()
        myenv.update(sb_env)

        for mypath in remove_paths:
            mypath = self.dest_dir+mypath
            self._output.output("[%s|%s] %s: %s" % (
                    blue("ChrootHandler"), darkred(self.spec_name),
                    _("removing dir"), mypath,
                )
            )
            rc = molecule.utils.remove_path_sandbox(mypath, sb_env)
            if rc != 0:
                self._output.output("[%s|%s] %s: %s: %s" % (
                        blue("ChrootHandler"), darkred(self.spec_name),
                        _("removal failed for"), mypath, rc,
                    )
                )
                return rc

        # write release file
        release_file = self.metadata.get('release_file')
        if isinstance(release_file, get_stringtype()) and release_file:
            if release_file[0] == os.sep:
                release_file = release_file[len(os.sep):]
            release_file = os.path.join(self.dest_dir, release_file)
            if os.path.lexists(release_file) and not os.path.isfile(release_file):
                self._output.output("[%s|%s] %s: %s" % (
                        blue("ChrootHandler"), darkred(self.spec_name),
                        _("release file creation failed, not a file"),
                        release_file,
                    )
                )
                return 1
            release_string = self.metadata.get('release_string', '')
            release_version = self.metadata.get('release_version', '')
            release_desc = self.metadata.get('release_desc', '')
            file_string = "%s %s %s\n" % (release_string, release_version, release_desc,)
            try:
                f = open(release_file, "w")
                f.write(file_string)
                f.flush()
                f.close()
            except (IOError, OSError,) as e:
                self._output.output("[%s|%s] %s: %s: %s" % (
                        blue("ChrootHandler"), darkred(self.spec_name),
                        _("release file creation failed, system error"),
                        release_file, e,
                    )
                )
                return 1

        # run outer chroot script after
        exec_script = self.metadata.get('outer_chroot_script_after')
        if exec_script:
            env = os.environ.copy()
            env['CHROOT_DIR'] = self.source_dir
            self._output.output("[%s|%s] %s: %s" % (
                    blue("ChrootHandler"), darkred(self.spec_name),
                    _("spawning"), " ".join(exec_script),
                )
            )
            rc = molecule.utils.exec_cmd(exec_script, env=env)
            if rc != 0:
                self._output.output("[%s|%s] %s: %s" % (
                        blue("ChrootHandler"), darkred(self.spec_name),
                        _("outer chroot hook (after inner) failed"), rc,
                    )
                )
                return rc

        return 0
    def post_run(self):
        self._output.output("[%s|%s] %s" % (
            blue("ChrootHandler"),
            darkred(self.spec_name),
            _("executing post_run"),
        ))

        # now remove paths to empty
        empty_paths = self.metadata.get('paths_to_empty', [])
        for mypath in empty_paths:
            mypath = self.dest_dir + mypath
            self._output.output("[%s|%s] %s: %s" % (
                blue("ChrootHandler"),
                darkred(self.spec_name),
                _("emptying dir"),
                mypath,
            ))
            if os.path.isdir(mypath):
                molecule.utils.empty_dir(mypath)

        # now remove paths to remove (...)
        remove_paths = self.metadata.get('paths_to_remove', [])

        # setup sandbox
        sb_dirs = [self.dest_dir]
        sb_env = {
            'SANDBOX_WRITE': ':'.join(sb_dirs),
        }
        myenv = os.environ.copy()
        myenv.update(sb_env)

        for mypath in remove_paths:
            mypath = self.dest_dir + mypath
            self._output.output("[%s|%s] %s: %s" % (
                blue("ChrootHandler"),
                darkred(self.spec_name),
                _("removing dir"),
                mypath,
            ))
            rc = molecule.utils.remove_path_sandbox(mypath, sb_env)
            if rc != 0:
                self._output.output("[%s|%s] %s: %s: %s" % (
                    blue("ChrootHandler"),
                    darkred(self.spec_name),
                    _("removal failed for"),
                    mypath,
                    rc,
                ))
                return rc

        # write release file
        release_file = self.metadata.get('release_file')
        if isinstance(release_file, get_stringtype()) and release_file:
            if release_file[0] == os.sep:
                release_file = release_file[len(os.sep):]
            release_file = os.path.join(self.dest_dir, release_file)
            if os.path.lexists(
                    release_file) and not os.path.isfile(release_file):
                self._output.output("[%s|%s] %s: %s" % (
                    blue("ChrootHandler"),
                    darkred(self.spec_name),
                    _("release file creation failed, not a file"),
                    release_file,
                ))
                return 1
            release_string = self.metadata.get('release_string', '')
            release_version = self.metadata.get('release_version', '')
            release_desc = self.metadata.get('release_desc', '')
            file_string = "%s %s %s\n" % (
                release_string,
                release_version,
                release_desc,
            )
            try:
                f = open(release_file, "w")
                f.write(file_string)
                f.flush()
                f.close()
            except (
                    IOError,
                    OSError,
            ) as e:
                self._output.output("[%s|%s] %s: %s: %s" % (
                    blue("ChrootHandler"),
                    darkred(self.spec_name),
                    _("release file creation failed, system error"),
                    release_file,
                    e,
                ))
                return 1

        # run outer chroot script after
        exec_script = self.metadata.get('outer_chroot_script_after')
        if exec_script:
            env = os.environ.copy()
            env['CHROOT_DIR'] = self.source_dir
            self._output.output("[%s|%s] %s: %s" % (
                blue("ChrootHandler"),
                darkred(self.spec_name),
                _("spawning"),
                " ".join(exec_script),
            ))
            rc = molecule.utils.exec_cmd(exec_script, env=env)
            if rc != 0:
                self._output.output("[%s|%s] %s: %s" % (
                    blue("ChrootHandler"),
                    darkred(self.spec_name),
                    _("outer chroot hook (after inner) failed"),
                    rc,
                ))
                return rc

        return 0
Beispiel #10
0
 def __str__(self):
     if isinstance(self.value, get_stringtype()):
         return self.value
     else:
         return repr(self.value)