[PYTHON] git with subprocess.Popen

git_submodule_update.py


# vim: set fileencoding=utf-8 :
# Created:  2014-01-19
# Git submodule update within python subprocess
import os
import subprocess


GIT = "git"
SUBMODULE = "submodule"
FOREACH = "foreach"


class Git(object):
    def __init__(self):
        self._dir = ""
        pass

    @property
    def dir(self):
        return self._dir

    @dir.setter
    def dir(self, dir):
        self._dir = dir

    def submodule_update(self):
        pr = subprocess.Popen([GIT, SUBMODULE, FOREACH, 'git checkout master; git pull'],
                              cwd=os.path.dirname(self.dir),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              shell=False)
        (out, error) = pr.communicate()
        return out, error

if __name__ == "__main__":
    APP_ROOT = os.path.dirname(os.path.abspath(__file__))
    dir = os.path.join(APP_ROOT, ".git")
    git = Git()
    git.dir = dir
    git.submodule_update()

Recommended Posts

git with subprocess.Popen
Getting Started with Git (1) History Storage
Git basics
How to upload with Heroku, Flask, Python, Git (4)
Get git branch name and tag name with python
Update the XSERVER website with Git push (Note)