Skip to content

Instantly share code, notes, and snippets.

@Circuitsoft
Created February 13, 2009 05:27
Show Gist options
  • Select an option

  • Save Circuitsoft/63061 to your computer and use it in GitHub Desktop.

Select an option

Save Circuitsoft/63061 to your computer and use it in GitHub Desktop.

Revisions

  1. Circuitsoft revised this gist Apr 21, 2011. 2 changed files with 59 additions and 64 deletions.
    25 changes: 25 additions & 0 deletions git.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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)
    98 changes: 34 additions & 64 deletions gistfile1.py → test.py
    Original file line number Diff line number Diff line change
    @@ -1,64 +1,34 @@
    # This is the important part of git.py
    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)



    # This is test.py
    #!/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()
    #!/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()
  2. @invalid-email-address Anonymous created this gist Feb 13, 2009.
    64 changes: 64 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    # This is the important part of git.py
    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)



    # This is test.py
    #!/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()