Search code examples
pythongithubfabricgitpython

How do you define the host for Fabric to push to GitHub?


Original Question

I've got some python scripts which have been using Amazon S3 to upload screenshots taken following Selenium tests within the script.

Now we're moving from S3 to use GitHub so I've found GitPython but can't see how you use it to actually commit to the local repo and push to the server.

My script builds a directory structure similar to \images\228M\View_Use_Case\1.png in the workspace and when uploading to S3 it was a simple process;

for root, dirs, files in os.walk(imagesPath):
    for name in files:
        filename = os.path.join(root, name)
        k = bucket.new_key('{0}/{1}/{2}'.format(revisionNumber, images_process, name)) # returns a new key object
        k.set_contents_from_filename(filename, policy='public-read') # opens local file buffers to key on S3
        k.set_metadata('Content-Type', 'image/png')

Is there something similar for this or is there something as simple as a bash type git add images command in GitPython that I've completely missed?

Updated with Fabric

So I've installed Fabric on kracekumar's recommendation but I can't find docs on how to define the (GitHub) hosts. My script is pretty simple to just try and get the upload to work;

from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import os

def git_server():
    env.hosts = ['github.com']
    env.user = 'git'
    env.passowrd = 'password'

def test():
    process = 'View Employee'
    os.chdir('\Work\BPTRTI\main\employer_toolkit')
    with cd('\Work\BPTRTI\main\employer_toolkit'):
        result = local('ant viewEmployee_git')
    if result.failed and not confirm("Tests failed. Continue anyway?"):
        abort("Aborting at user request.")

def deploy():
    process = "View Employee"
    os.chdir('\Documents and Settings\markw\GitTest')
    with cd('\Documents and Settings\markw\GitTest'):
        local('git add images')
        local('git commit -m "Latest Selenium screenshots for %s"' % (process))
        local('git push -u origin master')

def viewEmployee():
    #test()
    deploy()

It Works \o/ Hurrah.


Solution

  • You should look into Fabric. http://docs.fabfile.org/en/1.4.1/index.html. Automated server deployment tool. I have been using this quite some time, it works pretty fine.

    Here is my one of the application which uses it, https://github.com/kracekumar/sachintweets/blob/master/fabfile.py