Skip to content

Instantly share code, notes, and snippets.

@kazufusa
Created January 19, 2014 10:51
Show Gist options
  • Save kazufusa/8503209 to your computer and use it in GitHub Desktop.
Save kazufusa/8503209 to your computer and use it in GitHub Desktop.
# 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment