#!/usr/bin/env python
import os, sys
import subprocess

repos = [
    # python 
    'Pylons/pyramid',
    'Pylons/pyramid_debugtoolbar',
    'Pylons/pyramid_tm',
    'Pylons/waitress',
    'Pylons/colander',
    'mozilla-services/cornice',
    # nodejs backend
    'dchester/epilogue',
    'webpack/webpack',
    'webpack/webpack-dev-server',
    'webpack/docs',
    'webpack/json-loader',
    'webpack/json5-loader',
    'webpack/css-loader',
    'webpack/url-loader',
    'webpack/file-loader',
    'webpack/worker-loader',
    'webpack/raw-loader',
    'webpack/coffee-loader',
    'bower/bower',
    # frontend
    'twbs/bootstrap',
    'marionettejs/backbone.marionette',
    'marionettejs/backbone.radio',
    'jashkenas/backbone',
    'jashkenas/underscore',
    'jashkenas/coffeescript',
    'jquery/jquery',
    'jquery/jquery-mobile',
    'jquery/jquery-color',
    'jquery/jquery-ui',
    'jquery/sizzle',
    'thedersen/backbone.validation',
    'bergie/hallo',
    'bergie/create',
    'bergie/VIE',
    'goodeggs/teacup',
    'FortAwesome/Font-Awesome',
    'umeboshi2/bootstrap-teacup-templates',
    'umeboshi2/marionette-form-view',
    'thlorenz/brace',
    'ajaxorg/ace',
    'moment/moment',
    'gulpjs/gulp',
    'gulpjs/gulp-cli',
    'gulpjs/gulp-util',
    'electron/electron',
    'mochajs/mocha',
    'photonstorm/phaser',
    'photonstorm/lazer',
    'photonstorm/phaser-examples',
    'curiousdannii/parchment',
    'curiousdannii/ifvms.js',
    'curiousdannii/gnusto',
    'hurrymaplelad/teact',
    'facebook/react',
    #'facebook/react-dom',
    'desandro/masonry',
    'd3/d3',
    'chjj/marked',
    # not really vendor stack
    'kripken/emscripten',
    'juj/emscripten-scummvm',
    'jhlywa/chess.js',
    'curiousdannii/parchment',
    'curiousdannii/gnusto',
    ]

parent_directory = os.path.expanduser('~/workspace/vendorstack')

if not os.path.isdir(parent_directory):
    os.makedirs(parent_directory)

def clone_repo(url, dirname=None):

    here = os.getcwd()
    os.chdir(parent_directory)
    cmd = ['git', 'clone', url]
    if dirname is not None:
        cmd.append(dirname)
    subprocess.check_call(cmd)
    os.chdir(here)
    

def update_repo(url, dirname=None):
    here = os.getcwd()
    os.chdir(parent_directory)
    cmd = ['git', 'clone', url]
    if dirname is not None:
        cmd.append(dirname)
    subprocess.check_call(cmd)
    os.chdir(here)
    
def make_github_url(repo):
    return 'git@github.com:%s.git' % repo

def clone_github_repo(repo):
    url = make_github_url(repo)
    clone_repo(url)



for r in repos:
    dirname = os.path.join(parent_directory, os.path.basename(r))
    if not os.path.isdir(dirname):
        print "cloning", r
        clone_github_repo(r)
    else:
        print "skipping", r
