Exemple #1
0
 def save(self, filename):
     """Saves a model to a file.
     """
     fh = open(filename, 'w')
     jsonpickle.set_encoder_options('simplejson', indent=4)
     try:
         core.write_nointr(fh, jsonpickle.encode(self))
     except:
         pass
     fh.close()
     jsonpickle.set_encoder_options('simplejson', indent=None)
Exemple #2
0
    def commit_with_msg(self, msg, tmpfile, amend=False):
        """Creates a git commit."""

        if not msg.endswith('\n'):
            msg += '\n'

        # Create the commit message file
        fh = open(tmpfile, 'w')
        core.write_nointr(fh, msg)
        fh.close()

        # Run 'git commit'
        status, out = self.git.commit(F=tmpfile, v=True, amend=amend,
                                      with_status=True,
                                      with_stderr=True)
        os.unlink(tmpfile)
        return (status, out)
Exemple #3
0
    def commit_with_msg(self, msg, amend=False):
        """Creates a git commit."""

        if not msg.endswith('\n'):
            msg += '\n'
        # Sure, this is a potential "security risk," but if someone
        # is trying to intercept/re-write commit messages on your system,
        # then you probably have bigger problems to worry about.
        tmpfile = self.tmp_filename()

        # Create the commit message file
        fh = open(tmpfile, 'w')
        core.write_nointr(fh, msg)
        fh.close()

        # Run 'git commit'
        status, out = self.git.commit(F=tmpfile, v=True, amend=amend,
                                      with_status=True,
                                      with_stderr=True)
        os.unlink(tmpfile)
        return (status, out)
Exemple #4
0
def write(path, contents):
    """Writes a string to a file."""
    fh = open(path, 'w')
    core.write_nointr(fh, core.encode(contents))
    fh.close()