(self, content, path, **kwargs)
Create file with given content on a specified path

        If the target path requires root privileges, this function can be
        executed with option root=True.
Create file with given content on a specified path
Create file with given content on a specified path
def create_file(self, content, path, **kwargs):
        """Create file with given content on a specified path

        If the target path requires root privileges, this function can be
        executed with option root=True.

        """
        if (self.dry):
            # In dry-run mode, run an equivalent echo command.
            cmd = ["echo", "-e", repr(content), ">", path]
        else:
            tmp_file = tempfile.NamedTemporaryFile(mode="w", delete=False)
            with tmp_file as fd:
                fd.write(content)
            cmd = ["mv", tmp_file.name, path]
        self.run(cmd, **kwargs)
        if (not self.dry):
            self.logger.info("Created file {}".format(path))
def create_file ( self , content , path , * * kwargs ) : if ( self . dry ) : # In dry-run mode, run an equivalent echo command. cmd = [ "echo" , "-e" , repr ( content ) , ">" , path ] else : tmp_file = tempfile . NamedTemporaryFile ( mode = "w" , delete = False ) with tmp_file as fd : fd . write ( content ) cmd = [ "mv" , tmp_file . name , path ] self . run ( cmd , * * kwargs ) if ( not self . dry ) : self . logger . info ( "Created file {}" . format ( path ) )