Skip to content

Instantly share code, notes, and snippets.

@Circuitsoft
Created February 13, 2009 05:27
Show Gist options
  • Save Circuitsoft/63061 to your computer and use it in GitHub Desktop.
Save Circuitsoft/63061 to your computer and use it in GitHub Desktop.
import os, time
import subprocess
class repo:
def __init__(self, repodir="."):
self.repodir=repodir
def __callgit(self, cmd, *args):
command = ['git', cmd]
for a in args:
command.append(a)
env = {'GIT_DIR':self.repodir}
p = subprocess.PIPE
print 'Calling',command,'on',self.repodir
return subprocess.Popen(command, env=env, stdin=p, stdout=p)
callgit = __callgit # Make it temporarily available outside
def snapshot(self, ref='HEAD', format='zip', filter=None):
results = self.__callgit('archive', '--format=%s' % format, ref)
if filter:
output = subprocess.Popen(filter, stdin=results.stdout, stdout=subprocess.PIPE).stdout
else:
output = results.stdout
while True:
yield output.read(0x1000)
#!/usr/bin/python
import git
import web
from subprocess import *
class hello:
def GET(self):
for a in ['callgit', 'snapshot']:
yield '<A HREF="%s">%s</a>' % (a,a)
class callgit:
def GET(self):
web.header('Content-Type', 'application/binary')
web.header('Content-Disposition', 'attachment; filename=test.tar.gz')
repoobj = git.repo('/var/spool/gitosis/repositories/sensorcentral.git')
output = repoobj.callgit('archive', '--format=tar', '4cc3471f876f8a6814c567902a07b5f15083b9d4').stdout
return Popen(('gzip', '-9c', '-'), stdout=PIPE, stdin=output).stdout
class snapshot:
def GET(self):
web.header('Content-Type', 'application/binary')
web.header('Content-Disposition', 'attachment; filename=test.tar.gz')
repoobj = git.repo('/var/spool/gitosis/repositories/sensorcentral.git')
return repoobj.snapshot('4cc3471f876f8a6814c567902a07b5f15083b9d4', 'tar', ('gzip', '-9c', '-'))
if __name__ == "__main__":
urls = ("/", "hello",
"/callgit", "callgit",
"/snapshot", "snapshot")
web.application(urls, globals()).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment